To my knowledge it is not possible to inspect the state of a terminal from a process in the shell.
But even if you could, changing behavior based on the terminal title would be very error-prone. There's no easy way to check for misspellings or anything like that. It also isn't very scaleable - you'd have one do_something_based_on_title
command that would just keep growing as you add features.
Instead of one massive set-title
script, make each command responsible for setting it's own terminal title when they run. You can do this easily with aliases, like so (put this in your .bashrc
or similar).
set_title() {
echo -e "\e]0;$*\a"
}
alias apic='set_title "API Codebase"; command_for_api_codebase'
alias irc='set_title "IRC"; irssi'
alias server1='set_title "Server1"; ssh server1'
Now you have tab-completion for these commands, no risk of the title-setting and program-starting code getting out of whack, and no more need to right click on the tab to set its title. Just run the commands you want, and wham the title gets set too.
set-title
command? – Hussain Tamboli Feb 25 '16 at 11:43set-title Server1
for example. – terdon Feb 25 '16 at 11:52