Skip to content

Commit 283ed2d

Browse files
committed
suggest method that directly activate shsh
Signed-off-by: Tin Lai <[email protected]>
1 parent b246571 commit 283ed2d

File tree

2 files changed

+67
-65
lines changed

2 files changed

+67
-65
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Shsh is a POSIX-compatible script handler, as a former fork of [basher](https://
2626

2727
Automatically bootstrap and install `shsh` (which would also modify your shell's init script)
2828
```sh
29-
curl -s https://raw.githubusercontent.com/soraxas/shsh/master/bootstrap/install.sh | sh
29+
source <(https://raw.githubusercontent.com/soraxas/shsh/master/bootstrap/install.sh)
3030
```
3131

3232
### Pre-made Recipes

bootstrap/install.sh

+66-64
Original file line numberDiff line numberDiff line change
@@ -5,78 +5,80 @@ set -e
55
# source shsh environment variable
66
eval "$(curl -s https://raw.githubusercontent.com/soraxas/shsh/master/libexec/shsh-_env-var)"
77

8-
## stop if basher is already installed
9-
if [ -d "$SHSH_ROOT" ]; then
10-
error_echo "shsh already exists at '$SHSH_ROOT'."
11-
error_echo "Delete it if you want to start this bootstrap process again."
12-
exit 1
13-
fi
8+
main() {
9+
## stop if basher is already installed
10+
if [ -d "$SHSH_ROOT" ]; then
11+
error_echo "shsh already exists at '$SHSH_ROOT'."
12+
error_echo "Delete it if you want to start this bootstrap process again."
13+
exit 1
14+
fi
1415

1516

16-
info_echo "Installing shsh to '$SHSH_ROOT'"
17-
git clone https://github.com/soraxas/shsh.git "$SHSH_ROOT" > /dev/null
17+
info_echo "Installing shsh to '$SHSH_ROOT'"
18+
git clone https://github.com/soraxas/shsh.git "$SHSH_ROOT" > /dev/null
1819

19-
# Check shell type
20-
shell_type=$(basename "$SHELL")
21-
info_echo "Detected shell type: $shell_type"
22-
case "$shell_type" in
23-
bash) startup_type="simple" ; startup_script="$HOME/.bashrc" ;;
24-
zsh) startup_type="simple" ; startup_script="$HOME/.zshrc" ;;
25-
sh) startup_type="simple" ; startup_script="$HOME/.profile";;
26-
fish) startup_type="fish" ; startup_script="$HOME/.config/fish/config.fish" ;;
27-
*)
28-
error_echo "Unknown shell '$shell_type'."
29-
error_echo "Perhaps set the \$SHELL environment variable to your shell type before running this?"
30-
error_echo "e.g. export SHELL=bash"
31-
exit 1
32-
;;
33-
esac
20+
# Check shell type
21+
shell_type=$(basename "$SHELL")
22+
info_echo "Detected shell type: $shell_type"
23+
case "$shell_type" in
24+
bash) startup_type="simple" ; startup_script="$HOME/.bashrc" ;;
25+
zsh) startup_type="simple" ; startup_script="$HOME/.zshrc" ;;
26+
sh) startup_type="simple" ; startup_script="$HOME/.profile";;
27+
fish) startup_type="fish" ; startup_script="$HOME/.config/fish/config.fish" ;;
28+
*)
29+
error_echo "Unknown shell '$shell_type'."
30+
error_echo "Perhaps set the \$SHELL environment variable to your shell type before running this?"
31+
error_echo "e.g. export SHELL=bash"
32+
exit 1
33+
;;
34+
esac
3435

3536

36-
if [ ! -f "$startup_script" ]; then
37-
touch "$startup_script"
38-
fi
37+
if [ ! -f "$startup_script" ]; then
38+
touch "$startup_script"
39+
fi
3940

4041

