-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsh
executable file
·134 lines (114 loc) · 2.56 KB
/
jsh
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
129
130
131
132
133
134
#!/bin/bash
set -e
# color bash output
RED='\033[0;31m'
BLUE='\033[0;34m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# required path
export WORKDIR=$(cd $(dirname $0) && pwd)
export REGISTRY=s3://jsh-release/profiles/
# help command
help() {
echo -e " ${GREEN}
_ _
(_)___| |__
| / __| '_ \\
| \__ \ | | |
_/ |___/_| |_|
|__/
${NC}
Version: 1.0
Usage: jsh [command]
Commands:
${GREEN}upload${NC} upload profile
${GREEN}list${NC} list available profiles
${GREEN}view${NC} view profile
${GREEN}load${NC} load profile
"
exit 1
}
# upload command
upload() {
help_upload() {
echo -e "Usage: jsh ${GREEN}upload${NC} [PATH]"
exit 1
}
[ -z "$1" ] && help_upload
echo -e "... Uploading ${BLUE}$1${NC}"
aws s3 cp "$1" ${REGISTRY} --quiet
echo -e "${GREEN}✔${NC} Successfully ${GREEN}uploaded${NC} ${BLUE}$1${NC}"
}
# list command
list() {
(
printf ${GREEN}"PROFILES${NC}\n"
aws s3 ls ${REGISTRY} | awk '{print $4}'
) | column -t
}
# view command
view() {
help_view() {
echo -e "Usage: jsh ${GREEN}view${NC} [PATH]"
exit 1
}
[ -z "$1" ] && help_view
echo -e "... Fetching ${BLUE}$1${NC}\n"
aws s3 cp ${REGISTRY}${1} /dev/stdout
echo -e "\n\n${GREEN}✔${NC} Successfully ${GREEN}fetched${NC} ${BLUE}$1${NC}"
}
# load command
load() {
help_load() {
echo -e "Usage: jsh ${GREEN}load${NC} [USER]"
exit 1
}
[ -z "$1" ] && help_load
# define default variables
USER=$1
JSHRC=/tmp/jsh/current_profile.jshrc
echo -e "... Fetching ${BLUE}$1${NC}"
aws s3 cp --quiet ${REGISTRY}${USER} ${JSHRC}
echo -e "${GREEN}✔${NC} Successfully ${GREEN}fetched${NC} ${BLUE}$1${NC}"
# identify SHELL based on *.jshrc
eval $(awk '/JSH_SHELL/{print $2}' ${JSHRC})
case $JSH_SHELL in
"zsh")
echo -e "${BLUE}✔${NC} Setting up ${BLUE}zsh${NC} shell"
echo 'export PROMPT="$bg[green]% $fg[black]% %n@jshrc ▶ %c%{$reset_color%} ㇇"' >>${JSHRC}
sleep 1
JSHRC=$JSHRC USER=$USER zsh -is <<<'source ${JSHRC}; \
clear; echo ✔ Successfully loaded ${USER}; \
exec </dev/tty;'
;;
"bash")
echo -e "${GREEN}✔${NC} Setting up ${GREEN}bash${NC} shell"
echo 'export PS1="\e[0;42m\u@jsh ▶ \W\e[m ㇇"' >>${JSHRC}
sleep 1
JSHRC=$JSHRC USER=$USER bash -i <<<'source ${JSHRC}; \
clear; echo ✔ Successfully loaded ${USER}; \
exec </dev/tty;'
;;
*)
echo -e "${RED}missing JSH_SHELL in *.jshrc!${NC}"
;;
esac
}
# "main"
case "$1" in
upload)
upload "$2"
;;
list)
list
;;
view)
view "$2"
;;
load)
load "$2"
;;
*)
help
;;
esac