-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.sh
71 lines (63 loc) · 1.43 KB
/
helper.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
# wrapper functions
error()
{
>&2 echo -e "${BRED}Error${NC}: $1"
}
warning()
{
>&2 echo -e "${BYELLOW}Warning${NC}: $1"
}
_usage()
{
echo -e "${BYELLOW}Usage${NC}: $1"
}
_config()
{
echo -e "${BYELLOW}$1${NC} [Default: $2]"
echo -e "$3"
}
_git()
{
PWD=$(pwd)
cd "${DIRECTORY}" || exit 1
case "$1" in
add)
git add "$2"
git commit -m "Added $2"
;;
edit)
git add "$2"
git commit -m "Edited $2"
;;
move)
git rm "$2"
git add "$3"
git commit -m "Moved $2 to $3"
;;
delete)
git rm "$2"
git commit -m "Deleted $2"
;;
*)
error "Unknown internal git operation"
echo "Aborting..."
;;
esac
if [ "$(git status -s | wc -l)" != "0" ]; then
warning "There are unstaged changes in your repo!"
read -rp "Would you like to work on this? [Yes/no] " choice
case "${choice}" in
(n*|N*)
cd "${PWD}" || exit 1
;;
*)
warning "You will be dropped into a subshell inside your notes directory!"
echo -e "You can leave by typing '${BRED}exit${NC}'"
cd "${DIRECTORY}" || exit 1
exec "${SHELL}"
;;
esac
else
cd "${PWD}" || exit 1
fi
}