top | item 40559329

(no title)

tupolef | 1 year ago

I don't want to switch to Wayland for now, but I will check foot when I do.

I do the same thing with URxvt as a systemd daemon, Tmux as a transient service with systemd-run from .bashrc, and a script in i3wm to run URxvtd client or hide/get the window.

The way I use to run Tmux from a transient service locally and in ssh with the same .bashrc is nice I think. Tmux will survive the terminal and even if I close my session and come back to it:

  #!/usr/bin/env bash
  # ~/.bashrc: sourced by bash(1) for non-login shells.
  
  # If not running interactively, don't do anything
  case $- in
    *i*) ;;
    *) return ;;
  esac
  
  chmod 700 ~/.bashrc.d
  chmod 600 ~/.bashrc ~/.bashrc.d/*
  
  # check if we are already in a Tmux session and not in ssh then open/attach the default one
  if [[ ! "${TERM}" == "tmux"* ]] && [[ -z "${TMUX}" ]] && [[ -z "${SSH_CONNECTION}" ]] && command -v tmux 1> /dev/null; then
    # attach or start the local default Tmux session
    if systemctl --quiet $([[ $(id -u) != 0 ]]; echo "--user") is-active tmux-local-$(id -un).scope; then
      tmux -L local-$(id -un) attach-session -t local-$(id -un) ; exit
    fi
    systemd-run -q --unit tmux-local-$(id -un) --scope $([[ $(id -u) != 0 ]] && echo "--user") tmux -L local-$(id -un) new-session -s local-$(id -un) ; exit
  elif [[ -z "${TMUX}" ]] && [[ -n "${SSH_CONNECTION}" ]] && command -v tmux 1> /dev/null; then
    # attach or start the ssh default Tmux session
    if systemctl --quiet $([[ $(id -u) != 0 ]]; echo "--user") is-active tmux-ssh-$(id -un).scope; then
      tmux -L ssh-$(id -un) attach-session -t ssh-$(id -un) ; exit
    fi
    systemd-run -q --unit tmux-ssh-$(id -un) --scope $([[ $(id -u) != 0 ]] && echo "--user") tmux -L ssh-$(id -un) new-session -s ssh-$(id -un) && exit || echo 'Tmux Systemd unit failed/exited'
  
  fi
  
  # if Tmux is not installed or if we are inside a Tmux session continue the sourcing
  for file in ~/.bashrc.d/*.bashrc;
  do
    source "${file}"
  done

discuss

order

No comments yet.