There are many common question such as 'How to create a new window in the current directory'. Here are some simple how-to, inspired by tmux FAQ.
1. Preparing - set environment variable by PS1 in shell
PS1='$([ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD)${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
How it works?
$([ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD)
The previous half part makes the magic, #I indicates the index of each displays. In display 1, it saves current directory ($PWD) into environment variable $TMUXPWD_1, corresponding to $TMUXPWD_2, $TMUXPWD_3 ...etc.Just type 'printenv |grep TMUXPWD' and you will know everything.
${debian_chroot:+($debian_chroot)}\u@\h:\w\$
Well, this is my own prompt (such as walkingice@my_laptop$ ), you can keep your own settings by 'cat ~/.bashrc |grep PS1'2. Create new window in current directory
bind-key c run-shell 'tmux neww "cd $(tmux display -p "\$TMUXPWD_#I"); exec bash"'3. Split window in current directory
bind-key h run-shell 'tmux splitw -v "cd $(tmux display -p "\$TMUXPWD_#I"); exec bash"'Caution: I prefer Ctrl-a h to split horizontal window(splitw -v). In other words, when I click Ctrl-a h, I am saying "Hey, give me a horizontal line". I think it make more sense than tmux original key binding.
bind-key v run-shell 'tmux splitw -h "cd $(tmux display -p "\$TMUXPWD_#I"); exec bash"'
bind h splitw -h "cd $PWD; exec $SHELL"
ReplyDeletebind v splitw -v "cd $PWD; exec $SHELL"
are far simpler imho — plus they work with the CWD of the individual pane, thus are not limited to the pane that lastly set $TMUXPWD_#I. (If there was no prior shell to set $PWD in that pane, e. g. as an app was started directly, cd will default to ~.)
Thanks for the hints, anyway.
Silly me, I completely ignored that tmux doesn't look at the individual $PWD. My bad.
ReplyDeleteRecent tmux (any version after 2011), there are format option like pane_pid, and later (2012.4) there is pane_current_path. So for most use cases, these two will be sufficient.
ReplyDeleteUse: tmux display -p "#{pane_current_path}"
in a script.
Control the break of any recording inside Movement 5 and look as 3D sections and shards fly by the camera. inMotion3D Smash's movement is programmed and adjustable, so clients essentially need to drag, drop a generator into the course of events, apply their media to the Drop Zone, and look as it breakes. Motion Effects
ReplyDeleteI appreciate the practical approach used to explain the topic.online business analyst course
ReplyDeleteThis is something many people should know about. Thanks for explaining it so clearly. qlik sense course
ReplyDelete