blob: de40874ab5de8557b65a2af0bd1e1b46ade56b38 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#!/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";;
# -rw-r--r-- == binary 110100100 == octal 644
# https://stackoverflow.com/a/1796009
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
sudo chmod -c "$mod" -- "$path"
done < "$mods"
exit;;
\?) exit 1;;
esac
done
shift $((OPTIND-1))
$cmd "$@"
|