how to create title bars for tmux panes - terminal

I need to name my tmux panes and view them with a title bar is there any way to set a nano title bar like for each tmux pane? is there any alternative?

I don't know of a way to create "nano title bars" in tmux. However, you can have each pane write to the tmux status bar on every command. You'd set your preexec (zsh, as you've tagged this) to something like:
preexec() { print -Pn '\e]0;$1 | %~\a' }
That example uses prompt expansion sequences to show the last command and the working dir.
The FORMATS section of the tmux manpage describes what can be displayed there.

while sleep 1;do tput sc;tput cup 0 $(($(tput cols)/2));echo "Pane 2";tput rc;done &

Related

Prevent tmux's pane_title from being updated

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}")'

keep terminal window title when using screen

Whenever I start screen, it changes the title of the terminal window to 'screen'. Can I prevent that and have the window title remain what it would be if I hadn't run my command under screen?
More specifically, I'd like gnome-terminal to display the name of the buffer I'm editing in vim. I can do this by adding set title to my .vimrc. Now when I run vim, the buffer name (along with some other information), shows up in the title of gnome-terminal. When I start screen and run vim, the title changes to 'screen'.
I've looked at the following page:
http://beautifulpixels.blogspot.co.at/2012/01/automatic-screen-window-titles-in-bash.html
But the suggested solution places the window title in the screen status line. I also tried adding this:
case $TERM in
screen*)
# http://dtfm.tumblr.com/post/7193076007/the-sweetest-screenrc-hack-ever
SCREENTITLE='\[\ek\e\\\]\[\ek\W\e\\\]'
;;
*)
SCREENTITLE=''
;;
esac
TITLEBAR='\[\e]0;\a\]'
export PS1="${SCREENTITLE}${TITLEBAR}[\u#\h \W]\$ "
To my .bashrc, but this only sets the window title to the current directory. Even if I run vim, the window title remains the current working directory. This is not the case if I run it outside of screen.
Any ideas?
Although I didn't exactly solve it, demure's comment enticed me to check out tmux. Using that I was able to put the following line:
autocmd BufReadPost,FileReadPost,BufNewFile * call system("tmux rename-window '" . expand("%:p:~") . " - VIM'")
In my .vimrc file and I get the effect I wanted in the first place (except, of course, now I'm using tmux).
References:
tmux tabs with name of file open in vim
How can I expand the full path of the current file to pass to a command in Vim?

Setting Title for Tabs in Terminator (Console Application) in Ubuntu

Is there way to set terminator (Version: 0.95ppa1) title of tabs to a different string via bash command-line (CLI)?
I plan to use this feature with AutoKey and I can open multiple machines at same time and set title to Name of the machine its connected to.
ORIG=$PS1
TITLE="\e]2;\"This is just crazy enough to work\"\a"
PS1=${ORIG}${TITLE}
Resets title to
"This is just crazy enough to work"
This should apply to all xterm-style terminal emulators.
From the Terminator man pages,
Ctrl+Alt+W
Rename window title.
Ctrl+Alt+A
Rename tab title.
Ctrl+Alt+X
Rename terminal title.
You can also launch a new instance with
$ terminator --title [title]
Add follwing in your .bashrc file by editing it using vim ~/.bashrc and use set_title to rename your tab:
set_title()
{
ORIG=$PS1
TITLE="\e]2;$*\a"
PS1=${ORIG}${TITLE}
}
run source ~/.bashrc command after editing your .bashrc file
Ex.: set_title newtab will rename your current tab to newtab
working Properly in Gnome3.14 terminal and terminator 0.97
On Terminator 1.91-6 double click terminal title enables edition
PS1 does not need to be set. Credit for this function goes to geirha on freenode #bash
set_title() { printf '\e]2;%s\a' "$*"; }
This seems to work for me. I'm using BASH on Crunchbang (Debian derived)
$ echo -en '\e]0;echo works too\a'
With Terminator 0.96 and GNU bash 4.2.25 the printf suggestion above worked for me, but I had to tweak it slightly to make it into a function that would just work for me in a new Terminator tab. I added this to the end of my ~/.bashrc file:
set_title() { printf "\e]2;$*\a"; }
The key was placing the \a at the end of the quoted string. Then when opening a new tab in Terminator I can use this like so:
set_title "My new tab title"
Apologies to those who already stated the essentials of this answer, but since I found that I had to make slight changes to get it to work for me, this my also benefit someone else.
Try add PROMPT_COMMAND='echo -en "\033]0; $("pwd") \a"' in your .bashrc
For terminator 0.98 (Ubuntu 16.04 MATE), right clicking the title enables renaming it.
Right click on terminator and choose preferences from the drop-down menu. Choose profiles tab and enable "show title bar" option. It works!!
Tip: You can actually rename each terminator window!!

Can I get terminal title? (or otherwise restore old one)

Setting terminal title is easy with echo -e "\e]0;some title\007". Works with pretty much every terminal program.
What I want is to set terminal title when some program starts - and restore old one when it finishes. Is this possible?
On xterm, the terminal control sequences 22 and 23 work fine, as in
#!/bin/sh
/bin/echo -ne '\033[22;0t' # Save title on stack
/bin/echo -ne "\033]0;$(date)\007"
sleep 1
/bin/echo -ne '\033[23;0t' # Restore title from stack
It looks like this isn't supported in the Mac OS X Terminal.App though.
There are some terminal programs that supporting it (xterm has compile time options for that, as mentioned by RWS), but most terminal programs simply lack such feature, including in particular Terminal.app.
Yes, that is possible indeed. See a xterm reference manual (like this for example) and wander your way through it. xterm even has a build in stack for this, so you don't have to store the title manually.
My solution was to set the window title during my script, then unset the window title when I completed. Unsetting the title reverted to the original value. Specifically, I did the following:
# Set the terminal title
printf "\e]2;%s\a" "running my script"
# Do whatever processing is required.
...
# Restore terminal title
printf "\e]2;\a"

X11: move an existing window via command line?

Given an X client window ID, is there a way to move that window or change its geometry from the command line?
$ xlsclients -a
Window 0x3000001:
Machine: ohm
Name: Terminal
Icon Name: foo
Command: foo
Instance/Class: foo/bar
$ xmovewindow -id 0x3000001 --geometry +100+200 <-- this is what I would like to do
I think xdotool will do the job.
xdotool lets you programatically (or manually) simulate keyboard input and mouse activity, move and resize windows, etc. It does this using X11's XTEST extension and other Xlib functions.
E.g.
$ xdotool windowfocus 0x1a00ad2
will focus the window with id 0x1a00ad2. There's also a windowmove command which is probably the one you're looking for.
wmctrl is slighty more advanced. It is compatible with EWMH/NetWM X window managers as you can read on their website. I don't think you'll need it to be compatible with those though.

Resources