Skip to content

Commit 339a06c

Browse files
gpakoszGregory Pakosz
authored andcommitted
added the install.sh installation script, resolves #795
1 parent 23f6e11 commit 339a06c

2 files changed

Lines changed: 200 additions & 4 deletions

File tree

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Installation
2020
------------
2121

22-
Requirements:
22+
**Requirements:**
2323

2424
- tmux **`>= 2.6`** running on Linux, macOS, OpenBSD, Windows (WSL or Cygwin)
2525
- awk, perl (with Time::HiRes support), grep, and sed
@@ -33,23 +33,30 @@ You can install Oh my tmux! at any of the following locations:
3333
- `$XDG_CONFIG_HOME/tmux`
3434
- `~/.config/tmux`
3535

36-
Installing in `~`:
36+
**Automatic installation**
37+
38+
Copy the following command and paste it in your terminal.
39+
```
40+
curl -fsSL "https://github.com/gpakosz/.tmux/raw/refs/heads/master/install.sh#$(date +%s)" | bash
41+
```
42+
43+
**Manual installation in `~`**
3744
```
3845
$ cd
3946
$ git clone --single-branch https://github.com/gpakosz/.tmux.git
4047
$ ln -s -f .tmux/.tmux.conf
4148
$ cp .tmux/.tmux.conf.local .
4249
```
4350

44-
Installing in `$XDG_CONFIG_HOME/tmux`:
51+
**Manual installation in `$XDG_CONFIG_HOME/tmux`**
4552
```
4653
$ git clone --single-branch https://github.com/gpakosz/.tmux.git "/path/to/oh-my-tmux"
4754
$ mkdir -p "$XDG_CONFIG_HOME/tmux"
4855
$ ln -s /path/to/oh-my-tmux/.tmux.conf "$XDG_CONFIG_HOME/tmux/tmux.conf"
4956
$ cp /path/to/oh-my-tmux/.tmux.conf.local "$XDG_CONFIG_HOME/tmux/tmux.conf.local"
5057
```
5158

