Skip to content

Commit 668eb2b

Browse files
committed
(new sh) Request user-permission to modify bashrc
1 parent 0b86456 commit 668eb2b

2 files changed

Lines changed: 49 additions & 9 deletions

File tree

shell/install.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ c_emph="$c_magenta"
2626
c_path="$c_green"
2727

2828
print() ( IFS=" " printf "$c_fg%s$c_reset\n" "$*" )
29+
print_n() ( IFS=" " printf "$c_fg%s$c_reset" "$*" )
2930
log() ( IFS=" " printf "$c_log%s$c_reset\n" "$*" )
3031
error() ( IFS=" " printf "$c_err%s$c_reset\n" "$*" >&2 )
3132

@@ -66,6 +67,29 @@ ensure_alias () {
6667
fi
6768
}
6869

70+
ensure_aliases () {
71+
code_sh_path="$1"
72+
code_connect_sh_path="$2"
73+
print_n "May I modify your ${c_path}~/.bashrc${c_fg}? [yN] "
74+
read -r yn
75+
76+
case $yn in
77+
[Yy]*)
78+
# Add the aliases to ~/.bashrc if not already done
79+
ensure_alias "code" "$code_sh_path"
80+
ensure_alias "code-connect" "$code_connect_sh_path"
81+
82+
;;
83+
*)
84+
print "Okay; make sure to add the following to your shell-profile manually:"
85+
print "alias code='$code_sh_path'"
86+
print "alias code-connect='$code_connect_sh_path'"
87+
;;
88+
esac
89+
90+
printf \\n
91+
}
92+
6993

7094
#####
7195

@@ -96,13 +120,8 @@ chmod +x "$CODE_CONNECT_SH"
96120

97121
printf \\n
98122

123+
ensure_aliases "$CODE_SH" "$CODE_CONNECT_SH"
99124

100-
# Add the aliases to ~/.bashrc if not already done
101-
ensure_alias "code" "$CODE_SH"
102-
ensure_alias "code-connect" "$CODE_CONNECT_SH"
103-
104-
105-
printf \\n
106125
print "${c_emph}code-connect${c_fg} installed to ${c_path}$CODE_CONNECT_INSTALL_DIR${c_fg} successfully!"
107126
printf \\n
108127
print "Restart your shell or reload your ${c_path}.bashrc${c_fg} to see the changes."

shell/uninstall.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ c_emph="$c_magenta"
2323
c_path="$c_green"
2424

2525
print() ( IFS=" " printf "$c_fg%s$c_reset\n" "$*" )
26+
print_n() ( IFS=" " printf "$c_fg%s$c_reset" "$*" )
2627
log() ( IFS=" " printf "$c_log%s$c_reset\n" "$*" )
2728
error() ( IFS=" " printf "$c_err%s$c_reset\n" "$*" >&2 )
2829

@@ -37,7 +38,7 @@ alias_exists () {
3738

3839
remove_alias () {
3940
name="$1"
40-
if alias-exists "$name"; then
41+
if alias_exists "$name"; then
4142
log "Removing alias ${c_emph}$name${c_log} from ${c_path}~/.bashrc"
4243
sed -i "/alias $name=/d" ~/.bashrc
4344
else
@@ -46,11 +47,31 @@ remove_alias () {
4647
unalias "$name" > /dev/null 2>&1
4748
}
4849

50+
remove_aliases () {
51+
print_n "May I modify your ${c_path}~/.bashrc${c_fg}? [yN] "
52+
read -r yn
53+
54+
case $yn in
55+
[Yy]*)
56+
# Add the aliases to ~/.bashrc if not already done
57+
remove_alias "code"
58+
remove_alias "code-connect"
59+
60+
;;
61+
*)
62+
print "Okay; make sure to remove the following from your shell-profile manually:"
63+
print "alias code='...'"
64+
print "alias code-connect='...'"
65+
;;
66+
esac
67+
68+
printf \\n
69+
}
70+
4971

5072
#####
5173

52-
remove_alias "code"
53-
remove_alias "code-connect"
74+
remove_aliases
5475

5576
log "Removing ${c_path}$CODE_CONNECT_INSTALL_DIR"
5677
rm -rf $CODE_CONNECT_INSTALL_DIR

0 commit comments

Comments
 (0)