How to get fish shell prompt to show the hostname

fishpromptshell

I'm attempting to make my Fish prompt look like the old Gentoo shell did.

user@hostname ~ %
where the user@hostname is green, and the $PWD and symbol were blue.

Right now it only shows: user@ ~ %, and no hostname.

aaron@ ~ % su -
Password: 
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
root@ ~ % hostname
rpi
root@ ~ % cat .config/fish/functions/fish_prompt.fish 
function fish_prompt
      if not set -q $__fish_prompt_hostname
        set -g __fish_prompt_hostname (hostname)
     end
     set_color -o red
     echo -n -s "$USER" @ "$__fish_prompt_hostname" " "
     set_color -o blue
     echo -n (prompt_pwd)
     echo -n " % "
     set_color normal
end

Another odd thing… before I rebooted, it was showing up correctly:

enter image description here

Best Answer

  • You want set -q __fish_prompt_hostname without the $

    You'll notice, in the fine documentation:

    set ( -q | --query ) [SCOPE_OPTIONS] VARIABLE_NAMES...
    # ............................................^^^^
    
  • Related Question