Rename a terminal in the Cloud9 IDE - unix

Seeing 'bash - "username"' in the terminal name is pretty useless when I'm running multiple windows, is there a way to rename those windows?

you can add the following function to your bashrc
setTitle() {
# configure tmux to allow xterm set title sequence
tmux set-window-option automatic-rename off
tmux set-option allow-rename off
tmux set-option set-titles-string "#T"
tmux set-option set-titles on
# set terminal title
echo -ne "\033]0;$#\007"
}
and then run setTitle "my terminal name".
Sometimes bash prompt (PS1) contains \033]0;...\007 as well, in that case you need to modify it to not allow overriding the title set by setTitle function

Related

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 bind Ctrl-Tab and Ctrl-Shift-Tab in tmux for mintty

I would like to bind CTRL+TAB and CTRL+SHIFT+TAB (without prefix) to tmux functions, under minTTY/cygwin.
I have tried the following tmux configuration:
set-option -gw xterm-keys on
bind-key -n C-Tab next-window
bind-key -n "^[[1;5I" next-window # tmux doesn't recognize
bind-key -n "\e[1;5I" next-window # tmux doesn't recognize
If I hit CTRL+TAB after launching tmux, I get a bell sound. If I hit it after the tmux prefix, it prints 1;5I.
I am using minTTY 2.2.3 under cygwin/Babun. I have disabled minTTY's handling of this key combo via its options (SwitchShortcuts=no in .minttyrc).
For reference, CTRL+TAB and CTRL+SHIFT+TAB work for cycling screen windows with the following .screenrc:
bindkey "^[[1;5I" next
bindkey "^[[1;6I" prev
I got here because I bumped into the same issue.
tmux now supports custom key bindings via user-keys - since August 2017, so if you can build tmux yourself, or once a new tmux version is released, it's possible like so:
set -s user-keys[0] "\e[1;5I"
set -s user-keys[1] "\e[1;6I"
bind-key -n User0 select-pane -t+
bind-key -n User1 select-pane -t-
Note that you must use double quotes and not single quotes or else it won't interpret \e correctly.
At the time of writing the example in the manual uses single quotes - https://github.com/tmux/tmux/issues/1043 , though it's likely to be fixed soon.

Change tmux default to zsh

When tmux opens, I would like it to use zsh instead of bash by default. How would I accomplish this?
From man tmux:
default-shell path
Specify the default shell. This is used as the login shell for new windows when the default-command option is set to empty, and must
be the full path of the executable. When started tmux tries to set a default value from the first suitable of the SHELL environment
variable, the shell returned by getpwuid(3), or /bin/sh. This option should be configured when tmux is used as a login shell.
So, in your tmux.conf:
# set shell
set -g default-shell /bin/zsh
and if you want you can add default command each time, when we start a new window:
# Retach userspaces
set -g default-command "reattach-to-user-namespace -l zsh"
You probably want zsh to be your default shell for most things, then (but this will not apply to cron). The following will make zsh your default shell, and you should then not need to tell tmux anything.
chsh -s /usr/bin/zsh
Note that some OSs still use /bin/zsh as the path to zsh.
If you prefer to set it individually for a session, but not for other (future) sessions, you can use
tmux new-session /bin/zsh \; set default-shell /bin/zsh

How do you switch to zsh when using Nitrous.io

Any ideas? I've tried using :
chsh -s /bin/zsh
But any password I've tried has failed.
You can't use zsh in the main console as you don't have root access, but you could utilize zsh with tmux (which is already installed on your Nitrous box).
You will just need to add this line into ~/.tmux.conf :
set-option -g default-shell /bin/zsh
Once this has been added, start a new tmux session by running:
tmux new -s session_name
Just put zsh at the end of ~/.bashrc to automatically start zsh in the main console when you log in.
Typing exit once will take you back to bash.

How to send a command to all panes in tmux?

