2

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?

3
  • 1
    Please post your code that sets fish_title.
    – Chris Page
    Aug 25, 2011 at 23:46
  • This will set the window title in bash and zsh: printf '\e]2;Custom Window Title\a' Does that work in fish?
    – Chris Page
    Aug 25, 2011 at 23:48
  • For 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.
    – Chris Page
    Aug 25, 2011 at 23:58

3 Answers 3

3

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.

10

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

It is likely something to do with the configuration of Terminal.app. I'm running Terminal 2.0.2 on Leopard which allows me to configure the window's title via the preferences (see settings -> window).

It's possible that enabling 'shell command name' might get your desired result. The default is just to display Terminal - $process - $size probably over-rules the fish environment.

2
  • I'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.
    – fideli
    Dec 16, 2009 at 1:04
  • None of Terminal's preferences will override or disable the escape sequence for setting the window and tab titles.
    – Chris Page
    Aug 25, 2011 at 23:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .