-
Notifications
You must be signed in to change notification settings - Fork 1
/
vem.sh
executable file
·109 lines (88 loc) · 2.83 KB
/
vem.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
# vim environment management
# https://en.wikibooks.org/wiki/Bash_Shell_Scripting[Bash Shell Scripting - Wikibooks, open books for an open world]
# http://wiki.bash-hackers.org/howto/getopts_tutorial[Small getopts tutorial [Bash Hackers Wiki]]
# https://github.com/alebcay/awesome-shell[alebcay/awesome-shell: A curated list of awesome command-line frameworks, toolkits, guides and gizmos. Inspired by awesome-php.]
if ! [[ -d $HOME/VIM ]]; then
echo 'generate ~/VIM for save settings'
mkdir $HOME/VIM
fi
if [[ -e $HOME/.vimrc ]] && [[ -d $HOME/.vim ]]; then
echo ".vimrc and .vim exist"
else
echo "no .vimrc and .vim diretory"
fi
# copy ~/.vim, ~/.vimrc to ~/VIM/somedir
backup() {
if [[ "$1" == 't' ]]; then
dir=`date +"%s"`
else
dir=$1
fi
mydir=$HOME/VIM/$dir
mkdir $mydir
cp -pr $HOME/.vim $mydir
cp -p $HOME/.vimrc $mydir
echo "backup $# $mydir done"
}
# delete ~/.vimrc and ~/.vim
to_empty() {
case "$1" in
[yY])
echo "you say Y"
echo "remove .vimrc, .vim"
rm $HOME/.vimrc
rm -rf $HOME/.vim
;;
*)
echo "do nothing";;
esac
}
# restore VIM repo to HOME
restore() {
if [[ -e $HOME/.vimrc ]] || [[ -d $HOME/.vim ]]; then
echo "Home have .vimrc or .vim, empty first"
exit 0
elif [[ -d $HOME/VIM/$1 ]]; then
echo "will restore to HOME"
cp -p $HOME/VIM/$1/.vimrc $HOME/.vimrc
cp -rp $HOME/VIM/$1/.vim $HOME/.vim
else
echo "no $1 dir"
fi
}
__ScriptVersion="0.1"
#=== FUNCTION ================================================================
# NAME: usage
# DESCRIPTION: Display usage information.
#===============================================================================
function usage ()
{
echo "Usage : $0 [options] [--]
Options:
-h|help Display this message
-v|version Display script version
-l|list List VIM repos
-c|create Create VIM repos dir
-r|restore restore from VIM repos
-e|empty empty .vimrc .vim
-b|backup backup .vim* to VIM repos dir"
} # ---------- end of function usage ----------
#-----------------------------------------------------------------------
# Handle command line arguments
#-----------------------------------------------------------------------
while getopts ":hvleb:c:r:" opt
do
case $opt in
h|help ) usage; exit 0 ;;
v|version ) echo "$0 -- Version $__ScriptVersion"; exit 0 ;;
l|list ) ls -l $HOME/VIM; exit 0 ;;
e|empty ) read -r -p "確認要刪嗎?[y/N] " response; to_empty $response; exit 0 ;;
b|backup ) backup $OPTARG; exit 0 ;;
r|restore ) restore $OPTARG; exit 0 ;;
c|create ) echo "will create $HOME/VIM/$OPTARG"; exit 0 ;;
* ) echo -e "\n Option does not exist : $OPTARG\n"
usage; exit 1 ;;
esac # --- end of case ---
done
shift $(($OPTIND-1))