How to make tmux.conf to name windows based on their window index only and not display the hostname - tmux

How to make tmux.conf to name windows based on their window index only and not display the hostname after it. It should just display the window index only.
Currently tmux by default is showing the user hostname as well.

Is this what you're looking for?
set -g window-status-current-style "#I"
set -g window-status-style "#I"

Related

tmux doesn't display pane names

I have configured tmux (version 3.1c) to display pane names in .tmux.conf:
set -g pane-border-format "#{pane_index} #{pane_title}"
set -g pane-border-status bottom
However, tmux doesn't display the pane name (neither inside macOS terminal app nor iTerm).
Your configuration looks good, you just need to source the new configuration file with tmux source-file /path/to/.tmux.conf

how to search within shortcuts of tmux

Pressing ? within a tmux session lists out the available shortcuts.
But there are so many... how can one search for some text within those displayed shortcuts?
I figured it out. My tmux's default mode was in emacs. I just had to switch to Vi (which I am comfortable with). So all I had to do was:
set-window-option -g mode-keys vi

Different starting directory per window?

I daily use tmux (2.5) on my laptop to work, and my tmux sessions have a starting directory which is the working directory I started the tmux session from. Every pane/window I open start with this starting directory as working directory.
I can change this starting directory, and this change would apply to the whole session.
But if I want to work on a different project with several panes, I could start a new window, but every pane I would open in it would start with the session's starting directory : I would have to cd to the new location for each pane which isn't practical.
If I need to work on several project/directories simultaneously, I can start a new terminal session, then cd to the relevant directory/project and start a new tmux session. That's not complicated.
But if I want to do the same thing on a server through ssh, I'd need to either :
open a new ssh session.
either embed my remote tmux sessions in an other tmux session.
Neither sounds practical to me, I'd prefer a single tmux session on the remote machine.
I think it would be more convenient to being able to start new window with its own starting directory location that would apply to any new pane opened in it. Is there a way to achieve this?
Edit :
I already tried the -c parameter of tmux new-window command.
But it doesn't assign its starting directory to the window created this way, it only applies this custom starting directory to the first pane created.
Any new pane opened in this window then uses the session's starting directory as default working dir (and not the path passed to tmux new-window).
This question is very similar to: https://unix.stackexchange.com/questions/12032/create-new-window-with-current-directory-in-tmux
It depends on your tmux version but the -c parameter does do the trick but it does not remember the setting. There used to be a default-path setting but that has been removed in version 1.9 unfortunately.
For newer versions you will need to pass along the -c in all cases (you can use an alias if you manually execute that command) or if you use key bindings you need to rebind the split/new window keys.
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
To use a custom path instead of the current pane path, execute this command:
tmux setenv custom_path /home/whatever/some/path
Put this in your config:
bind '"' split-window -c "#{custom_path}"
bind % split-window -h -c "#{custom_path}"
bind c new-window -c "#{custom_path}"
Yes, it turns out the -c option to the new-window command is what you are looking for: https://unix.stackexchange.com/questions/12032/create-new-window-with-current-directory-in-tmux Also, this: https://unix.stackexchange.com/questions/101949/new-tmux-panes-go-to-the-same-directory-as-the-current-pane-new-tmux-windows-go
So either of tmux new-window -c $(pwd) or tmux new-window -c /path/to/dir inside your tmux session should do it.

Tmux window or pane name won't change in GNOME Terminal

Using Fedora 25 and GNOME Terminal. I have used Tmux for a few years in Ubuntu with a long customized .tmux.conf file. Recently installed Tmux and Tmuxinator in Fedora.
When I open the Terminal. I see that the title is set to tom#localhost:~. When I create a new Tmux session such as tmux new -s panes. The title of the pane is still tom#localhost:~.
Inside the Tmux session. When I open a new window with name console like this new-window -n console. The title won't change to console and keeps saying tom#localhost:~.
I thought maybe tmux is not overriding the titles so I added this to the tmux.conf file:
set-option -g set-titles on
set -g terminal-overrides "xterm*:XT:smcup#:rmcup#"
That still doesn't do anything.
The Terminal settings. I have Profile/Command/When terminal commands set their own titles set to Replace initial title.
I cannot figure this out. What am I doing wrong here?
I am not exactly sure why it works. But this solves my problem.
Inside the .tmux.conf file I added the line set-option -g allow-rename off. At the top of the file I had the line set -g default -terminal "xterm". I removed this line.

How to force emacs-style status-keys in tmux?

I have this problem with tmux 1.8: I want to set status-keys option to 'emacs' because I really dislike entering commands in vi-mode. However adding the following line to .tmux.conf has no effect:
set -g status-keys emacs
When tmux is restarted, tmux show-options -g | grep keys says emacs but the actual behaviour is vi-style.
The root of the problem is the $EDITOR environment variable, which it set to vim in my case. The documentations states:
status-keys [vi | emacs]
Use vi or emacs-style key bindings in the status line,
for example at the command prompt. The default is emacs,
unless the VISUAL or EDITOR environment variables are set
and contain the string `vi'.
So apparently when the environment variable is "vim" it forces vi status-keys.
Is there a way to override this behaviour and have the prompt behave emacs-style despite the environment variable? I can obviously hack around this (like starting tmux with other env variables and restoring the original later) but I hope there is a clean solution.
Thanks!
I had this problem and I think I just figured it out. Are you by chance also using ZSH (Z Shell)?
I found this post that says that ZSH will also switch to "vi mode" if your VISUAL and/or EDITOR is set to vi/vim. So the problem I was having in tmux as actually bubbling up from ZSH!
In short, make sure you can use emacs-style keys in your shell outside of tmux. If you're using ZSH you can add bindkey -e to .zshrc to set emacs bindings. Then in .tmux.conf:
set -g mode-keys emacs
set -g status-keys emacs
Both status-key and mode-keys default to vi if EDITOR contains vi, but this is only a default (during startup, before the configuration files are processed). Setting either of these options in your configuration should override the EDITOR-based default.
Are you also setting mode-keys (which controls the key maps used in copy-mode, and the choose-… commands)?
set -gw mode-keys emacs

Resources