-
Notifications
You must be signed in to change notification settings - Fork 1
/
gig
executable file
·119 lines (114 loc) · 3.27 KB
/
gig
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
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
delete=
lang=
edit=
generate=
view=
TEMPLATE_DIR="$HOME/.GiG/GitIgnoreTemplates"
GITIGNORE=".gitignore"
CREDITS="# This gitignore is generated using https://github.com/prdpx7/GiG/"
function show_usage()
{
echo '
Usage: [-a] [-d] [-e] [-g] [-h] [-l LANG] [-v] [-u]
Optional Arguments:
-a , --all : display available gitignore template list
-d , --delete : delete default gitignore template for given -l LANG
-e , --edit : Edit the default gitignore template for given -l LANG
-g , --generate : generate new gitignore template or append if already exist for given -l LANG
-h , --help : show this help message and exit
-l LANG, --lang LANG : Specify language(full name not just extension) to generate their respective gitignore template
-v, --view : view gitignore template for given -l LANG in less mode
-u, --update : pull recent update
Examples:
$ gig -l python -e #edit the default python gitignore template
$ gig -l node -v #view default node gitignore template
$ gig -l c++ -g #generate c++ gitignore template in present directory(append content if already exist)
$ gig --all
actionscript.gitignore
ada.gitignore
android.gitignore
...
...
'
}
function is_exist()
{
if [ ! -f "$TEMPLATE_DIR/$lang.gitignore" ];then
echo "Not a valid language name(should use full name): for more info try gig --help"
exit 1
fi
}
function main()
{
while [ $# -gt 0 ]; do
case $1 in
-h|--help)
show_usage
exit
;;
-l|--lang)
lang=`echo $2 | tr "A-Z" "a-z"`
is_exist $lang
shift
;;
-a|--all)
ls $TEMPLATE_DIR/*.gitignore | xargs -n 1 basename
exit 0
;;
-v|--view)
view=1
shift
;;
-e|--edit)
edit=1
shift
;;
-g|--generate)
generate=1
shift
;;
-d|--delete)
delete=1
shift
;;
-u|--update)
if [ ! -d $HOME/.GiG ];then
echo "looks like you have chosen different clone path"
exit 1
fi
~/.GiG/install.sh
exit 0
;;
-?*)
printf 'WARNING: Unknown option (ignored): %s\n' "$1" >&2
shift
;;
*)
shift
;;
esac
done
is_exist $lang
lang_path="$TEMPLATE_DIR/$lang.gitignore"
if [ $view ];then
less "$lang_path" ;
elif [ $generate ];then
cat "$lang_path" >> $GITIGNORE ;
echo "Added gitignore attributes for $lang !!!" ;
first_line=$(head -1 $GITIGNORE)
if [ "$first_line" != "$CREDITS" ]; then
sed -i "1i$CREDITS" $GITIGNORE
fi
elif [ $edit ];then
$EDITOR "$lang_path" ;
elif [ $delete ];then
echo "Do you really want to delete $lang_path (y/n):" ;
read ch ;
ch=$(echo $ch | tr "A-Z" "a-z") ;
if [ $ch = "y" ];then
rm "$lang_path" ;
fi
fi
}
main "$@"