mirror of
https://github.com/tmux-plugins/tmux-continuum.git
synced 2024-11-16 15:38:46 +00:00
global modifications to properly restore saved sessions
This commit is contained in:
parent
3007c867cf
commit
400724bad0
38
scripts/continuum_start.sh
Executable file
38
scripts/continuum_start.sh
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
CURRENT_DIR="$( dirname "$0" )"
|
||||||
|
|
||||||
|
echo -e "\n$(date +%T) IN" >> /tmp/continuum
|
||||||
|
|
||||||
|
source "$CURRENT_DIR/helpers.sh"
|
||||||
|
source "$CURRENT_DIR/variables.sh"
|
||||||
|
|
||||||
|
start_tmux() {
|
||||||
|
local systemd_tmux_server_start_cmd="$(get_tmux_option "${systemd_tmux_server_start_cmd_option}" "${systemd_tmux_server_start_cmd_default}" )"
|
||||||
|
/usr/bin/tmux ${systemd_tmux_server_start_cmd}
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_session() {
|
||||||
|
local sessions_count="$(tmux list-sessions 2>/dev/null | wc -l)"
|
||||||
|
|
||||||
|
if /usr/bin/tmux has-session -t "${tmux_server_session_temporary}"; then
|
||||||
|
# add a new session to preserve server daemon
|
||||||
|
[ "${sessions_count}" = 1 ] && tmux new-session -d && \
|
||||||
|
echo "$(date +%T) add session" >> /tmp/continuum
|
||||||
|
|
||||||
|
# kill session
|
||||||
|
echo "$(date +%T) kill session" >> /tmp/continuum
|
||||||
|
/usr/bin/tmux kill-session -t "${tmux_server_session_temporary}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
start_tmux
|
||||||
|
|
||||||
|
# wait detached process of session restoration : start_auto_restore_in_background()
|
||||||
|
# with a sleep 1 inside fetch_and_run_tmux_resurrect_restore_script()
|
||||||
|
#sleep 1
|
||||||
|
|
||||||
|
clean_session
|
||||||
|
}
|
||||||
|
main
|
@ -1,9 +1,10 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
CURRENT_DIR="$( dirname ${BASH_SOURCE[0]} )"
|
CURRENT_DIR="$( dirname ${BASH_SOURCE[0]} )"
|
||||||
|
PARENT_DIR="${CURRENT_DIR%/*}"
|
||||||
|
|
||||||
source "$CURRENT_DIR/../helpers.sh"
|
source "${PARENT_DIR}/helpers.sh"
|
||||||
source "$CURRENT_DIR/../variables.sh"
|
source "${PARENT_DIR}/variables.sh"
|
||||||
|
|
||||||
template() {
|
template() {
|
||||||
local tmux_start_script="$1"
|
local tmux_start_script="$1"
|
||||||
@ -19,7 +20,7 @@ template() {
|
|||||||
[Service]
|
[Service]
|
||||||
Type=forking
|
Type=forking
|
||||||
Environment=DISPLAY=:0
|
Environment=DISPLAY=:0
|
||||||
ExecStart=${systemd_tmux_server_start_cmd}
|
ExecStart=${PARENT_DIR}/continuum_start.sh
|
||||||
|
|
||||||
ExecStop=${HOME}/.tmux/plugins/tmux-resurrect/scripts/save.sh
|
ExecStop=${HOME}/.tmux/plugins/tmux-resurrect/scripts/save.sh
|
||||||
ExecStop=/usr/bin/tmux kill-server
|
ExecStop=/usr/bin/tmux kill-server
|
||||||
@ -46,14 +47,9 @@ enable_tmux_unit_on_boot() {
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
local options="$(get_tmux_option "$auto_start_config_option" "${auto_start_config_default}")"
|
local options="$(get_tmux_option "$auto_start_config_option" "${auto_start_config_default}")"
|
||||||
# start tmux with a temporary session
|
|
||||||
local systemd_tmux_server_start_cmd_default="/usr/bin/tmux $(get_tmux_option "${systemd_tmux_server_start_cmd_option}" "${systemd_tmux_server_start_cmd_default}" ) -s ${tmux_server_session_temporary}"
|
|
||||||
# adds sleep to give tmux some time to finish dettached subprocess "fetch_and_run_tmux_resurrect_restore_script"
|
|
||||||
# and kills tmux temporary session
|
|
||||||
local systemd_tmux_server_start_cmd="${systemd_tmux_server_start_cmd_default} && sleep 2 && /usr/bin/tmux kill-session -t ${tmux_server_session_temporary}"
|
|
||||||
local tmux_start_script_path="${CURRENT_DIR}/linux_start_tmux.sh"
|
local tmux_start_script_path="${CURRENT_DIR}/linux_start_tmux.sh"
|
||||||
local systemd_unit_file=$(template "${tmux_start_script_path}" "${options}")
|
local systemd_unit_file=$(template "${tmux_start_script_path}" "${options}")
|
||||||
mkdir -p "$(dirname ${systemd_unit_file_path})"
|
[ ! -d "$(dirname ${systemd_unit_file_path})" ] && mkdir -p "$(dirname ${systemd_unit_file_path})"
|
||||||
echo "$systemd_unit_file" > "${systemd_unit_file_path}"
|
echo "$systemd_unit_file" > "${systemd_unit_file_path}"
|
||||||
enable_tmux_unit_on_boot
|
enable_tmux_unit_on_boot
|
||||||
}
|
}
|
||||||
|
@ -38,4 +38,4 @@ systemd_unit_file_path="$HOME/.config/systemd/user/${systemd_service_name}"
|
|||||||
|
|
||||||
tmux_server_session_temporary="tmux-continuum-tmp"
|
tmux_server_session_temporary="tmux-continuum-tmp"
|
||||||
systemd_tmux_server_start_cmd_option="@continuum-systemd-start-cmd"
|
systemd_tmux_server_start_cmd_option="@continuum-systemd-start-cmd"
|
||||||
systemd_tmux_server_start_cmd_default="new-session -d"
|
systemd_tmux_server_start_cmd_default="new-session -d -s ${tmux_server_session_temporary}"
|
||||||
|
Loading…
Reference in New Issue
Block a user