52-
Installing in `~/.config/tmux`:
59+
**Manual installation `~/.config/tmux`**
5360
```
5461
$ git clone --single-branch https://github.com/gpakosz/.tmux.git "/path/to/oh-my-tmux"
5562
$ mkdir -p ~/.config/tmux

install.sh

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#!/bin/bash
2+
# Oh my tmux!
3+
# 💛🩷💙🖤❤️🤍
4+
# https://github.com/gpakosz/.tmux
5+
# (‑●‑●)> dual licensed under the WTFPL v2 license and the MIT license,
6+
# without any warranty.
7+
# Copyright 2012— Gregory Pakosz (@gpakosz).
8+
#
9+
# ------------------------------------------------------------------------------
10+
# 🚨 PLEASE REVIEW THE CONTENT OF THIS FILE BEFORE BLINDING PIPING TO CURL
11+
# ------------------------------------------------------------------------------
12+
{
13+
if [ ${EUID:-$(id -u)} -eq 0 ]; then
14+
printf '❌ Do not execute this script as root!\n' >&2 && exit 1
15+
fi
16+
17+
if [ -z "$BASH_VERSION" ]; then
18+
printf '❌ This installation script requires bash\n' >&2 && exit 1
19+
fi
20+
21+
if ! tmux -V >/dev/null 2>&1; then
22+
printf '❌ tmux is not installed\n' >&2 && exit 1
23+
fi
24+
25+
is_true() {
26+
case "$1" in
27+
true|yes|1)
28+
return 0
29+
;;
30+
*)
31+
return 1
32+
;;
33+
esac
34+
}
35+
36+
if ! is_true "$PERMISSIVE" && [ -n "$TMUX" ]; then
37+
printf '❌ tmux is currently running, please terminate the server\n' >&2 && exit 1
38+
fi
39+
40+
install() {
41+
printf '🎢 Installing Oh my tmux! Buckle up!\n' >&2
42+
printf '\n' >&2
43+
now=$(date +'%Y%d%m%S')
44+
45+
for dir in "${XDG_CONFIG_HOME:-$HOME/.config}/tmux" "$HOME/.tmux"; do
46+
if [ -d "$dir" ]; then
47+
printf '⚠️ %s directory exists, making a backup → %s\n' "${dir/#"$HOME"/'~'}" "${dir/#"$HOME"/'~'}.$now" >&2
48+
if ! is_true "$DRY_RUN"; then
49+
mv "$dir" "$dir.$now"
50+
fi
51+
fi
52+
done
53+
54+
for conf in "$HOME/.tmux.conf" \
55+
"$HOME/.tmux.conf.local" \
56+
"${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf" \
57+
"${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf.local"; do
58+
if [ -f "$conf" ]; then
59+
if [ -L "$conf" ]; then
60+
printf '⚠️ %s symlink exists, removing → 🗑️\n' "${conf/#"$HOME"/'~'}" >&2
61+
if ! is_true "$DRY_RUN"; then
62+
rm -f "$conf"
63+
fi
64+
else
65+
printf '⚠️ %s file exists, making a backup -> %s\n' "${conf/#"$HOME"/'~'}" "${conf/#"$HOME"/'~'}.$now" >&2
66+
if ! is_true "$DRY_RUN"; then
67+
mv "$conf" "$conf.$now"
68+
fi
69+
fi
70+
fi
71+
done
72+
73+
if [ -d "${XDG_CONFIG_HOME:-$HOME/.config}" ]; then
74+
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/tmux"
75+
OH_MY_TMUX_CLONE_PATH="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/oh-my-tmux"
76+
TMUX_CONF="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"
77+
else
78+
OH_MY_TMUX_CLONE_PATH="$HOME/.tmux"
79+
TMUX_CONF="$HOME/.tmux.conf"
80+
fi
81+
TMUX_CONF_LOCAL="$TMUX_CONF.local"
82+
83+
if [ -d "$OH_MY_TMUX_CLONE_PATH" ]; then
84+
printf '⚠️ %s exists, making a backup\n' "${OH_MY_TMUX_CLONE_PATH/#"$HOME"/'~'}" >&2
85+
printf '%s → %s\n' "${OH_MY_TMUX_CLONE_PATH/#"$HOME"/'~'}" "${OH_MY_TMUX_CLONE_PATH/#"$HOME"/'~'}.$now" >&2
86+
if ! is_true "$DRY_RUN"; then
87+
mv "$OH_MY_TMUX_CLONE_PATH" "$OH_MY_TMUX_CLONE_PATH.$now"
88+
fi
89+
fi
90+
91+
printf '\n'
92+
printf '✅ Using %s\n' "${OH_MY_TMUX_CLONE_PATH/#"$HOME"/'~'}" >&2
93+
printf '✅ Using %s\n' "${TMUX_CONF/#"$HOME"/'~'}" >&2
94+
printf '✅ Using %s\n' "${TMUX_CONF_LOCAL/#"$HOME"/'~'}" >&2
95+
96+
printf '\n'
97+
OH_MY_TMUX_REPOSITORY=${OH_MY_TMUX_REPOSITORY:-https://github.com/gpakosz/.tmux.git}
98+
printf '⬇️ Cloning Oh my tmux! repository...\n' >&2
99+
if ! is_true "$DRY_RUN"; then
100+
if ! git clone -q --single-branch "$OH_MY_TMUX_REPOSITORY" "$OH_MY_TMUX_CLONE_PATH"; then
101+
printf '❌ Failed\n' >&2 && exit 1
102+
fi
103+
fi
104+
105+
printf '\n'
106+
if is_true "$DRY_RUN" || ln -s -f "$OH_MY_TMUX_CLONE_PATH/.tmux.conf" "$TMUX_CONF"; then
107+
printf '✅ Symlinked %s → %s\n' "${TMUX_CONF/#"$HOME"/'~'}" "${OH_MY_TMUX_CLONE_PATH/#"$HOME"/'~'}/.tmux.conf" >&2
108+
fi
109+
if is_true "$DRY_RUN" || cp "$OH_MY_TMUX_CLONE_PATH/.tmux.conf.local" "$TMUX_CONF_LOCAL"; then
110+
printf '✅ Copied %s → %s\n' "${OH_MY_TMUX_CLONE_PATH/#"$HOME"/'~'}/.tmux.conf.local" "${TMUX_CONF_LOCAL/#"$HOME"/'~'}" >&2
111+
fi
112+
113+
tmux() {
114+
${TMUX_PROGRAM:-tmux} ${TMUX_SOCKET:+-S "$TMUX_SOCKET"} "$@"
115+
}
116+
if ! is_true "$DRY_RUN" && [ -n "$TMUX" ]; then
117+
tmux set-environment -g TMUX_CONF "$TMUX_CONF"
118+
tmux set-environment -g TMUX_CONF_LOCAL "$TMUX_CONF_LOCAL"
119+
tmux source "$TMUX_CONF"
120+
fi
121+
122+
if [ -n "$TMUX" ]; then
123+
printf '\n' >&2
124+
printf '⚠️ Installed Oh my tmux! while tmux was running...\n' >&2
125+
printf '→ Existing sessions have outdated environment variables\n' >&2
126+
printf ' • TMUX_CONF\n' >&2
127+
printf ' • TMUX_CONF_LOCAL\n' >&2
128+
printf ' • TMUX_PROGRAM\n' >&2
129+
printf ' • TMUX_SOCKET\n' >&2
130+
printf '→ Some other things may not work 🤷\n' >&2
131+
fi
132+
133+
printf '\n' >&2
134+
printf '🎉 Oh my tmux! successfully installed 🎉\n' >&2
135+
}
136+
137+
if [ -p /dev/stdin ]; then
138+
printf '✋ STOP\n' >&2
139+
printf ' 🤨 It looks like you are piping commands from the internet to your shell!\n' >&2
140+
printf " 🙏 Please take the time to review what's going to be executed...\n" >&2
141+
142+
(
143+
printf '\n'
144+
145+
self() {
146+
printf '# Oh my tmux!\n'
147+
printf '# 💛🩷💙🖤❤️🤍\n'
148+
printf '# https://github.com/gpakosz/.tmux\n'
149+
printf '\n'
150+
151+
declare -f install
152+
}
153+
154+
while :; do
155+
printf ' Do you want to review the content? [Yes/No/Cancel] > ' >&2
156+
read -r answer >&2
157+
case $(printf '%s\n' "$answer" | tr '[:upper:]' '[:lower:]') in
158+
y|yes)
159+
case "$(command -v bat)${VISUAL:-${EDITOR}}" in
160+
*bat*)
161+
self | LESS='' bat --paging always --file-name install.sh
162+
;;
163+
*vim*)
164+
self | vim -c ':set syntax=tmux' -R -
165+
;;
166+
*)
167+
tput smcup
168+
clear
169+
self | LESS='-R' ${PAGER:-less}
170+
tput rmcup
171+
;;
172+
esac
173+
break
174+
;;
175+
n|no)
176+
break
177+
;;
178+
c|cancel)
179+
printf '\n'
180+
printf '⛔️ Installation aborted...\n' >&2 && exit 1
181+
;;
182+
esac
183+
done
184+
) < /dev/tty || exit 1
185+
printf '\n'
186+
fi
187+
188+
install
189+
}

0 commit comments

Comments
 (0)