Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fish shell - Showing the current command in the window title of screen

I want the current command to be shown in the title of screen (or tmux).

I tried following settings but it doesn't work.

How can I make it work?

.screenrc

shelltitle "$ |fish"
shell /usr/local/bin/fish

.config/fish/config.fish

set -x PS1 '\033k\033\\[\u@\h \W]\$ '
like image 809
Shonosuke Avatar asked Jul 22 '14 10:07

Shonosuke


4 Answers

For fish version 2.1.0 you only have to edit ~/.config/fish/functions/fish_title.fish

function fish_title
    hostname
end

For version 1.23.1 this doesn't seem to work. If the directories do not exist, first create them:

mkdir -p ~/.config/fish/functions/

like image 103
Mr. Morris Avatar answered Oct 25 '22 20:10

Mr. Morris


What worked for me in .config/fish/functions/fish_title.fish :

function fish_title
    # this one sets the X terminal window title
    # argv[1] has the full command line
    echo (hostname): (pwd): $argv[1]

    switch "$TERM"
    case 'screen*'

      # prepend hostname to screen(1) title only if on ssh
      if set -q SSH_CLIENT
        set maybehost (hostname):
      else
        set maybehost ""
      end

      # inside the function fish_title(), we need to
      # force stdout to reach the terminal
      #
      # (status current-command) gives only the command name
      echo -ne "\\ek"$maybehost(status current-command)"\\e\\" > /dev/tty
    end
end
like image 39
melissa_boiko Avatar answered Oct 25 '22 20:10

melissa_boiko


I think you're looking for fish_title. See documentation here.

You could do something like this:

function fish_title
    echo $_ ' '
    pwd
end
funcsave fish_title

(Note you just run this at a prompt - don't put it in a config file).

like image 45
ridiculous_fish Avatar answered Oct 25 '22 22:10

ridiculous_fish


Thanks for your answers. Finally, this made it work!

.screenrc

shelltitle "$ |fish"
shell /usr/local/bin/fish

.config/fish/config.fish

function fish_prompt
    echo -ne '\033k'
    echo -ne $argv
    echo -ne '\033\\'
    echo -ne '$ '
end
like image 29
Shonosuke Avatar answered Oct 25 '22 20:10

Shonosuke