How do I set the title of Terminal.app with the fish shell?
Solution 1
I installed fish (1.23.1) to investigate this. It turns out that fish only updates the title if $TERM
is one of the following: xterm
, screen
, nxterm
, rxvt
. Otherwise, it never calls the fish_title
function.
Terminal's default value is xterm-256color
and prior to Mac OS X Lion 10.7 it was xterm-color
, neither of which is recognized by fish. Fish is simply being unreasonably conservative about which terminfo values it thinks support this feature. fish_title
isn't called for any xterm*
variants, for example.
To work around this limitation of fish, you can set $TERM
to xterm
. The simplest way to do this is with a Terminal preference setting:
Terminal > Preferences > Settings > [profile] > Advanced > Declare terminal as
Select xterm
from the popup menu. This preference controls the value of $TERM
(that's all it does).
Note that using xterm
instead of Terminal's default may disable some terminal functionality or, prior to Lion, cause misbehavior due to incompatibilities between the xterm
terminfo description and older versions of Terminal.
Therefore, if fish isn't your default shell, you may want to only change $TERM
when invoking fish. e.g., you can invoke fish with TERM=xterm fish
from a shell, or you can create a custom Terminal settings profile just for running fish (you can set the "Run command" preference to invoke fish, so creating a new terminal window or tab with this profile will automatically run fish).
Or, if you're not shy about modifying fish: once you've installed it via MacPorts or Fink you've got the sources sitting on your machine and you can extend its list of recognized $TERM values, or even update the code to allow for suffixes on the recognized values. e.g., it should at least allow any values that start with xterm
or screen
. Otherwise, it's not even going to work with common screen
variants. And if you do that, please contribute it back to the fish project.
Solution 2
If you found this question wondering how to change the window/tab title in fish, and the fish_title
function works for you (see Chris Page's answer), then here's an example that sets the title to use a shortened version of your working directory.
$ funced fish_title
function fish_title
if [ $_ = 'fish' ]
echo (prompt_pwd)
else
echo $_
end
end
$ funcsave fish_title
Related videos on Youtube
Lorin Hochstein
Software engineer, often doing operations stuff. Once upon a time I was an academic. I work on the Delivery Engineering team at Netflix.
Updated on September 17, 2022Comments
-
Lorin Hochstein over 1 year
I'm trying the fish shell in Mac OS X, intalled using MacPorts. I'd like to have the title of my Terminal window be my current directory. Currently, the title just says
Terminal - fish - 80x24
According to the fish documentation, the default
fish_title
function should provide this behavior. It doesn't do the right thing in Terminal.app, although it does work with iTerm. Defining my own fish_title function doesn't fix the problem.Has anybody been able to get this to work?
-
Chris Page over 12 yearsPlease post your code that sets fish_title.
-
Chris Page over 12 yearsThis will set the window title in bash and zsh:
printf '\e]2;Custom Window Title\a'
Does that work in fish? -
Chris Page over 12 yearsFor comparison, try doing it using fish in xterm and see if it works there. Another thing to check is the value of $TERM. In Lion, Terminal changed the default value from "xterm-color" to "xterm-256color". Perhaps fish is depending on $TERM to decide whether to actually emit the escape sequence to set the title.
-
-
fideli over 14 yearsI'm not sure about that. For example, in bash, one can set the title following these instructions: superuser.com/questions/79972/…. But those instructions don't work for the fish shell.
-
Chris Page over 12 yearsNone of Terminal's preferences will override or disable the escape sequence for setting the window and tab titles.