Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 167 lines (148 sloc) 3.69 KB
#!/bin/bash
main()
{
sync "@/org/gnome/terminal"
sync "@/org/gnome/shell"
sync "~/.config/nvim/init.vim"
sync "~/.config/nvim/plugins.vim"
sync "~/.config/nvim/rc"
sync "~/.config/nvim/syntax"
sync "~/.config/nvim/autoload"
sync "~/.config/nvim/ftdetect"
sync "~/.config/nvim/indent"
sync "~/.config/fish"
sync "~/.config/gtk-3.0"
sync "~/.config/Code/User/keybindings.json"
sync "~/.config/Code/User/settings.json"
sync "~/.vscode/extensions"
sync "~/.local/share/rhythmbox" -i
sync "~/.local/share/keyrings/pppoe.keyring" -i
sync "~/.local/share/gnome-shell/extensions"
sync "~/.elinks/elinks.conf"
sync "~/.emacs"
sync "~/.emacs.d"
sync "~/.task" -i
sync "~/.taskrc"
sync "~/.tmux.conf"
sync "~/.gitconfig"
sync "~/.gitignore"
sync "~/bin/local"
sync "/etc/profile"
sync "/etc/profile.d"
sync "/etc/fonts"
sync "/etc/pacman.d/hooks"
sync "/etc/pacman.d/mirrorlist"
sync "/etc/pacman.d/mirrorlist-archlinuxcn"
sync "/etc/default"
sync "/etc/hosts"
sync "/etc/yaourtrc"
sync "/etc/sudoers"
sync "/etc/locale.conf"
sync "/etc/makepkg.conf"
sync "/etc/pacman.conf"
sync "/etc/mkinitcpio.conf"
sync "/home/public/fonts"
sync "/home/public/wallpaper"
sync "/usr/local/bin/makeless"
}
sync()
{
if [[ $1 == $HOME/* || $1 == @*/ || ! ( $1 == /* || $1 == "~"/* || $1 == @/* ) ]]; then
echo -e "! \e[1;31mHUMAN ERROR PREVENTION \e[0;31m$1\e[0m"
exit 3
fi
if ! [[ -z $2 || $2 == -i ]]; then
echo -e "! \e[1;31mHUMAN ERROR PREVENTION \e[0;31m$2\e[0m"
exit 3
fi
if [[ $1 == @/* ]]; then
sync-dconf "$1" "$2"
else
SRC=$(realpath -m $(expand-tilde "$1"))
if [[ -d $SRC ]]; then
sync-dir "$1" "$2"
else
sync-regular "$1" "$2"
fi
fi
}
declare -a IGNORES
sync-dir()
{
echo -n "* "
SRC=$(realpath -m $(expand-tilde "$1"))/ # XXX: the trailing slash '/' is IMPORTANT !!!
DST=$(realpath -m --relative-to . $(src-to-dst "$1"))
mkdir -p "$DST"
sync-work "$SRC" "$DST" "$1"
if [[ $2 == -i ]]; then
IGNORES+=("$DST")
fi
}
sync-regular()
{
echo -n " "
SRC=$(realpath -m $(expand-tilde "$1"))
DST=$(realpath -m --relative-to . $(src-to-dst "$1"))
DIR=$(dirname "$DST")
mkdir -p "$DIR"
sync-work "$SRC" "$DST" "$1"
if [[ $2 == -i ]]; then
IGNORES+=("$DST")
fi
}
sync-dconf()
{
echo -n "@ "
ITEM=${1:1}
SRC=$ITEM/
DST=dconf$ITEM
DIR=$(dirname "$DST")
mkdir -p "$DIR"
report-progress "$1" "$SRC" "$DST"
dconf dump "$SRC" > "$DST"
if [[ $2 == -i ]]; then
IGNORES+=("$DST")
fi
}
expand-tilde()
{
eval 'echo '"$1"
}
src-to-dst()
{
echo "$@" | sed 's/^~\///; s/^\/etc\///; s/^\///'
}
report-progress()
{
WS=$(tput cols)
W1=$((WS * 26 / 80))
W2=$((WS * 30 / 80))
W3=$((WS * 18 / 80))
F1=$(fix-string-width $W1 $1)
F2=$(fix-string-width $W2 $2)
F3=$(fix-string-width $W3 $3)
echo -e "\e[1;32m$F1 \e[0;34m$F2 \e[0;35m$F3\e[0m"
}
sync-work()
{
if [[ $2 == ..* || $2 == . || $2 == /* || ($2 == home/* && $2 != home/public/*) ]]; then
echo -e "\e[1;31mHUMAN ERROR PREVENTION: \e[1;32m$3 \e[0;34m$1 \e[0;35m$2\e[0m"
exit 2
fi
report-progress "$3" "$1" "$2"
rsync -avhP --delete "$1" "$2" > /dev/null || exit 1
}
# string (int width, string str)
function fix-string-width()
{
if [[ ${#2} -gt $1 ]]; then
echo -n ''
tail -c $1 <<< "$2"
else
printf "%-${1}s" "$2"
fi
}
main "$@"
git add -A
git reset -q -- ${IGNORES[@]}
git commit -vem "#`date -Iseconds`" && git push