From c6d6ca0e049340f725a00cd91e271e2fec1453a6 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Wed, 4 Jun 2025 21:31:46 -0700 Subject: [PATCH 1/2] Define assh function to connect with `autossh` and `.bashrc` when the remote does not have a RemoteCommand specified --- .bashrc | 3 +-- .zshrc | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.bashrc b/.bashrc index 0c685d9..06376d4 100644 --- a/.bashrc +++ b/.bashrc @@ -146,8 +146,7 @@ if ! shopt -oq posix; then fi # Customizations - -if [ -f ~/.profile ]; then +if [ -f ~/.profile ] && [ -z "${SSH_CONNECTION}" ]; then . ~/.profile fi diff --git a/.zshrc b/.zshrc index 31ae1b4..9251aa9 100644 --- a/.zshrc +++ b/.zshrc @@ -70,6 +70,21 @@ if [ -z "${SUDO_USER}" ] && [ -z "${SSH_CONNECTION}" ] && [ -z "${TERM_PROGRAM}" tmux new -A -s local_tmux fi +# Define a function to use autossh with a custom bashrc +function assh() { + remote_file=$(mktemp) + if $(ssh "$@" "cat > ${remote_file}" < ~/.bashrc > /dev/null 2>&1); then + # Successfully copied bashrc to the remote. Source it upon ssh + autossh -t "$@" "bash --rcfile ${remote_file}; rm ${remote_file}" + else + # SSH Config specifies a RemoteCommand; connect normally + autossh "$@" + fi +} +# Use ssh completion for autossh +compdef autossh=ssh +compdef assh=ssh + # Custom dircolors [ -f ~/.dircolors ] && eval "$(dircolors ~/.dircolors)" From 83b9e1c7197f9eadbe1c411fa5e679580fa22064 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Wed, 4 Jun 2025 21:32:41 -0700 Subject: [PATCH 2/2] Update tmux-resurrect to include pane contents and autossh connections --- .config/tmux/tmux.conf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.config/tmux/tmux.conf b/.config/tmux/tmux.conf index fba2487..31b3653 100644 --- a/.config/tmux/tmux.conf +++ b/.config/tmux/tmux.conf @@ -55,7 +55,9 @@ set -g @plugin 'tmux-plugins/tmux-resurrect' set -g @plugin 'tmux-plugins/tmux-continuum' set -g @continuum-restore 'on' set -g @continuum-boot 'on' -set -g @resurrect-processes 'ssh nano k9s nvim' +set -g @continuum-save-interval '10' # Save every n minutes +set -g @resurrect-capture-pane-contents 'on' +set -g @resurrect-processes '"~autossh->autossh *" ssh nano k9s nvim' # Open Links set -g @plugin 'tmux-plugins/tmux-open'