From 6e778534534d2dd2f74b10c15d75cb1d6998ad5f Mon Sep 17 00:00:00 2001 From: yukkop Date: Tue, 22 Jul 2025 21:15:42 +0000 Subject: [PATCH] feat(lib): `shell`: local-dir --- lib/default.nix | 1 + lib/shell/local-dir.sh | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 lib/shell/local-dir.sh 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