I'm trying to write a script which will programmatically set a tmux pane's title. I've got it mostly working by using the following:
# tmux.conf
set -g pane-border-format "#{pane_index}:#{pane_title}"
# script
# ...
tmux select-pane -t foo:0.0 -T "this will be shortlived"
However, as soon as I do anything in that pane, the custom title is unset. I've looked through tmux's source, but have not been able to find anything obvious answers. (The value appears to be a fragment of my $PS1.)
So, how is is pane_title set and is there any way for me to prevent it from overriding my custom title? (I'm pretty sure you can use a shell function to populate value's within the pane-border-format string template, but this doesn't really work if the values are set dynamically via a script.)
The intent of pane title is for applications inside tmux to update it, there is no way to prevent this happening other than configuring every application not to do it, or modifying tmux itself. In this case, it is your shell changing it. You can check your shell profiles and the system shell profiles for the OSC title setting sequence (\033]2; or \033]0; or \e[2; or \e[0;), but other programs will still feel free to change it.
If you want a custom pane title that can't be modified by applications, the best bet is to use a user option. If you have tmux 3.0a or later you can set it on the pane in your script:
[ -n "$TMUX" ] && tmux set -p #mytitle "foo"
Then use it in pane-border-format:
set -g pane-border-format "#{#mytitle}"
If you have an older tmux there are no pane options but it is possible by using an option named with the pane ID, something like:
if [ -n "$TMUX" ]; then
I=$(tmux display -p '#{pane_id}')
tmux set -w "#mytitle_$I" "foo"
fi
Then:
set -g pane-border-format '#(tmux show -wv "#mytitle_#{pane_id}")'
Related
I am trying to get tmux to use screen-256color instead of xterm-256color, as it is not recommended. But when I am not using tmux, I would like to keep it as xterm-256color
A little bit of my setup, I am currently using iTerm2 and ssh to my development linux box, which is using zsh.
In my ~/.zshrc, I have:
export TERM="xterm-256color"
In my ~/.tmux.conf, I have:
set -g default-terminal "screen-256color"
With this configuraiton, without tmux, echo $TERM returns xterm-256color (which is right) and with tmux, echo $TERM is still returning xterm-256color instead of screen-256color.
Is there anything else I need to set in order for this to work?
Thanks!
The reason this does not work as expected is, that the zsh session that is started inside tmux overwrites TERM.
You should not set TERM from within in your shell. TERM is the way the terminal informs the shell and other applications about its capabilities (number of colors, key sequences for special keys, etc.). If you change TERM inside the shell, you change the what features the shell and applications expect from the terminal without the terminal itself knowing about it. Oftentimes this may not be an actual issue, but it is better to change the terminal configuration and set the desired value there.
You already did so when setting screen-256color in the configuration of tmux, which is essentially a terminal emulator, too. To do it for iTerm2 (tested with version 3.0.10):
Open the Preferences dialog (in the Menu: iTerm2 → Preferences, or press ⌘+,).
In the dialog go to Profiles → Terminal.
There you can choose the desired value for TERM under Report Terminal Type.
You could modify your .zshrc file to check if you are running in tmux:
[ -z "$TMUX" ] && export TERM=xterm-256color
When I am using vim-figitive it often shells out for commands like git push and so on.
Every time it opens a shell I see some leftovers from the previous session, something like:
Press ENTER or type command to continue
It sets me off every time because I can't figure out if this is the output from the current session or the previous one.
Is there a way to mark it with some sort of line every time I shell out from vim? Something like this in .zshrc would do it I think:
if [ -n $VIM ]; then
echo "----------------------------------------------------------------------------------"
fi
Update
It works when I run :sh, but not when I run commands from vim-fugitive. Is there is a way to intercept system() calls or whatever it is using?
From #tpope:
My recommendation would be to look into disabling the "alternate
screen" for your terminal emulator (or terminal multiplexor). That's
what I do.
Just add the following to tmux.conf
# tmux.conf
# For tmux , the alternate-screen option defaults to on
set-window-option -g alternate-screen off
I'm trying to write a script that makes GNU screen call virtualenvwrapper's workon command to jump to an existing virtualenv based on the screen session name.
I've managed to make it work when the session starts, but I want to be able to run commands everytime a window is created, and I can't find hooks or anything similar to it.
Does screen allow a way to run commands everytime a window is created within a session?
Try putting the logic into your ~/.profile (if using the deflogin on setting) or ~/.mkshrc (or similar, depending on your shell) file. Something like this:
if test -n "$STY"; then
# we are inside GNU screen
screenpid=${STY%%.*}
screenname=${STY#*.}
# do your magic
fi
In this scenario, $screenname will contain either the name passed to the -S option of GNU screen, or something like ttyp0.shorthostname or pts-9.shorthostname (depending on the OS) if -S was not used.
Suddenly, both my screen/tmux started changing my windows' names after every command. They keep changing the name to the value of $PROMPT_COMMAND on every single action on the terminal, even after manually renaming them (by Ctrl+A A on screen or Ctrl+B on tmux).
On tmux I already tried to change the tmux.conf settings to disable window auto renaming off, but seems that it was ignored.
I am using bash without the standard /etc/bashrc configuration file. My distro is Fedora 18.
Add the following to your tmux config file:
set-option -g allow-rename off
Put this at the end of the .tmux.conf file:
set-window-option -g automatic-rename off
set-option -g allow-rename off
then reload the tmux config file (ctrl + b > : > source-file ~/.tmux.conf).
First, if l0b0's answer fixed your problem could you please mark it as a solution? Second, for those of use who stumble upon this question and are using fedora 19 this redhat bug report may be of interest. It seems like the default value of $PROMPT_COMMAND set by /etc/bashrc has been changed recently. I reverted to the previous behavior like this:
echo 'printf "\033]0;%s#%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"' > /etc/sysconfig/bash-prompt-screen
chmod a+rx /etc/sysconfig/bash-prompt-screen
Check whether your PS1 (plus PS2, PS3 or PS4 if those are set) is changing the title:
printf %q "$PS1" | grep -F '\\033'
How do you add a shortcut by commandline?
If we do it by hand (Keyboard > Custom Shortcuts) it works as it is supposed to do.
When we want to do it by commandline (in a bashscript as example)
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name "killscript"
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command "pkill chromium"
gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding "<Primary><Alt>X"
This doesn't work.. When I'll check the shortcut by the dconfeditor I see that it has the proper name, binding and command set up.
Any ideas how I could get this fixed?
You can always change the settings in the GUI and watch the changes in the terminal using:
dconf watch /
You will notice that there are 4 commands the 3 you already have to set name, binding, and command and a 4th that adds the command to an array:
/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/binding
'<Primary>1'
/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/name
'test'
/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/command
'test'
/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings
['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']
So to add your custom0 command to the array use this command and then it works
gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']"
Also, check this detailed answer on how to manipulate the array https://askubuntu.com/a/597414
I'm not sure how you would make a custom keybaord shortcut (like a hotkey or something) but if you're working from the commandline and want to make a long command shorter, you could use an alias in your .bashrc or .bash_profile file
alias ls='ls -la'
if it's more complicated, you make a bash script and make it executable and, if you want to access it from wherever you are, add the folder it's in to your PATH varible