diff --git a/lib/default.nix b/lib/default.nix index 9b6eef9..8748958 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -51,6 +51,7 @@ in { shellModules = { logs = builtins.readFile ./shell/logs.sh; check-tool = builtins.readFile ./shell/check-tool.sh; + local-dir = builtins.readFile ./shell/local-dir.sh; }; sharedShellAliases = { diff --git a/lib/shell/local-dir.sh b/lib/shell/local-dir.sh new file mode 100644 index 0000000..7f3b8d2 --- /dev/null +++ b/lib/shell/local-dir.sh @@ -0,0 +1,14 @@ +printf '\033[0;34mDetecting local directories...\033[0m\n' +if git_root=$($BIN_GIT rev-parse --show-toplevel 2>/dev/null); then + LOCAL_DIR="$git_root" + printf '\033[0;32mFound git root: \033[1;37m%s\033[0m\n' "$LOCAL_DIR" +else + LOCAL_DIR="$(pwd)" + printf '\033[1;33mNot in git repo, using current dir: \033[1;37m%s\033[0m\n' "$LOCAL_DIR" + printf 'Are you realy want continue? (y/n):\n' + read -r CONTINUE + if [ "$CONTINUE" != "y" ]; then + printf '\033[0;31mAborting...\033[0m\n' + exit 0 + fi +fi