Reputation: 3347
Currently my zsh
prompt utilizes $'%2~ %%'
to output the current and previous directory before just displaying %
as my input prompt. For example, if I'm in /Users/david/Documents/Code/project
, my prompt will display:
Code/project %
However, if I back up into the Code
directory, a tilde is shown:
~Documents/Code %
I'm trying to reproduce this in the fish
shell by replacing the regex provided in their prompt_pwd
function and gets passed to sed
. By default, that function looks like:
function prompt_pwd --description 'Print the current working directory, shortend to fit the prompt'
echo $PWD | sed -e "s|^$HOME|~|" -e "s|^/private||" -e 's-\([^/]\)[^/]*/-\1/-g'
end
Currently, this outputs the full name of the current directory, but truncates all other directories to one character (and replaces $HOME
with a tilde). I'm trying to figure out what regular expression I can provide that function to duplicate what I had going on in zsh.
Upvotes: 0
Views: 280
Reputation: 99124
I suggest:
echo $PWD | sed -e "s|^$HOME/|~|" -e 's-.*/\([^/]*/[^/]*\)-\1/-'
Upvotes: 2