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

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/


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