feat: add new git check clean script
This commit is contained in:
parent
54bc34d7dc
commit
51f3ed41cc
2 changed files with 52 additions and 0 deletions
|
@ -9,5 +9,9 @@
|
|||
inherit pkgs;
|
||||
inherit config;
|
||||
})
|
||||
(import ./git_check_clean.script.nix {
|
||||
inherit pkgs;
|
||||
inherit config;
|
||||
})
|
||||
];
|
||||
}
|
||||
|
|
48
home-manager/stvnliu/scripts/git_check_clean.script.nix
Normal file
48
home-manager/stvnliu/scripts/git_check_clean.script.nix
Normal file
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
}: let
|
||||
git = config.programs.git.package;
|
||||
in
|
||||
pkgs.writeShellScriptBin "git-check-clean" ''
|
||||
#!${pkgs.bash}/bin/bash
|
||||
cd_err() {
|
||||
echo "change-directory occurred error. interrupting..."
|
||||
}
|
||||
git_check() {
|
||||
prev=$1
|
||||
repo_dir=$2
|
||||
filter=$3
|
||||
if [[ ! "$filter" == "dirty" && ! "$filter" = "clean" ]]; then
|
||||
echo "Could not parse filter string"
|
||||
return
|
||||
fi
|
||||
cd "$repo_dir" || return
|
||||
inside_git_repo="$(${git}/bin/git rev-parse --is-inside-work-tree 2>/dev/null)"
|
||||
if [ "$inside_git_repo" ]; then
|
||||
if [ "$(${git}/bin/git status --porcelain)" ]; then
|
||||
result=0
|
||||
else
|
||||
result=1
|
||||
fi
|
||||
#echo "not a git repository"
|
||||
fi
|
||||
if [ "$filter" = "dirty" ]; then
|
||||
if [[ $result -eq 0 ]]; then
|
||||
echo "DIRTY $PWD"
|
||||
fi
|
||||
else
|
||||
if [[ $result -eq 1 ]]; then
|
||||
echo "CLEAN $PWD"
|
||||
fi
|
||||
fi
|
||||
#echo "going back to $prev"
|
||||
cd "$prev" || return
|
||||
}
|
||||
export -f git_check
|
||||
export -f cd_err
|
||||
path=$PWD
|
||||
for item in $(${pkgs.findutils}/bin/find . -maxdepth 1 -type d); do
|
||||
git_check "$path" "$item" "$1"
|
||||
done
|
||||
''
|
Loading…
Add table
Add a link
Reference in a new issue