Fish-shell: fish in emacs' ansi-term has prompt issues

Created on 11 Jun 2012  ·  16Comments  ·  Source: fish-shell/fish-shell

Under emacs's ansi-term (probably the only way to get the real power of fish inside of emacs), the prompt looks like:

2;fish /home/ahyatt2;fish /home/ahyatt
ahyatt@ahyatt /home/ahyatt>

My term is eterm-color, which is standard for ansi-term. Probably some of the default ansi control sequences in the prompt are not quite kosher.

bug release notes

Most helpful comment

The above fix is close. Adding:

function fish_title
  true
end

to ~/.config/fish/config.fish fixed it for me in Emacs 24.1

All 16 comments

After I reported this, I happened to notice that this is documented in the original fish documentation, with the fix being: echo 'function fish_title;end' > ~/.config/fish/config.fish

However, that doesn't work for me:

Welcome to fish, the friendly interactive shell
Type helpB for instructions on how to use fish
fish: Unknown function “fish_title”
fish: Unknown function “fish_title”
ahyatt@ahyatt ~>

I have exactly the same problem but with iTerm.

The 'fix' didn't work for me either.

The above fix is close. Adding:

function fish_title
  true
end

to ~/.config/fish/config.fish fixed it for me in Emacs 24.1

This is the one.

+1

@akrito Thanks! This worked for me, too.

The fish title hack is not working for me. There may be no title, but it is still changing the folder displayed in the tile (when viewed from iterm)

@SlightlyCyborg: If you don't use the fish title thing, do you get the folder displayed twice (and only once with it)? If you use it on another terminal, does it work?

iTerm has special integration with shells, and the fish version isn't conditional on the $TERM being iTerm, and it only blacklists screen. By default this file will be saved as ~/.iterm2_shell_integration.fish, so you might want to see what happens when you remove that.

@faho I only checked it on iterm (turns out it is just macs standard Terminal) to find out why I was still getting a strange line printed on emacs term every time I used cd

7;file://Collins-MacBook-Air.local/Users/collinbell/dameon

Yes, if I remove the fish_title from the config, then I will see the folder appear twice on the mac Terminal app. The same thing still happens in emacs term.

@SlightlyCyborg: Run this:

    if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal"
        echo "True"
    end

Does it print "true"? In that case, this is _our_ cwd reporting for VTE or Apple Terminal. Since you are running emacs in a terminal that can handle this, we're printing it, but emacs then mangles it so the term no longer gets the full sequence (yet another limitation of ansi-term).

We might need to do what Apple does for Emacs:

/etc/bashrc_Apple_Terminal


# Working Directory
#
# Tell the terminal about the current working directory at each prompt.

if [ -z "$INSIDE_EMACS" ]; then
    update_terminal_cwd() {
    # Identify the directory using a "file:" scheme URL, including
    # the host name to disambiguate local vs. remote paths.

    # Percent-encode the pathname.
    local url_path=''
    {
        # Use LC_CTYPE=C to process text byte-by-byte. Ensure that
        # LC_ALL isn't set, so it doesn't interfere

https://gist.github.com/floam/f535842a16226e77d014d67bade2b2f3

I'm going to add the $INSIDE_EMACS check for the CWD OSC and define an empty fish_title if the user is using VTE/Terminal.app. The reasoning for the latter is that these modern terminals both compose a nicer title if we don't try to provide a custom one (no path in title twice, "fish" in title twice) - and the user can configure which components they'd like in their terminal inside the terminal preferences.

Before and after in Terminal.app (you can configure Terminal.app to show the full path, if you prefer):
messy

cleaner

I got tripped up by the iTerm shell integration. Could we mention that in the readme in the fish section, too?

@rdrey: IIRC, iTerm ships that, so you'll have to take it up with them.

Sorry, I was in the completely wrong repo last night. I thought I was commenting on an issue in https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Btools/shell. 😅

I've created a PR for iTerm2 instead. (https://github.com/gnachman/iterm2-website/pull/35)

Was this page helpful?
0 / 5 - 0 ratings