-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitCli
executable file
·128 lines (121 loc) · 3.37 KB
/
GitCli
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
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
usage()
{
cat <<- EOF
Github Manager with Github-CLI
Command Format : GitRepo <command> <option(s)>
GitRepo: [-h|--help] [-c|--create] [-l|--list] [-i|--info] [-d|--delete] [-f|--fuzzy] [-s|--search]
EOF
}
createRepo()
{
echo "##########################################################"
echo "Github Repositories creator "
echo "##########################################################"
read -rp "Enter Repository name : " name
read -rp "private or public (default:private) : " status
read -rp "Enter Repository description (Press Enter to leave Empty) : " description
read -rp "Do you want to clone the Repository in your current directory (y/n) : " clone
if [ -z "$name" ];then
echo "Must Provide Repository name!"
else
if [ -z "$status" ] || [ "$status" == "private" ];then
case $clone in
([yY]|[yY]|[eE]|[sS])
gh repo create "$name" --private --clone -d "$description"
;;
([nN]|[nN]|[oO])
gh repo create "$name" --private -d "$description"
;;
esac
elif [ "$status" == "public" ];then
gh repo create "$name" "--${status}" -d "$description"
else
echo "Invalid Input"
fi
fi
}
deleteRepo()
{
listRepo
read -r "Enter Repository Name to delete : " name
gh repo delete "$name"
}
fuzzyDiff()
{
fzf_options=(
--reverse
--ansi
--prompt='[Commit] > '
--bind="ctrl-u:preview-page-up"
--bind="ctrl-d:preview-page-down"
--bind="ctrl-k:preview-up"
--bind="ctrl-j:preview-down"
--preview="echo {} | cut -d ' ' -f 1 | xargs -I % sh -c 'git show %'"
--preview-window='down:75%'
)
git log --oneline "$@" | fzf "${fzf_options[@]}"
}
help_message()
{
cat << EOF
##########################################################
Available Options For Script.
-i --info Display Infos about Repositories
-h --help Display Description And Options For this Script
-l --list List Repositories Linked to account
-c --create Create Repository and Clone it to current path
-f --fuzzy Fuzzy search for diff in current repo
-d --delete List Repositories Linked to account
-s --search Search and Output Informations about a Repository
##########################################################
EOF
}
listRepo()
{
echo "#################################"
gh repo list
echo "#################################"
}
searchRepo()
{
read -r "Enter Repository name to search :" name
gh search repos "$name"
}
statusInfo()
{
echo "#################################"
gh status
echo "#################################"
}
if [ "$#" -eq 0 ];then
usage
exit 1
else
case $1 in
-c|--create)
createRepo
;;
-d|--delete)
deleteRepo
;;
-h|--help)
help_message
;;
-i|--info)
statusInfo
;;
-f|--fuzzy)
fuzzyDiff
;;
-l|--list)
listRepo
;;
-s|--search)
searchRepo
;;
*)
usage
;;
esac
fi