tmux-python / tmuxp

πŸ–₯️ Session manager for tmux, build on libtmux.
https://tmuxp.git-pull.com/
MIT License
4.09k stars 233 forks source link

Environment variable is not being set when environment value contains "-th" #543

Open thamaraiselvam opened 4 years ago

thamaraiselvam commented 4 years ago

Problem

Environment variable is not being set in a weird case

tmuxp details

output of tmux show-options -g

@battery_bar "#[bg=none]#[fg=colour196]β—Ό#[fg=colour202]β—»#[fg=colour208]β—»#[fg=colour214]β—»#[fg=colour220]β—»#[fg=colour226]β—»#[fg=colour190]β—»#[fg=colour154]β—»#[fg=colour118]β—»#[fg=colour82]β—»#[fg=colour196]"
@battery_bar_length auto
@battery_bar_palette gradient
@battery_bar_symbol_empty β—»
@battery_bar_symbol_full β—Ό
@battery_hbar "#[fg=colour196]▏"
@battery_hbar_palette gradient
@battery_percentage 9%
@battery_status ↓
@battery_status_charging ↑
@battery_status_discharging ↓
@battery_vbar "#[fg=colour196]▁"
@battery_vbar_palette gradient
@root !
activity-action other
assume-paste-time 1
base-index 1
bell-action any
default-command 
default-shell /bin/zsh
default-size 80x24
destroy-unattached off
detach-on-destroy on
display-panes-active-colour #00afff
display-panes-colour #00afff
display-panes-time 800
display-time 1000
history-limit 5000
key-table root
lock-after-time 0
lock-command "lock -np"
message-command-style fg=#ffff00,bg=#000000,bright
message-style fg=#000000,bg=#ffff00,bright
mouse on
prefix C-a
prefix2 None
renumber-windows on
repeat-time 600
set-titles on
set-titles-string "#h ❐ #S ● #I #W"
silence-action other
status on
status-bg #080808
status-fg #8a8a8a
status-format[0] "#[align=left range=left #{status-left-style}]#{T;=/#{status-left-length}:status-left}#[norange default]#[list=on align=#{status-justify}]#[list=left-marker]<#[list=right-marker]>#[list=on]#{W:#[range=window|#{window_index} #{window-status-style}#{?#{&&:#{window_last_flag},#{!=:#{window-status-last-style},default}}, #{window-status-last-style},}#{?#{&&:#{window_bell_flag},#{!=:#{window-status-bell-style},default}}, #{window-status-bell-style},#{?#{&&:#{||:#{window_activity_flag},#{window_silence_flag}},#{!=:#{window-status-activity-style},default}}, #{window-status-activity-style},}}]#{T:window-status-format}#[norange default]#{?window_end_flag,,#{window-status-separator}},#[range=window|#{window_index} list=focus #{?#{!=:#{window-status-current-style},default},#{window-status-current-style},#{window-status-style}}#{?#{&&:#{window_last_flag},#{!=:#{window-status-last-style},default}}, #{window-status-last-style},}#{?#{&&:#{window_bell_flag},#{!=:#{window-status-bell-style},default}}, #{window-status-bell-style},#{?#{&&:#{||:#{window_activity_flag},#{window_silence_flag}},#{!=:#{window-status-activity-style},default}}, #{window-status-activity-style},}}]#{T:window-status-current-format}#[norange list=on default]#{?window_end_flag,,#{window-status-separator}}}#[nolist align=right range=right #{status-right-style}]#{T;=/#{status-right-length}:status-right}#[norange default]"
status-format[1] "#[align=centre]#{P:#{?pane_active,#[reverse],}#{pane_index}[#{pane_width}x#{pane_height}]#[default] }"
status-interval 10
status-justify left
status-keys emacs
status-left "#[fg=#000000,bg=#ffff00,bold] ❐ #S #[fg=#ffff00,bg=default,none] "
status-left-length 1000
status-left-style fg=#8a8a8a,bg=#080808
status-position bottom
status-right "#(cut -c3- ~/.tmux.conf | sh -s _battery)#[fg=#080808,bg=default,none]#[fg=#8a8a8a,bg=#080808,none]#[fg=#e4e4e4]#[bg=none]#[none]#{?session_many_attached,πŸ‘“,}#[fg=#e4e4e4]#[bg=none]#[none]#{?client_prefix,⌨,} #{@battery_status} #{@battery_bar} #{@battery_percentage} #[fg=#8a8a8a,bg=#080808,none]| %R #[fg=#8a8a8a,bg=#080808,none]| %d %b #[fg=#d70000,bg=#080808,none]#[fg=#e4e4e4,bg=#d70000,none] #(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} false #D) #[fg=#e4e4e4,bg=#d70000,none]#[fg=#000000,bg=#e4e4e4,bold] #(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} false #D) "
status-right-length 1000
status-right-style fg=#8a8a8a,bg=#080808
status-style fg=#8a8a8a,bg=#080808
update-environment[0] DISPLAY
update-environment[1] KRB5CCNAME
update-environment[2] SSH_ASKPASS
update-environment[3] SSH_AUTH_SOCK
update-environment[4] SSH_AGENT_PID
update-environment[5] SSH_CONNECTION
update-environment[6] WINDOWID
update-environment[7] XAUTHORITY
visual-activity off
visual-bell off
visual-silence off
word-separators " "

Environment

Darwin 19.2.0 Darwin Kernel Version 19.2.0: Sat Nov 9 03:47:04 PST 2019; root:xnu-6153.61.1~20/RELEASE_X86_64 x86_64

Step 4: Describe the problem:

tmuxp is not setting environment variable which starts with -th

Steps to reproduce:

  1. create a session yaml file as following

    session_name: test
    windows:
    - window_name: default
    panes: []
    environment:
    ONE: th
    TWO: -th
    THREE: -th-
  2. tmuxp load session.yaml

  3. check following environments

 echo $ONE
 echo $TWO
 echo $THREE

only ONE will be there

Observed Results:

Expected Results:

dineshba commented 4 years ago

Myself and @jpninanjohn debugged this issue. Our finding:

1) Problem is for any env having -t in key or value 2) This bug is present in libtmux library itself.

We are calling self.session.set_environment(option, value) at here which should properly set the env for the session. This internally calls session.cmd which has this snippet.

def cmd(self, *args, **kwargs):
        # if -t is not set in any arg yet
        if not any('-t' in text_type(x) for x in args):
            # insert -t immediately after 1st arg, as per tmux format
            new_args = [args[0]]
            new_args += ['-t', self.id]
            new_args += args[1:]
            args = new_args
        return self.server.cmd(*args, **kwargs)

This adds a key and value as -t and session id if it does not find -t in given args. This does not do an exact match. It matches -t even if it is contained in middle of the word also in which case no target session is added. Hence the arguments are set for current session instead of new session.