How do I get fish shell prompt to show the hostname?

6,865

You want set -q __fish_prompt_hostname without the $

You'll notice, in the fine documentation:

set ( -q | --query ) [SCOPE_OPTIONS] VARIABLE_NAMES...
# ............................................^^^^
Share:
6,865

Related videos on Youtube

longviewbits
Author by

longviewbits

Portland techie, love all things *nix. Learning Python to get my start on world domination!

Updated on September 18, 2022

Comments

  • longviewbits
    longviewbits almost 2 years

    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

  • longviewbits
    longviewbits almost 9 years
    Thank you very much, Glenn. That did the trick. Much appreciated, sir!