Skip to content

Instantly share code, notes, and snippets.

@weirongxu
Last active August 29, 2015 14:00
Show Gist options
  • Save weirongxu/11203629 to your computer and use it in GitHub Desktop.
Save weirongxu/11203629 to your computer and use it in GitHub Desktop.
rsync dotfile
# hosts
/etc/hosts
# dotfile
~/.config/smplayer/smplayer.ini
~/compiz_bacpup.profile
~/_gdbinit
~/.remmina/
~/.bashrc
~/.zshrc
~/.shrc
~/.bypy.json
~/.ctags
~/.gitconfig
~/.npmrc
~/.evernote-devtoken
~/.record/
# nginx
/etc/nginx/nginx.conf
/etc/nginx/sites-available/default
/etc/nginx/sites-enabled/default
/etc/nginx/fastcgi.conf
/etc/nginx/proxy_params
# themes
~/.themes/FlatStudioGray/
~/.themes/Win8-03-Anakiwa/
~/.themes/Numix/
~/.themes/Numix-Darker/
# vim
~/.vim/
~/.vimrc
~/.nvimrc
#!/usr/bin/env bash
rsync_file='rsync -ai'
rsync_dir='rsync -ai --delete'
target_dir='dotfile'
start_num=0
while read line
do
((start_num++))
front=${line:0:2}
front1=${front:0:1}
back=${line:0-1:1}
if [[ -z "$line" || "$front1" = '#' ]]; then
# useless line
continue
elif [[ "$front" = '~/' ]]; then
# generate target
target=$target_dir/${line#*/}
elif [[ "$front1" = '/' ]]; then
target=$target_dir/root/${line#*/}
# elif [[ "$front1" = '!' ]]; then
# TODO exclude file
else
# error
echo -e "\e[00;31mline: $start_num, '$line' must start with '~/' or '/'.\e[00m"
read -n 1 -p '(Enter)'
break
fi
source=${line/#~/$HOME}
if [[ $back = '/' ]]; then
# dir
echo $rsync_dir "$source" "$target"
$rsync_dir "$source" "$target"
elif [[ -d $source ]]; then
# dir
echo $rsync_dir "$source" "$target/"
$rsync_dir "$source" "$target/"
elif [[ -e $source ]]; then
# file
echo $rsync_file "$source" "$target"
dir=`dirname $target`
if [[ ! -d $dir ]]; then
mkdir -p $dir
fi
$rsync_file "$source" "$target"
else
# error
echo -e "\e[00;31mline: $start_num, '$line' file not exist.\e[00m"
read -n 1 -p '(Enter)'
break
fi
done < rsync-list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment