blob: af0aa6c29ce7bce319d27f8c76754a6d60ed7c19 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#!/bin/sh
# didn't consider $HOME contain space? need improve?
while getopts clLsSmM opt; do
case $opt in
c|l|s) dir="$HOME"
cmd="git --git-dir=$dir/.cfg$opt/ --work-tree=$dir"
mods="$XDG_CONFIG_HOME/myconf/cfg${opt}_mods";;
L|S) dir=/etc/
cmd="sudo git --git-dir=$dir/.cfg$opt/ --work-tree=$dir"
mods="/etc/myconf/cfg${opt}_mods";;
m) $cmd ls-tree -r --name-only --full-tree HEAD | nawk -v a="$dir/" '{printf("%s%s\n",a,$0)}' | tr '\n' '\0' | xargs -0 ls -ldA -- | grep -v '^l\|^d' | nawk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k){for(i=10;$i;i++)$9=$9" "$i;printf("%0o %s\n",k,$9)}}' > mods
exit;;
M) while read -r mod path; do
chmod -c "$mod" -- "$path"
done < mods
exit;;
\?) exit 1;;
esac
done
shift $((OPTIND-1))
$cmd "$@"
|