-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsealion-setup
executable file
·110 lines (97 loc) · 2.57 KB
/
sealion-setup
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
#!/bin/sh
CONF_DIR="$HOME/.config"
SYS_DIR="/usr/share/sealion"
# msg outputs a topic + green message, with a final newline
msg() {
local topic="$1"
shift
if [ ! -z "$*" ]; then
printf "%b" "* \e[1;37m[\e[0m\e[1;34m$topic\e[0m\e[1;37m]"
printf ' %.0s' $(seq ${#topic} 10)
printf "%b\n" "\e[0;32m$*\e[0m"
fi
}
setup_zsh() {
# Set up zsh, if not already set up
if [ -f ~/.zshrc ]; then
already=0
grep -q -F 'precmd() {' ~/.zshenv && already=1
grep -q -F 'precmd() {' ~/.zshrc && already=1
if [ "$already" == "1" ]; then
msg zsh 'Already set up'
else
msg zsh 'Setting up'
cat << EOF >> ~/.zshrc
# Prompt Reminder
on() {
precmd() { /usr/bin/sealion }
off() { unset -f precmd }
}
# Enable prompt messages if on the right host and not over ssh
[ "\$HOST" = "$HOSTNAME" ] && [ ! -n "\$SSH_TTY" ] && on || true
EOF
fi
fi
}
setup_bash() {
# Set up bash, if not already set up
if [ -f ~/.bashrc ]; then
already=0
grep -q -F PROMPT_COMMAND= ~/.bash_profile && already=1
grep -q -F PROMPT_COMMAND= ~/.bashrc && already=1
if [ "$already" == "1" ]; then
msg bash 'Already set up'
else
msg bash 'Setting up'
cat << EOF >> ~/.bashrc
# Prompt Reminder
on() {
export PROMPT_COMMAND="/usr/bin/sealion"
off() { unset PROMPT_COMMAND; }
}
# Enable prompt messages if on the right host and not over ssh
[ \$HOSTNAME = "$HOSTNAME" ] && [ ! -n "\$SSH_TTY" ] && on || true
EOF
fi
fi
}
setup_fish() {
# Set up fish, if not already set up
if [ -d ~/.config/fish ]; then
already=0
grep -q -F 'function sealion --on-event fish_prompt' ~/.config/fish/config.fish 2>/dev/null && already=1
if [ "$already" == "1" ]; then
msg fish 'Already set up'
else
msg fish 'Setting up'
cat << EOF >> ~/.config/fish/config.fish
# Prompt Reminder
function on
function sealion --on-event fish_prompt
/usr/bin/sealion
end
function off
functions -e sealion
end
end
# Enable prompt messages if on the right host and not over ssh
if [ (hostname) = "$HOSTNAME" ]; and not count \$SSH_TTY > /dev/null; on; end
EOF
fi
fi
}
main() {
# Install default config to ~/$CONF_DIR/sealion.conf
if [ ! -f "$CONF_DIR/sealion.conf" ]; then
msg 'sealion.conf' "Installing to $CONF_DIR/sealion.conf"
install -Dm644 "$SYS_DIR/sealion.example.conf" "$CONF_DIR/sealion.conf"
else
msg 'sealion.conf' "Already in place: $CONF_DIR/sealion.conf"
fi
# Setup shells
setup_zsh
setup_fish
setup_bash
echo -e "\nAll done. Now run \$SHELL, or open a new terminal emulator window.\n"
}
main