feat: improve script
This commit is contained in:
parent
2e0927fc93
commit
ff3be101f9
1 changed files with 18 additions and 18 deletions
|
@ -4,7 +4,7 @@
|
||||||
}: let
|
}: let
|
||||||
git = config.programs.git.package;
|
git = config.programs.git.package;
|
||||||
in
|
in
|
||||||
pkgs.writeShellScriptBin "git-check-clean" ''
|
pkgs.writeShellScriptBin "git-check" ''
|
||||||
#!${pkgs.bash}/bin/bash
|
#!${pkgs.bash}/bin/bash
|
||||||
cd_err() {
|
cd_err() {
|
||||||
echo "change-directory occurred error. interrupting..."
|
echo "change-directory occurred error. interrupting..."
|
||||||
|
@ -12,15 +12,11 @@ in
|
||||||
git_check() {
|
git_check() {
|
||||||
prev=$1
|
prev=$1
|
||||||
repo_dir=$2
|
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"
|
#echo "Checking git-cleanliness at $repo_dir, working in $PWD"
|
||||||
cd "$repo_dir" || return
|
cd "$repo_dir" || return
|
||||||
inside_git_repo="$(${git}/bin/git rev-parse --is-inside-work-tree 2>/dev/null)"
|
inside_git_repo="$(${git}/bin/git rev-parse --is-inside-work-tree 2>/dev/null)"
|
||||||
result=256
|
result=256
|
||||||
|
default_skip=false
|
||||||
if [ "$inside_git_repo" ]; then
|
if [ "$inside_git_repo" ]; then
|
||||||
if [ "$(${git}/bin/git status --porcelain)" ]; then
|
if [ "$(${git}/bin/git status --porcelain)" ]; then
|
||||||
result=0
|
result=0
|
||||||
|
@ -29,24 +25,28 @@ in
|
||||||
fi
|
fi
|
||||||
#echo "not a git repository"
|
#echo "not a git repository"
|
||||||
fi
|
fi
|
||||||
if [ "$filter" = "dirty" ]; then
|
|
||||||
if [[ $result -eq 0 ]]; then
|
if [[ $result -eq 0 ]]; then
|
||||||
echo "DIRTY $PWD"
|
echo "DIRTY $PWD"
|
||||||
read -rp "Enter dirty directory? [y/N] " userinput
|
if $default_skip; then return; fi
|
||||||
|
read -rp "Enter dirty directory? [y/n/N(skip others)] " userinput
|
||||||
if [[ "$userinput" = "y" ]]; then
|
if [[ "$userinput" = "y" ]]; then
|
||||||
$SHELL
|
$SHELL
|
||||||
fi
|
fi
|
||||||
fi
|
if [[ "$userinput" = "N" ]]; then
|
||||||
else
|
default_skip=true
|
||||||
if [[ $result -eq 1 ]]; then
|
|
||||||
echo "CLEAN $PWD"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
#echo "going back to $prev"
|
#echo "going back to $prev"
|
||||||
cd "$prev" || return
|
cd "$prev" || return
|
||||||
}
|
}
|
||||||
path=$PWD
|
path=$PWD
|
||||||
for item in $(find . -maxdepth 1 -type d); do
|
scan_path=$PWD
|
||||||
git_check "$path" "$item" "$1"
|
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
|
done
|
||||||
''
|
''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue