Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current directory (without full path) in Fish Shell

Tags:

prompt

fish

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.

like image 653
Julian Coleman Avatar asked Jul 06 '15 17:07

Julian Coleman


People also ask

How do I find my current directory name in shell?

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.

How do I get current working directory in bash?

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.

How do I customize my fish shell prompt?

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!".

How do I get the current working directory in Python?

To find the current working directory in Python, use os. getcwd() , and to change the current working directory, use os. chdir(path) .


1 Answers

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
like image 183
Julian Coleman Avatar answered Sep 28 '22 05:09

Julian Coleman