diff --git a/scripts/handle_tmux_automatic_start.sh b/scripts/handle_tmux_automatic_start.sh index 433798b..3d97e73 100755 --- a/scripts/handle_tmux_automatic_start.sh +++ b/scripts/handle_tmux_automatic_start.sh @@ -18,17 +18,25 @@ is_systemd() { [ $(ps -o comm= -p1) == 'systemd' ] } +# Only manage the systemd unit either if it is not already installed, or if it +# was installed by us (as signified by the magic comment) +should_manage_systemd_unit() { + [ ! -f ${systemd_unit_file_path} ] \ + && \ + systemctl cat --user ${systemd_service_name} | grep -q 'managed-by:tmux-continuum' +} + main() { if is_tmux_automatic_start_enabled; then if is_osx; then "$CURRENT_DIR/handle_tmux_automatic_start/osx_enable.sh" - elif is_systemd; then + elif is_systemd && should_manage_systemd_unit; then "$CURRENT_DIR/handle_tmux_automatic_start/systemd_enable.sh" fi else if is_osx; then "$CURRENT_DIR/handle_tmux_automatic_start/osx_disable.sh" - elif is_systemd; then + elif is_systemd && should_manage_systemd_unit; then "$CURRENT_DIR/handle_tmux_automatic_start/systemd_disable.sh" fi fi diff --git a/scripts/handle_tmux_automatic_start/systemd_enable.sh b/scripts/handle_tmux_automatic_start/systemd_enable.sh index ec9d349..5154fcb 100755 --- a/scripts/handle_tmux_automatic_start/systemd_enable.sh +++ b/scripts/handle_tmux_automatic_start/systemd_enable.sh @@ -17,6 +17,9 @@ template() { local tmux_path="$(command -v tmux)" read -r -d '' content <<-EOF + #managed-by:tmux-continuum + # This file is managed by the tmux-continuum plugin. Manual changes + # will be overridden. [Unit] Description=tmux default session (detached) Documentation=man:tmux(1)