Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to simulate GNU Screen's shelltitle feature in tmux. I have the following in my ~/.bashrc:

if [[ "$TERM" == screen* ]]; then
    SCREEN_ESC='\[\ek\e\\\]'
else
    SCREEN_ESC=''
fi

PS1="\n\w ${SCREEN_ESC}$ "

and the following in my ~/.screenrc:

shelltitle        "$ |bash"

Setting shelltitle makes GNU Screen search for a newline in the shell and strip away all the characters from $PS1 upto the escape character, and replace it with the first word found after that. This is more clearly explained in the man page:

Here's how it works: you must modify your shell prompt to output a null title-escape-sequence (<esc>k<esc>) as a part of your prompt. The last part of your prompt must be the same as the string you specified for the search portion of the title. Once this is set up, screen will use the title-escape-sequence to clear the previous command name and get ready for the next command. Then, when a newline is received from the shell, a search is made for the end of the prompt. If found, it will grab the first word after the matched string and use it as the command name. If the command name begins with either '!', '%', or '^' screen will use the first word on the following line (if found) in preference to the just- found name.

This is different from tmux's set-option -g set-titles on which only captures the process name. So a Python script script.py would be titled as script.py in Screen (which is the way I want it) whereas, it would be titled as python in tmux (which I don't want.)

I know that one can rename tmux windows by:

printf '\033kWINDOW_NAME\033\\'

So I was wondering if there is some way I can alternatively let tmux know that I've entered a new command. If there is some way I can get the last command entered, I could use Bash's PROMPT_COMMAND to do this. Any ideas?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.