gpakosz / .tmux

🇫🇷 Oh my tmux! My self-contained, pretty & versatile tmux configuration made with ❤️
MIT License
21.73k stars 3.34k forks source link

Not displaying `hostname_ssh` in status bar (macOS Sonoma) #684

Closed ww7 closed 8 months ago

ww7 commented 8 months ago

Hi, on macOS (latest 'Sonoma') resolving of SSH hostname is not working. Printing empty value for hostname_full_ssh, hostname_ssh and hostname

At the same time, function ssh_or_mosh_args seems works: ssh -G $ssh_or_mosh_args 2>/dev/null | awk '/^hostname / { print $2; exit }' – printing correct remote hostname


I tried to debug as gpakosz#627

pane_info='25239:ww7:zsh (cwterm)' – seems no SSH process associated with that TTY

Before SSH connect, based on tmux display -p '#{pane_pid} #{b:pane_tty} false false #h #D' log:

cut -c3- ~/.tmux.conf | sh -sx _hostname 25239 ttys005 false false mbp21 %0
+ :
+ set -e
+ unset GREP_OPTIONS
+ export LC_NUMERIC=C
+ LC_NUMERIC=C
+ set +H
+ set +H
+ printf ''
+ sed -E s///
++ uname -s
+ _uname_s=Darwin
+ '[' -z /private/tmp/tmux-502/default,24922,0 ']'
+ '[' -z /private/tmp/tmux-502/default ']'
+ '[' -z /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux ']'
+ '[' /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux = tmux ']'
++ tmux -V
++ /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux -S /private/tmp/tmux-502/default -V
++ awk '{gsub(/[^0-9.]/, "", $2); print ($2+0) * 100}'
+ _tmux_version=330
+ command -v pkill
+ _hostname 25239 ttys005 false false mbp21 %0
+ pane_pid=25239
+ pane_tty=ttys005
+ ssh_only=false
+ full=false
+ h_or_H=mbp21
++ _pane_info 25239 ttys005
++ pane_pid=25239
++ pane_tty=ttys005
++ case "$_uname_s" in
++ ps -t ttys005 -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command=
++ awk -v pane_pid=25239 '
        ((/ssh/ && !/-W/) || !/ssh/) && !/tee/ {
          user[$2] = $1; if (!child[$3]) child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4)
        }
        END {
          pid = pane_pid
          while (child[pid])
            pid = child[pid]

          print pid":"user[pid]":"command[pid]
        }
      '
+ pane_info='25239:ww7:zsh (cwterm)'
+ command='ww7:zsh (cwterm)'
+ command='zsh (cwterm)'
++ _ssh_or_mosh_args 'zsh (cwterm)'
++ case "$1" in
++ printf %s ''
+ ssh_or_mosh_args=
+ '[' -n '' ']'
+ _is_true false
+ '[' false = true ']'
+ '[' false = yes ']'
+ '[' false = 1 ']'
+ hostname=mbp21
+ printf '%s\n' mbp21
mbp21 (this is local machine hostname)

and after SSH connection based on tmux display -p '#{pane_pid} #{b:pane_tty} false false #h #D'

cut -c3- ~/.tmux.conf | sh -sx _hostname 3657818 5 false false a %1
+ :
+ set -e
+ unset GREP_OPTIONS
+ export LC_NUMERIC=C
+ LC_NUMERIC=C
+ set +H
+ set +H
+ printf ''
+ sed -E s///
++ uname -s
+ _uname_s=Darwin
+ '[' -z /private/tmp/tmux-502/default,24922,0 ']'
+ '[' -z /private/tmp/tmux-502/default ']'
+ '[' -z /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux ']'
+ '[' /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux = tmux ']'
++ tmux -V
++ /opt/homebrew/Cellar/tmux/3.3a_3/bin/tmux -S /private/tmp/tmux-502/default -V
++ awk '{gsub(/[^0-9.]/, "", $2); print ($2+0) * 100}'
+ _tmux_version=330
+ command -v pkill
+ _hostname 3657818 5 false false a %1
+ pane_pid=3657818
+ pane_tty=5
+ ssh_only=false
+ full=false
+ h_or_H=a
++ _pane_info 3657818 5
++ pane_pid=3657818
++ pane_tty=5
++ case "$_uname_s" in
++ ps -t 5 -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command=
++ awk -v pane_pid=3657818 '
        ((/ssh/ && !/-W/) || !/ssh/) && !/tee/ {
          user[$2] = $1; if (!child[$3]) child[$3] = $2; pid=$2; $1 = $2 = $3 = ""; command[pid] = substr($0,4)
        }
        END {
          pid = pane_pid
          while (child[pid])
            pid = child[pid]

          print pid":"user[pid]":"command[pid]
        }
      '
ps: /dev/tty5 and /dev/5: No such file or directory
+ pane_info=3657818::
+ command=:
+ command=
++ _ssh_or_mosh_args ''
++ case "$1" in
++ printf %s ''
+ ssh_or_mosh_args=
+ '[' -n '' ']'
+ _is_true false
+ '[' false = true ']'
+ '[' false = yes ']'
+ '[' false = 1 ']'
+ hostname=a
+ printf '%s\n' a
a (full is a.ww7.work)
gpakosz commented 8 months ago

Hello @ww7 👋

Works for me on Sonoma.

There's an error in the command you tried:

ps: /dev/tty5 and /dev/5: No such file or directory
ww7 commented 8 months ago

Hello @gpakosz !

Thank you for the kind answer! As it works on your side with Sonoma then I should fix it on my side.

There's an error in the command you tried:

ps: /dev/tty5 and /dev/5: No such file or directory

^ sorry, this error is my mistake, it some wrong run.

Test shows SSH process associated with TTY. Before and after SSH session it shows only:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ww7                             57084 56766 zsh (cwterm)

I'm using sorin-ionescu/prezto Zsh configuration framework and seems some additional customization made this issue possible.

Empty Zsh and fresh setup of Prezto works fine with Oh my tmux!

Great thanks and sorry for disturbing! :)