2015-11-23 18:28:38 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
CURRENT_DIR="$( dirname ${BASH_SOURCE[0]} )"
|
2020-11-23 23:12:13 +00:00
|
|
|
PARENT_DIR="${CURRENT_DIR%/*}"
|
2015-11-23 18:28:38 +00:00
|
|
|
|
2020-11-23 23:12:13 +00:00
|
|
|
source "${PARENT_DIR}/helpers.sh"
|
|
|
|
source "${PARENT_DIR}/variables.sh"
|
2015-11-23 18:28:38 +00:00
|
|
|
|
|
|
|
template() {
|
|
|
|
local tmux_start_script="$1"
|
|
|
|
shift
|
|
|
|
local options="$@"
|
|
|
|
local content=""
|
|
|
|
|
|
|
|
read -r -d '' content <<-EOF
|
|
|
|
[Unit]
|
|
|
|
Description=tmux default session (detached)
|
|
|
|
Documentation=man:tmux(1)
|
|
|
|
|
|
|
|
[Service]
|
2015-11-30 08:09:48 +00:00
|
|
|
Type=forking
|
2015-11-23 18:28:38 +00:00
|
|
|
Environment=DISPLAY=:0
|
2020-11-23 23:12:13 +00:00
|
|
|
ExecStart=${PARENT_DIR}/continuum_start.sh
|
2015-11-23 18:28:38 +00:00
|
|
|
|
2016-01-23 15:39:06 +00:00
|
|
|
ExecStop=${HOME}/.tmux/plugins/tmux-resurrect/scripts/save.sh
|
2015-11-23 18:28:38 +00:00
|
|
|
ExecStop=/usr/bin/tmux kill-server
|
|
|
|
KillMode=none
|
|
|
|
|
2015-11-30 08:09:48 +00:00
|
|
|
RestartSec=2
|
|
|
|
|
2015-11-23 18:28:38 +00:00
|
|
|
[Install]
|
|
|
|
WantedBy=default.target
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo "$content"
|
|
|
|
}
|
|
|
|
|
|
|
|
systemd_tmux_is_enabled() {
|
|
|
|
systemctl --user is_enabled $(basename "${systemd_unit_file_path}") >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
enable_tmux_unit_on_boot() {
|
|
|
|
if ! systemd_tmux_is_enabled; then
|
|
|
|
systemctl --user enable ${systemd_service_name}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
local options="$(get_tmux_option "$auto_start_config_option" "${auto_start_config_default}")"
|
|
|
|
local tmux_start_script_path="${CURRENT_DIR}/linux_start_tmux.sh"
|
|
|
|
local systemd_unit_file=$(template "${tmux_start_script_path}" "${options}")
|
2020-11-23 23:12:13 +00:00
|
|
|
[ ! -d "$(dirname ${systemd_unit_file_path})" ] && mkdir -p "$(dirname ${systemd_unit_file_path})"
|
2015-11-23 18:28:38 +00:00
|
|
|
echo "$systemd_unit_file" > "${systemd_unit_file_path}"
|
|
|
|
enable_tmux_unit_on_boot
|
|
|
|
}
|
|
|
|
main
|