0

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.

davidcelis
  • 3,277
  • 1
  • 19
  • 16

1 Answers1

2

I suggest:

echo $PWD | sed -e "s|^$HOME/|~|" -e 's-.*/\([^/]*/[^/]*\)-\1/-'
Beta
  • 96,650
  • 16
  • 149
  • 150
  • This did pretty much just what I wanted! I removed the trailing slash, but everything else worked great. Thank you so much! – davidcelis Jun 10 '13 at 22:23
  • This was very close, thanks. I had to modify like this to get a proper `~/` prefix (a little hacky): `sed -e "s|^$HOME/||" -e 's-.*/\([^/]*/[^/]*\)-\1/-' | sed "s/^/~\//"` – Erik Nomitch Aug 30 '16 at 20:17