A buddy of mine finally got me to start using Fish Shell and I'm trying to set it up similar to how I had Bash. The PS1
in my .bash_profile
listed the current directory I was in, followed by a >
. It, however, wasn't the absolute path (e.g. /Users/me/Documents/...
or ~/Documents/...
). If I was in /Users/me/Documents/projects/Go/project1/
, the prompt would simply say project1 >
.
Is there a Fish Shell alternative to the \W
substitution available for Bash? Again, I just want the folder I'm in, not the full path. I know you can use the echo (pwd)
for all that.
I have looked into the basename
program, and echo "${PWD##*/}"
, but these appear to only work in Bash.
pwd (print working directory) – The pwd command is used to display the name of the current working directory in the Linux system using the terminal. This is a shell building command that is available in most Unix shells such as Bourne shell, ash, bash, kash, and zsh.
Print Current Working Directory ( pwd ) To print the name of the current working directory, use the command pwd . As this is the first command that you have executed in Bash in this session, the result of the pwd is the full path to your home directory.
Prompt Tab The "prompt" tab displays the contents of the current fish shell prompt. It allows selection from 17 predefined prompts. To change the prompt, select one and press "Prompt Set!".
To find the current working directory in Python, use os. getcwd() , and to change the current working directory, use os. chdir(path) .
Taken from @Jubobs' answer:
basename
is just a Unix utility; it's not associated to a particular shell, and should work equally well in Bash and Fish.
It appeared I was using basename
in the wrong context, and without a suffix.
This was solved by using the following:
function fish_prompt
echo (basename $PWD) "><> "
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With