I like to call :clear-history on panes with a huge scrollback. However, I want to script a way to send this command to all the panes in the various windows.
I know how to send a command to all the windows, courtesy of this question, but how do I send a command to all the panes of which window as well?
send-keys and synchronize-panes from the tmux manpage come to mind, but I'm not sure how to marry them together. But maybe there is a simpler way to do this.
Extra Observations:
Thinking about this a little bit, tmux list-panes -a seems to list all the panes in the current session. Pretty useful to start off with. Where do I go from here?
Have you tried following in tmux window with multiple panes
Ctrl-B :
setw synchronize-panes on
clear history
A bit late to the party but I didn't want to set and unset synchronize-panes just to send one command so I created a wrapper function around tmux and added a custom function called send-keys-all-panes.
_tmux_send_keys_all_panes_ () {
for _pane in $(tmux list-panes -F '#P'); do
tmux send-keys -t ${_pane} "$#"
done
}
I also create a wrapper around the tmux command to simplify calling this function (for convenience). The wrapper and the above code are all here.
This allows me to run tmux send-keys-all-panes <command> or tmux skap <command to send <command> to all panes.
Note that tmux is aliased to my wrapper function tmux_pp.
Update June 2019
Quick illustration on how to configure your own binding for synchronize panes.
Added the following into my tmux.conf (the comments certainly apply to my overall configuration):
# synchronize all panes in a window
# don't use control S, too easily confused
# with navigation key sequences in tmux (show sessions)
unbind C-S
bind C-Y set-window-option synchronize-panes
Now, I can toggle the ability to synchronize commands across multiple panes with <C-a><C-y>.
(Yes, I remapped the bind key to Ctrl a).
my tmux version is 1.9a, and this works for me, one key is enough for both on and off
bind-key X set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}"
None of the above answers worked for me (tmux v2.3), but this did, from the bash command line:
for _pane in $(tmux list-panes -a -F '#{pane_id}'); do \
tmux clear-history -t ${_pane} ; done
A more generalized script, for tmux commands other than 'clear-history' would just replace that element with a parameter, eg. $1. Do be careful if you intend to write a script to handle a series of tmux commands, as "-t ${_pane}" will need to be applied to each.
Note that the -a parameter to tmux list-panes is required to cover all panes in all windows in all sessions. Without that, only panes in your current tmux window will be affected. If you have more than one tmux session open and only want to apply the command to panes within the current session, replace -a with -s (It's all in the tmux man page).
I haven't the mod points to comment directly on each of the above answers, so here's why they weren't working for me:
The problem that I had with #shailesh-garg 's answer was that the sync affected only commands issued within the panes, not tmux commands issued using Ctrl-B : which are outside the panes.
The three problems that I had with #kshenoy 's answer were that:
it sends keystrokes to within a pane, not to the tmux operation
of that pane, so for instance, if one had a bash shell running in
the pane and one used the script to send "clear-history", those
would be the keystrokes that would appear in the bash command-line.
A work-around would be to send "tmux clear-history" or to pre-pend
"tmux " to "$#", but I haven't edited the answer because of my other
problems with the answer;
I couldn't figure out how to send a
new-line character without literally breaking the line;
Even when I did that, sending "tmux clear-history" had no effect.
If you want to send your command to every pane in every window in every session, add this to your .bashrc:
send_command_to_every_pane() {
for session in `tmux list-sessions -F '#S'`; do
for window in `tmux list-windows -t $session -F '#P' | sort`; do
for pane in `tmux list-panes -t $session:$window -F '#P' | sort`; do
tmux send-keys -t "$session:$window.$pane" "$*" C-m
done
done
done
}
You can then use it like this:
send_command_to_every_pane source ~/.bash_profile
Change "$*" to "$#" if you want that behavior, but in my experience this is what you want.
tmux send-keys -t <session id> <command> C-m
Replace the "session id" and "command" accordingly.
This is my utility function to do it, only executing the command when there there is nothing running in the pane.
#!/bin/bash
_send_bash_command_to_session() {
if [[ $# -eq 0 || "$1" = "--help" ]] ; then
echo 'Usage: _send_bash_command_to_session $session_name what ever command you want: '
return
fi
input_session="$1"
input_command="${#:2}"
for _pane in $(tmux list-panes -s -t ${input_session} -F '#{window_index}.#{pane_index}'); do
# only apply the command in bash or zsh panes.
_current_command=$(tmux display-message -p -t ${input_session}:${_pane} '#{pane_current_command}')
if [ ${_current_command} = zsh ] || [ ${_current_command} = bash ] ; then
tmux send-keys -t ${_pane} "${input_command}" Enter
fi
done
}
tmux_set_venv() {
_current_session=$(tmux display-message -p '#{session_name}')
_send_bash_command_to_session ${_current_session} workon $1
}
Example targeting a session called dev, enabling a python virtualenv in all panes that are in bash or zsh, avoiding executing the command in panes with vim or any other executable:
_send_bash_command_to_session dev workon myvirtualenv
or easier to remember: to do it in the current session:
tmux_set_venv myvirtualenv
Find my configuration file with this function.
You can combine synchronize-panes and send-keys in a single shortcut to send commands to all the panes:
Predefined tmux command clear-history:
bind-key C set-option -w synchronize-panes on\; clear-history \; set-option -w synchronize-panes off
Prompt an arbitrary tmux command:
bind-key p command-prompt -p "Panes command: " "set-option -w synchronize-panes on; %% ; set-option -w -u synchronize-panes"
Prompt an arbitrary shell command:
bind-key p command-prompt -p "Panes command: " "set-option -w synchronize-panes on; send-keys %%\\n ; set-option -w -u synchronize-panes"
By default, byobu uses tmux as backend. It's a wrapper that make things much easier:
Shift+F9:
Ctrl+F9:
Shift+F1
Admittedly only semi-related, I found I could make the status background red when I toggle synchronize-panes so it's obvious when I switch back to a window with an unknown synchronize-panes state:
bind-key C-x setw synchronize-panes on \; set-window-option status-bg red \; display-message "pane sync on"
bind-key M-x setw synchronize-panes off \; set-window-option status-bg default \; display-message "pane sync off"

Resources