-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.sh
executable file
·95 lines (88 loc) · 3.1 KB
/
chat.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
#!/usr/bin/env bash
CYAN='\033[0;36m'
GREEN='\033[0;32m'
RED='\033[0;31m'
RC='\033[0m' # Reset Color
git config alias.chatlog "log --reverse --pretty=\"format:%C(green)%aN %C(blue)[%ad]%C(reset)%n%B\" --date=relative"
commands() {
echo "Commands:"
echo -e "${GREEN}/quit or /exit${RC} (to quit chat)"
echo -e "${GREEN}/help${RC} (print list of supported commands)"
echo -e "${GREEN}/switch <channel name>${RC} (to change #channel"
echo -e "${GREEN}/create <channel name>${RC} (to create a new #channel)"
echo -e "${GREEN}/list${RC} (to list channels)"
echo -e "${GREEN}/repeat [n]${RC} (repeat last n messages - default 5)"
echo -e "${GREEN}/post${RC} (write a post aka. multiline message via your regular git message editor)"
}
welcome() {
echo -e "${CYAN}Welcome to GitSlick, the Git based miniature chat app.${RC}"
echo
commands
echo -e "Anything else is treated as a chat message. It will be commited to current dir git repo and pushed immediately to origin"
echo -e "with NO safety checks or error handling".
echo
echo -e "NOTE: Currently only really supports single line messages. Behaviour undefined if pasting multiline content."
echo -e "But you can now use the ${GREEN}/post${RC} feature if you want to send multiline content."
echo
echo -e "You are currenty in folder ${RED}$(pwd)${RC}"
echo -e "And pushing to ${RED}$(git remote get-url origin --push)${RC}"
echo
}
title(){
BASE=$(basename -s .git "$(git config --get remote.origin.url)")
BRANCH=$(git branch --show-current)
TITLE="#$BRANCH @ $BASE"
printf '\033]2;%s\a' "$TITLE"
#printf "\[\e]2;%s\a\]"
}
welcome
title
fetch_print_ff() {
git fetch --quiet
git chatlog "..@{u}"
git merge --ff-only --quiet
}
fetch_print_ff
while true ; do
while IFS=" " read -r -e -p "$(git branch --show-current)> " cm options; do
fetch_print_ff
echo
if [ "$cm" = "" ]; then
:
elif [ "$cm" = "/quit" ]; then
exit 0
elif [ "$cm" = "/exit" ]; then
exit 0
elif [ "$cm" = "/help" ]; then
commands
echo
elif [ "$cm" = "/switch" ]; then
git switch "$options"
title
echo "Showing last 5 messages in $options"
git chatlog -5
elif [ "$cm" = "/list" ]; then
echo -e "Existing channels: (use ${GREEN}/switch <channelname>${RC} to change channel"
git branch -a
elif [ "$cm" = "/create" ]; then
echo "Creating new channel $options"
git switch --quiet --orphan "$options"
git commit --allow-empty --message "Beginning of Channel $options"
git push --set-upstream --quiet origin "$options"
title
elif [ "$cm" = "/repeat" ]; then
: "${options:=5}"
echo -e "Repeating last $options messages in ${RED}$(git branch --show-current)${RC}"
git chatlog "-$options"
elif [ "$cm" = "/post" ]; then
git commit --quiet --allow-empty
git chatlog -1
git push --quiet origin
else
message="$cm $options"
git commit --quiet --allow-empty --message "$message"
git chatlog -1
git push --quiet origin
fi
done
done