diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-12-23 16:36:19 +0200 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-12-23 16:36:19 +0200 |
commit | ff3be101f94cdb5a076b311f802471bbb3bd0b37 (patch) | |
tree | 15b537e9b1e829d823be2e95e2ec658491dc5ff2 | |
parent | 2e0927fc93f57931f31b38f3a4065c07841fab53 (diff) | |
download | nixos-configuration-ff3be101f94cdb5a076b311f802471bbb3bd0b37.tar.gz nixos-configuration-ff3be101f94cdb5a076b311f802471bbb3bd0b37.tar.bz2 nixos-configuration-ff3be101f94cdb5a076b311f802471bbb3bd0b37.zip |
feat: improve script
-rw-r--r-- | home-manager/stvnliu/scripts/git_check_clean.script.nix | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/home-manager/stvnliu/scripts/git_check_clean.script.nix b/home-manager/stvnliu/scripts/git_check_clean.script.nix index 439913d..0265dfa 100644 --- a/home-manager/stvnliu/scripts/git_check_clean.script.nix +++ b/home-manager/stvnliu/scripts/git_check_clean.script.nix @@ -4,7 +4,7 @@ }: let git = config.programs.git.package; in - pkgs.writeShellScriptBin "git-check-clean" '' + pkgs.writeShellScriptBin "git-check" '' #!${pkgs.bash}/bin/bash cd_err() { echo "change-directory occurred error. interrupting..." @@ -12,15 +12,11 @@ in git_check() { prev=$1 repo_dir=$2 - filter=$3 - if [[ ! "$filter" == "dirty" && ! "$filter" = "clean" ]]; then - echo "Could not parse filter string" - return - fi #echo "Checking git-cleanliness at $repo_dir, working in $PWD" cd "$repo_dir" || return inside_git_repo="$(${git}/bin/git rev-parse --is-inside-work-tree 2>/dev/null)" result=256 + default_skip=false if [ "$inside_git_repo" ]; then if [ "$(${git}/bin/git status --porcelain)" ]; then result=0 @@ -29,24 +25,28 @@ in fi #echo "not a git repository" fi - if [ "$filter" = "dirty" ]; then - if [[ $result -eq 0 ]]; then - echo "DIRTY $PWD" - read -rp "Enter dirty directory? [y/N] " userinput - if [[ "$userinput" = "y" ]]; then - $SHELL - fi + if [[ $result -eq 0 ]]; then + echo "DIRTY $PWD" + if $default_skip; then return; fi + read -rp "Enter dirty directory? [y/n/N(skip others)] " userinput + if [[ "$userinput" = "y" ]]; then + $SHELL fi - else - if [[ $result -eq 1 ]]; then - echo "CLEAN $PWD" + if [[ "$userinput" = "N" ]]; then + default_skip=true fi fi #echo "going back to $prev" cd "$prev" || return } path=$PWD - for item in $(find . -maxdepth 1 -type d); do - git_check "$path" "$item" "$1" + scan_path=$PWD + if [ -z "$1" ]; then + scan_path=$PWD + else + scan_path=$1 + fi + for item in $(find $scan_path -maxdepth 1 -type d); do + git_check "$path" "$item" done '' |