Review shell scripts

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-01-22 14:07:22 +00:00
parent 8f94687b2b
commit bcbda92c46
27 changed files with 273 additions and 259 deletions

View File

@@ -30,36 +30,38 @@
in
''
nix-direnv() {
if [ -z "$1" ]; then
echo "use flake" > .envrc
local devshell=""
local hide=false
if [ ! -f flake.nix ]; then
echo "Do you want to create an empty flake.nix? (y/N)"
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
cp "${./template.nix}" flake.nix
fi
fi
while getopts "s:h" opt; do
case $opt in
s)
devshell=$OPTARG
;;
h)
hide=true
;;
*)
echo "Usage: nix-direnv [-s <devshell>] [-h]"
return 1
;;
esac
done
if [[ -z "$devshell" ]]; then
echo "use flake" > .envrc
if [ ! -f flake.nix ]; then cp "${../nix-develop/template.nix}" flake.nix; fi
else
echo "use flake self#$1" > .envrc
echo "use flake self#$devshell" > .envrc
fi
if git rev-parse --is-inside-work-tree &> /dev/null; then
if ! grep -q "^\.envrc$" .gitignore .git/info/exclude; then
echo "Do you want to hide the .envrc file from git? (y/N)"
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
echo ".envrc" >> .git/info/exclude
fi
fi
if [ -f flake.nix ] && ! grep -q "^flake.nix$" .gitignore .git/info/exclude; then
echo "Do you want to hide the flake.nix and flake.lock files from git? (y/N)"
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
echo "flake.nix" >> .git/info/exclude
echo "flake.lock" >> .git/info/exclude
fi
if hide && git rev-parse --is-inside-work-tree &>/dev/null; then
local top
top=$(git rev-parse --show-toplevel)
if ! grep -q "^\.envrc$" "$top/.gitignore" "$top/.git/info/exclude"; then echo "$(realpath --relative-to="$top" .envrc)" >> "$top/.git/info/exclude"; fi
if [ -z "$devshell" ]; then
if ! grep -q "^flake.nix$" "$top/.gitignore" "$top/.git/info/exclude"; then echo "flake.nix" >> "$top/.git/info/exclude"; fi
if ! grep -q "^flake.lock$" "$top/.gitignore" "$top/.git/info/exclude"; then echo "flake.lock" >> "$top/.git/info/exclude"; fi
fi
fi
@@ -67,8 +69,12 @@
}
_nix-direnv_completion() {
local shells=(${devShells})
compadd -- $shells
local options=(
'-s[Dev shell from root flake]:shell:(${devShells})'
'-h[Hide .envrc and flake.nix in git]'
)
_arguments -s $options
}
compdef _nix-direnv_completion nix-direnv

View File

@@ -1,30 +0,0 @@
{
inputs = {
nixpkgs = {
type = "github";
owner = "karaolidis";
repo = "nixpkgs";
ref = "integration";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
};
outputs =
{ nixpkgs, ... }@inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
packages = [ ];
};
formatter = pkgs.nixfmt-rfc-style;
}
);
}