41-
## now add the basher initialisation lines to the user's startup script
42-
info_echo "Adding shsh initialisation"
43-
#shellcheck disable=SC2016
44-
case "$startup_type" in
45-
simple)
46-
printf '%s\n' '' >>"$startup_script"
47-
printf '%s\n' 'export SHSH_ROOT="'"$SHSH_ROOT"'"' >>"$startup_script"
48-
printf '%s\n' 'export PATH="$SHSH_ROOT/bin:$PATH"' >>"$startup_script"
49-
printf '%s\n' 'eval "$(shsh init '"$shell_type"')"' >>"$startup_script"
50-
;;
51-
fish)
52-
printf '%s\n' '' >>"$startup_script"
53-
printf '%s\n' 'set -gx SHSH_ROOT "'"$SHSH_ROOT"'"' >>"$startup_script"
54-
printf '%s\n' 'set -p PATH "$SHSH_ROOT/bin"' >>"$startup_script"
55-
printf '%s\n' 'status --is-interactive; and shsh init fish | source' >>"$startup_script"
56-
;;
57-
*)
58-
error_echo "Unknown shell '$shell_type'."
59-
error_echo "Perhaps set the \$SHELL environment variable to your shell type before running this?"
60-
error_echo "e.g. export SHELL=bash"
61-
exit 1
62-
;;
63-
esac
42+
## now add the basher initialisation lines to the user's startup script
43+
info_echo "Adding shsh initialisation"
44+
#shellcheck disable=SC2016
45+
case "$startup_type" in
46+
simple)
47+
printf '%s\n' '' >>"$startup_script"
48+
printf '%s\n' 'export SHSH_ROOT="'"$SHSH_ROOT"'"' >>"$startup_script"
49+
printf '%s\n' 'export PATH="$SHSH_ROOT/bin:$PATH"' >>"$startup_script"
50+
printf '%s\n' 'eval "$(shsh init '"$shell_type"')"' >>"$startup_script"
51+
;;
52+
fish)
53+
printf '%s\n' '' >>"$startup_script"
54+
printf '%s\n' 'set -gx SHSH_ROOT "'"$SHSH_ROOT"'"' >>"$startup_script"
55+
printf '%s\n' 'set -p PATH "$SHSH_ROOT/bin"' >>"$startup_script"
56+
printf '%s\n' 'status --is-interactive; and shsh init fish | source' >>"$startup_script"
57+
;;
58+
*)
59+
error_echo "Unknown shell '$shell_type'."
60+
error_echo "Perhaps set the \$SHELL environment variable to your shell type before running this?"
61+
error_echo "e.g. export SHELL=bash"
62+
exit 1
63+
;;
64+
esac
6465

65-
# self-linking
66-
(
67-
cd "$SHSH_ROOT"
68-
if command -v make >/dev/null 2>&1; then
69-
# use built-in make command
70-
make self-linking
71-
else
72-
# mamually link
73-
ln -srf "bin/shsh" "$SHSH_ROOT/cellar/bin/shsh"
74-
ln -srf completions/shsh.bash $SHSH_ROOT/cellar/completions/bash/shsh.bash
75-
ln -srf completions/shsh.fish $SHSH_ROOT/cellar/completions/fish/shsh.fish
76-
ln -srf completions/shsh.zsh $SHSH_ROOT/cellar/completions/zsh/compctl/shsh.zsh
77-
fi
78-
)
66+
# self-linking
67+
(
68+
cd "$SHSH_ROOT"
69+
if command -v make >/dev/null 2>&1; then
70+
# use built-in make command
71+
make self-linking
72+
else
73+
# mamually link
74+
ln -srf "bin/shsh" "$SHSH_ROOT/cellar/bin/shsh"
75+
ln -srf completions/shsh.bash "$SHSH_ROOT/cellar/completions/bash/shsh.bash"
76+
ln -srf completions/shsh.fish "$SHSH_ROOT/cellar/completions/fish/shsh.fish"
77+
ln -srf completions/shsh.zsh "$SHSH_ROOT/cellar/completions/zsh/compctl/shsh.zsh"
78+
fi
79+
)
80+
}
7981

8082
# restart shell
81-
exec "$SHELL" -l
83+
main && echo exec "$SHELL"
8284

0 commit comments

Comments
 (0)