Skip to content

Commit

Permalink
Configure keybinding and command to renew environment (SSH_AUTH_SOCK,…
Browse files Browse the repository at this point in the history
… DISPLAY) inside tmux session when attached back to existing session
  • Loading branch information
samoshkin committed Nov 24, 2017
1 parent 6377634 commit 5cc0e65
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
12 changes: 12 additions & 0 deletions tmux/renew_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -eu

pane_fmt="#{pane_id} #{pane_in_mode} #{pane_input_off} #{pane_dead} #{pane_current_command}"
tmux list-panes -s -F "$pane_fmt" | awk '
$2 == 0 && $3 == 0 && $4 == 0 && $5 ~ /(bash|zsh|ksh|fish)/ { print $1 }
' | while read -r pane_id; do
# renew environment variables according to update-environment tmux option
# also clear screen
tmux send-keys -t "$pane_id" 'Enter' 'eval "$(tmux show-env -s)"' 'Enter' 'C-l'
done;
21 changes: 14 additions & 7 deletions tmux/tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,20 @@ set -g @prefix_highlight_show_copy_mode 'on'
set -g @prefix_highlight_copy_mode_attr "fg=$color_dark,bg=$color_secondary"



# ============================
# === Hooks ===
# ============================

# Prompt to rename window right after it's created
set-hook -g after-new-window 'command-prompt -I "#{window_name}" "rename-window '%%'"'
# =====================================
# === Renew environment ===
# =====================================
set -g update-environment \
"DISPLAY\
SSH_ASKPASS\
SSH_AUTH_SOCK\
SSH_AGENT_PID\
SSH_CONNECTION\
SSH_TTY\
WINDOWID\
XAUTHORITY"

bind '$' run "~/.tmux/renew_env.sh"


# ============================
Expand Down

0 comments on commit 5cc0e65

Please sign in to comment.