Dorilds
Dorilds

Reputation: 448

change fish shell prompt based on hostname

How do I go about changing my fish shell prompt when I'm on a different machine via ssh.

I get it working with running a set -q __fish_prompt_hostname at the top of my prompt config and "$__fish_prompt_hostname" when I want to call it, but when I ssh to another machine it cannot find the hostname and display it.

I know in bash $HOSTNAME is the way to go, but with fish I'm not sure how to get the hostname. (I also would like to change the colors of my prompt based on the hostname due to some machines being more volatile than others.)

Any suggestions?

Upvotes: 2

Views: 3549

Answers (1)

Kurtis Rader
Kurtis Rader

Reputation: 7459

You can emulate bash by putting set -x HOSTNAME (hostname) in your ~/.config/fish/config.fish. You may prefer to strip the domain name from it with set -x HOSTNAME (hostname | string split -m1 '.')[1]. That is what the prompt_hostname function does to set the __fish_prompt_hostname var.

Upvotes: 4

Related Questions