Skip to content

Commit 05a4a82

Browse files
petechesBruno Sutic
authored andcommitted
initial stab at systemd support for tmux-continuum
1 parent 15649e9 commit 05a4a82

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

continuum.tmux

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
set -x
4+
35
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
46

57
source "$CURRENT_DIR/scripts/helpers.sh"

scripts/handle_tmux_automatic_start.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
set -x
4+
35
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
46

57
source "$CURRENT_DIR/helpers.sh"
@@ -14,14 +16,22 @@ is_osx() {
1416
[ $(uname) == "Darwin" ]
1517
}
1618

19+
is_systemd() {
20+
[ $(ps -o comm= -p1) == 'systemd' ]
21+
}
22+
1723
main() {
1824
if is_tmux_automatic_start_enabled; then
1925
if is_osx; then
2026
"$CURRENT_DIR/handle_tmux_automatic_start/osx_enable.sh"
27+
elif is_systemd; then
28+
"$CURRENT_DIR/handle_tmux_automatic_start/systemd_enable.sh"
2129
fi
2230
else
2331
if is_osx; then
2432
"$CURRENT_DIR/handle_tmux_automatic_start/osx_disable.sh"
33+
elif is_systemd; then
34+
"$CURRENT_DIR/handle_tmux_automatic_start/systemd_disable.sh"
2535
fi
2636
fi
2737
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
source "$CURRENT_DIR/../variables.sh"
6+
7+
main() {
8+
systemctl --user disable ${systemd_service_name}
9+
}
10+
main
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
5+
CURRENT_DIR="$( dirname ${BASH_SOURCE[0]} )"
6+
7+
source "$CURRENT_DIR/../helpers.sh"
8+
source "$CURRENT_DIR/../variables.sh"
9+
10+
template() {
11+
local tmux_start_script="$1"
12+
shift
13+
local options="$@"
14+
local content=""
15+
16+
read -r -d '' content <<-EOF
17+
[Unit]
18+
Description=tmux default session (detached)
19+
Documentation=man:tmux(1)
20+
21+
[Service]
22+
Type=oneshot
23+
RemainAfterExit=True
24+
Environment=DISPLAY=:0
25+
ExecStart=/usr/bin/tmux ${systemd_tmux_server_start_cmd}
26+
ExecStartPost=/usr/bin/tmux run /home/peteches/.tmux/plugins/tmux-resurrect/scripts/restore.sh
27+
28+
ExecStop=/home/peteches/.tmux/plugins/tmux-resurrect/scripts/save.sh
29+
ExecStop=/usr/bin/tmux kill-server
30+
KillMode=none
31+
32+
[Install]
33+
WantedBy=default.target
34+
EOF
35+
36+
echo "$content"
37+
}
38+
39+
systemd_tmux_is_enabled() {
40+
systemctl --user is_enabled $(basename "${systemd_unit_file_path}") >/dev/null 2>&1
41+
}
42+
43+
enable_tmux_unit_on_boot() {
44+
if ! systemd_tmux_is_enabled; then
45+
systemctl --user enable ${systemd_service_name}
46+
fi
47+
}
48+
49+
main() {
50+
local options="$(get_tmux_option "$auto_start_config_option" "${auto_start_config_default}")"
51+
local systemd_tmux_server_start_cmd="$(get_tmux_option "${systemd_tmux_server_start_cmd}" "${systemd_tmux_default_server_start_cmd}" )"
52+
local tmux_start_script_path="${CURRENT_DIR}/linux_start_tmux.sh"
53+
local systemd_unit_file=$(template "${tmux_start_script_path}" "${options}")
54+
echo "$systemd_unit_file" > "${systemd_unit_file_path}"
55+
enable_tmux_unit_on_boot
56+
}
57+
main

scripts/variables.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ status_script="#($CURRENT_DIR/scripts/continuum_status.sh)"
3232
status_on_style_wrap_option="@continuum-status-on-wrap-style" # example value: "#[fg=green]#{value}#[fg=white]"
3333
status_off_style_wrap_option="@continuum-status-off-wrap-style" # example value: "#[fg=yellow,bold]#{value}#[fg=white,nobold]"
3434
status_wrap_string="\#{value}"
35+
36+
systemd_service_name="tmux.service"
37+
systemd_unit_file_path="$HOME/.config/systemd/user/${systemd_service_name}"

0 commit comments

Comments
 (0)