TMUX - setting up vi mode - tmux

I heard much good about TMUX but so far I am just failing with the setup.
I would like to use the vi mode that allows you to copy with "SPACE" an "ENTER".
Currently I must use CTRL+SPACE and ALT+W.
I am running KALI 5.9.0 and TMUX 3.1c
When I run TMUX and check the setting it shows me the following:
$ tmux show -g status-keys
status-keys emacs
$ tmux show -g mode-keys
mode-keys emacs
My ~/.tmux.conf files looks like this:
set-window-option -g status-keys vi
set-window-option -g mode-keys vi
I also tried the following two:
setw -g status-keys vi
setw -g mode-keys vi
set -g status-keys vi
set -g mode-keys vi
I killed all tmux session and checked again but it seems as something is permanently overwriting my vi mode.
What am I missing?

I have this in my .bashrc, and when I run tmux everything's still in vi mode:
# use vi shortcuts in terminal
set -o vi

Related

"Bad file descriptor" with tmux - pwd does not work

Any idea what might be causing this error below ?
Google was no help.
Everything is just fine if I am not in tmux.
Tmux version is 1.9a.
>pwd
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
-bash: 7: Bad file descriptor
>ls
-bash: 7: Bad file descriptor
>pwd
pwd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
-bash: 7: Bad file descriptor
>cd
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
-bash: 7: Bad file descriptor
>pwd
/home/joco
-bash: 7: Bad file descriptor
>ls
My tmux conf is:
>cat ~/.tmux.conf
set -g prefix C-b
set -sg escape-time 1
set -g base-index 1
set -g pane-base-index 1
bind r source-file ~/.tmux.conf \; display "Reloaded!"
bind \ split-window -h
bind - split-window -v
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
set-option -g repeat-time 400
set -g mouse-select-pane on
set -g mouse-resize-pane on
set -g mouse-select-window on
set -g xterm-keys on
set -g default-terminal "xterm-256color"
bind-key -n C-S-Left swap-window -t -1
bind-key -n C-S-Right swap-window -t +1
set -g mode-mouse on
setw -g mode-keys vi
bind e display "#{pane_current_path}"
set -g display-panes-time 2000
set-option -g display-time 4000
#bind-key -tvi-copy y copy-pipe "~/bin/pbcopy"
#set -g default-terminal "screen-256color"
bind -t vi-copy y copy-pipe 'pbcopy-remote'
bind C-c run "tmux save-buffer - | pbcopy-remote"
#### COLOUR (Solarized 256)
# default statusbar colors
set-option -g status-bg colour235 #base02
set-option -g status-fg colour136 #yellow
set-option -g status-attr default
# default window title colors
set-window-option -g window-status-fg colour244 #base0
set-window-option -g window-status-bg default
#set-window-option -g window-status-attr dim
set-window-option -g xterm-keys on
# active window title colors
set-window-option -g window-status-current-fg colour166 #orange
set-window-option -g window-status-current-bg default
#set-window-option -g window-status-current-attr bright
# pane border
set-option -g pane-border-fg colour235 #base02
set-option -g pane-active-border-fg colour240 #base01
# message text
set-option -g message-bg colour235 #base02
set-option -g message-fg colour166 #orange
# pane number display
set-option -g display-panes-active-colour colour33 #blue
set-option -g display-panes-colour colour166 #orange
# clock
set-window-option -g clock-mode-colour colour64 #green
# bell
set-window-option -g window-status-bell-style fg=colour235,bg=colour160 #base02, red
set-window-option -g xterm-keys on
set -g status-right "#(date)"
# List of plugins
#set -g #plugin 'tmux-plugins/tpm'
#set -g #plugin 'tmux-plugins/tmux-sensible'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
set -g #plugin 'seebi/tmux-colors-solarized'
set -g #colors-solarized 'light'
#set -g #colors-solarized '256'
#set -g #colors-solarized 'dark'
EDIT:
After starting a new tmux (as recommended by Robert), I get:
.bash_profile is called
-bash: 7: Bad file descriptor
>pwd
/home/joco
-bash: 7: Bad file descriptor
>pwd
/home/joco
-bash: 7: Bad file descriptor
>cd
-bash: 7: Bad file descriptor
>
I had the same problem with GNU screen: -bash: 7: Bad file descriptor.
The problem was that I had started screen from a subshell of Midnight Commander. Exiting Midnight Commander before starting screen fixed it.

