bash: change tab title when command is run - bash

I want to change the tab title in iTerm2 if a specific command is run. Specifically, when the runserver command from django is run, I would like the tab to show 'runserver' in the title.
I've been experimenting with bash escape codes, but I can't find something to do this. I have seen trap brought up in similar questions, but I can't find great documentation on how to do something like what I want.
iTerm2 also has 'triggers' in preferences that checks for regex matches, but I can't get the 'command' portion to execute. I.e. catching the string 'Starting development server at' via regex and running the command echo test does not do anything.

Open 'Preference' (⌘+,)
Select 'Appearance' Tab
Select 'Show current job name' in field 'Windows & Tab Titles'
Base on iTerm 2.9

Related

Automatic meaningful titles for GNOME Terminal tabs

(related: Identify gnome-terminal window by tab title)
When I open several tabs in GNOME Terminal (Version 3.44.0 for GNOME 42) on my Ubuntu 22.04, all tabs have the uninformative title "Terminal". I want them to be automatically titled:
the current working directory if it's in shell prompt (e.g. /home/user123/Downloads)
the name of the open process (e.g. vim ~/.bashrc) in case there is an open process.
How can I achieve that? I use bash, but I can switch to zsh if necessary.
From another thread somewhere on the internet:
function termtitle()
{
printf "\033]0;$*\007";
}
I put this in my .bashrc right above my PS1Update(). Then I call it in PS1Update, right after I update the prompt. I call it with a string constructed from some env flags, username, hostname, pwd. You can put almost anything. I throw in $0. I did try using $PS1, but I use color and I think the printf in termtitle() trips over the escape sequences. So I build another string with the same info but w/o color.
Every time the prompt is updated, so it the terminal window/tab title, like if I change dir, ssh to another machine.
Hope this helps!

Why is scrappy shell in command line trying to autocomplete my commands and running to the next line?

I am using Terminal on Mac. When I enter scrapy shell 'website url', terminal starts trying to autocomplete my code and it becomes very hard to type. Code runs onto the next line. This error only occurs in the shell, not in normal terminal.
At the bottom of the screen, it says
[F4] Emacs 1/1 [F3] History [F6] Paste mode [F2] Menu - CPython 3.7.3
It never used to display this status. I would like to turn autocomplete off so I can use the shell normally.
In Terminal Preferences, I tried selecting 'Restore Default Profiles'. This did not help.
Emacs was open within scrapy shell. I uninstalled the package and it worked.

Change in the hostname/user in Terminal in Leopard OSX

My terminal previously showed subalcharla$ at the command line.
The terminial is now showing subalcharla#subal-charlas-macbook ~ $.
How do I go back to the original setting?
What is the difference between the two?
How did this get changed without my doing so?
At the end of ~/.profile add the line
export PS1='\u$ '
to get your old prompt back.
To do this you can type
nano ~/.profile
which will bring up a text editor. Press down until you get to the bottom of the file. Hit Enter to create a new line, and paste in
export PS1='\u$ '
Press Control+X to exit the editor and say "yes" when asked if you want to save. Now restart your terminal and your prompt should be restored.
The first prompt you gave shows your username, the second shows your username and hostname. There is no error and the functionality of your bash shell is not changed by changing the prompt.
Something must have changed your PS1 environment variable, maybe a system update or the installation of software. It's probably benign though.
I don't know how it got changed, but it's controlled by some symbol definitions. Use "man bash" in the terminal and search for the section called "PROMPTING". There are symbols named PS1-to-4 that it uses to construct the prompt.

iTerm 2 name length

I am new to OSX and have downloaded iTerm 2 and my name for the command line is superfluously long.
It looks like my-name-Macbook-pro:~ myname$
and I want it to look like ~myname$
Is there an easy way to shorten this name, I have googled as much as I can but can't find an easy solution.
This has nothing to do with OSX or with iterm2. OSX by default uses the bash shell and you just need to set the prompt correctly.
The prompt is set by the variable PS1. See this article on how to set your bash prompt. To achieve what you want, you need the \w and the \u fields. So something like
PS1=\\w:\\u\$
will give you ~:myname$. Play around with the other options and see what you like best. Once you find a setting that you like, enter it in your .bashrc file so that it is loaded every time you login. Also see this question for cool stuff to put in your .bashrc.

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!!

Resources