How to automatically rename tmux windows to the current directory

I would like to have tmux to automatically rename the window with the current working directory (cwd). As it is by default, it names the tab/window as the name of the current process, such as zsh or vim.
When I open a new window in tmux, the name is reattach-to-use-namespace and then it immediately switches to zsh.
I'm on OS X 10.10.2, I use zshell, and I have tmux 1.9a.
To be clear, I don't want the entire path in the name of the window, just the current directory, so for example, I want projectName, not /Users/username/Development/projectName.
If you want to see my current tmux.conf, here it is.
With tmux 2.3+, the b: format modifier shows the "basename" (or "tail") of a path.
set-option -g status-interval 5
set-option -g automatic-rename on
set-option -g automatic-rename-format '#{b:pane_current_path}'
The FORMATS section of man tmux describes other modifiers, such as #{d:} and even #{s/foo/bar/:}.
With tmux 2.2 or older, the basename shell command can be used instead.
set-option -g status-interval 5
set-option -g automatic-rename on
set-option -g automatic-rename-format '#(basename "#{pane_current_path}")'
Expanding on what Josef wrote, you can put the basename of the directory in the status using a shell snippet:
# be sure to see note* below
set -g window-status-format '#I:#(pwd="#{pane_current_path}"; echo ${pwd####*/})#F'
set -g window-status-current-format '#I:#(pwd="#{pane_current_path}"; echo ${pwd####*/})#F'
# status bar updates every 15s by default**, change to 1s here
# (this step is optional - a lower latency might have negative battery/cpu usage impacts)
set -g status-interval 1
*Note that what would be ${pwd##*/} is escaped to ${pwd####*/} since # has special meaning in the format string.
**See here for an example default tmux config.
Show the top N components
Showing just the basename generates too much ambiguity, but full paths are too much clutter, so I settled for:
the/last/path
instead of:
/a/very/long/the/last/path
or just:
path
.tmux.conf
set-window-option -g window-status-current-format '#[fg=white,bold]** #{window_index} #[fg=green]#{pane_current_command} #[fg=blue]#(echo "#{pane_current_path}" | rev | cut -d'/' -f-3 | rev) #[fg=white]**|'
set-window-option -g window-status-format '#[fg=white,bold]#{window_index} #[fg=green]#{pane_current_command} #[fg=blue]#(echo "#{pane_current_path}" | rev | cut -d'/' -f-3 | rev) #[fg=white]|'
Trick taken from: Remove part of path on Unix
If that still does not solve ambiguity, I go for:
bind-key -r w choose-window -F '#{window_index} | #{pane_current_command} | #{host} | #{pane_current_path}'
Tested on Tmux 2.1, Ubuntu 16.04.
To get the best of both worlds - window name is path when you're at a shell prompt, but name of executable when you're running something, try this:
set-option -g status-interval 1
set-option -g automatic-rename on
set-option -g automatic-rename-format "#{?#{==:#{pane_current_command},bash},#{b:pane_current_path},#{pane_current_command}}"
Replace "bash" with whatever shell you're using.
Adding this config to your ~/.tmux.conf file should work:
set-option -g window-status-current-format '#I:#{pane_current_path}#F'
set-option -g window-status-format '#I:#{pane_current_path}#F'
set-option -g status-interval 1
It depends however on your Tmux version. I wasn't able to make it work on 1.9a3 (in Cygwin) - but with Tmux 1.8 on Ubuntu (in Vagrant) it worked fine.
I use the following in ~/.tmux.conf to achieve this (working on OSX, zsh, tmux-2.3):
set -g automatic-rename-format '#{pane_current_path}'
set -g status-interval 5
You can set status-interval to 1 to make it respond faster to changing directories.
According to the changelog (https://raw.githubusercontent.com/tmux/tmux/master/CHANGES) this should work in tmux 1.9 and up.
Using ssh into a CentOS machine with tmux 2.3 the window name doesn't change until I press return in the new panel, not sure why that is happening.
Do something like this in a tmux session for zsh shell:
setopt PROMPT_SUBST
export PS1=$'\ek$(basename $(pwd))\e\\> '
If someone uses bash shell:
export PS1="\033k\$(basename \$(pwd))\033\\> "
You can add these commands in the shell initialization file on the condition the $TERM env variable is set to the value "screen"
I am using zsh hook for that
Add following in ~/.zshrc
precmd () {
if [ -n "$TMUX" ]; then
tmux set-window-option -q window-status-format "#[fg=cyan bg=cyan] | #[fg=white, bg=cyan] #I | ${PWD##/*/} #[fg=cyan, bg=cyan] | "
tmux set-window-option -q window-status-current-format "#[fg=cyan, bg=cyan] | #[fg=white, bg=cyan] #I | ${PWD##/*/} #[fg=cyan, bg=cyan] | "
fi
}
This doesn't strictly answer your question--it doesn't automatically rename an existing tmux session to the current working directory.
Rather, when creating a new session, it names that session after the current working directory.
Here's what I did:
to
~/.aliases
add
alias tm='tmux new -s `basename $PWD`'
Open a new terminal window and type:
tm
This now creates a new tmux session which is named after the current working directory.
Note: This relies on basename which does not exist in Windows.
I am sure that you want use this:
set -g status-left '#{pane_current_path} '
To change what you see in the window list you can specify a format when you define the key-binding for the chose-window function like this:
bind-key '"' choose-window -F "#{session_name} | #{window_name} - #{b:pane_current_path} (#{pane_current_command})"

Some setting of Tmux doesnt work

On Mac Mountain lion, tmux installed via Homebrew.
Some settings like the following doesn't work:
setw -g pane-base-index 1
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on
Then error:
/Users/millisami/.tmux.conf: 52: unknown option: pane-base-index
/Users/millisami/.tmux.conf: 53: unknown option: mouse-resize-pane
/Users/millisami/.tmux.conf: 55: unknown option: mouse-select-window
Whats wrong?
As rado said, tmux 2.1 doesn't support the individual mouse settings. It replaced them with a single setting, mouse which can be set with set -g mouse on in your ~/.tmux.conf.
As for the pane-base-index setting, Mark Nichols suggestion of:
# set window and pane index to 1 (0 by default)
set-option -g base-index 1
setw -g pane-base-index 1
worked for me on OS X 10.10.5 running tmux 2.1 installed via brew in iTerm 2.1.4.
# set window and pane index to 1 (0 by default)
set-option -g base-index 1
setw -g pane-base-index 1
set -g mode-mouse on
setw -g mouse-select-window on
setw -g mouse-select-pane on
It could be that you are using tmux 2.1, which doesn't support those anymore.

tmux set -g mouse-select-window not working

from what I understand
set -g mouse-select-window on
Should allow me to click on a window in the status bar and go to that window. I put that in my tmux.conf file though and nothing happens when I click on a window. What am I doing wrong?
In my .tmux.conf I have the following:
set -g mode-mouse on
set -g mouse-select-window on
set -g mouse-select-pane on
Do you have the mode-mouse on setting?
On 2.1 this config got deprecated and the new option to allow all mouse support is:
set -g mouse on
This break the nice mouse scroll support, but can be enabled with this:
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"

tmux -- disable echo of last run command?

I started using tmux recently and things are good except for the fact that tmux prints out my last run command before output, e.g.:
~ $ pwd
pwd/Users/me
You can see that it put "pwd" before the directory there, which is annoying.
My shell(zsh) doesn't do this when I run commands outside of tmux.
show-environment -g doesn't reveal any weird options being passed to zsh or anything: SHELL=/bin/zsh
I read through the manpage and Googled around but I can't find anything.
Thanks for any help!
Figured it out -- needed to change my ~/.tmux.conf to have a different TERM(xterm instead of screen-256color):
# act like vim
setw -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind-key -r C-h select-window -t :-
bind-key -r C-l select-window -t :+
# act like GNU screen
unbind C-b
set -g prefix C-a
# look good
#set -g default-terminal "screen-256color"
set -g default-terminal "xterm"
set -g status "off"

Resources