Make prompt_pwd make a lot more sense

Remove the case statements, which were handled by the sed blocks anyway
Move around the '/' character in the regex, so only one regex is needed
Fix a bug where '/' is output as '//'
This commit is contained in:
Emily Eisenberg
2012-07-06 01:41:07 -07:00
committed by ridiculousfish
parent c45479a6e5
commit d07e78c59a

View File

@@ -1,22 +1,10 @@
if test (uname) = Darwin
function prompt_pwd --description "Print the current working directory, shortend to fit the prompt"
if test "$PWD" != "$HOME"
printf "%s" (echo $PWD|sed -e 's|^/private\(/.\{1,\}\)|\1|' -e "s|^$HOME|~|" -e 's-/\(\.\{0,1\}[^/]\)\([^/]*\)-/\1-g')
echo $PWD|sed -n -e 's-.*/\.\{0,1\}.\([^/]*\)-\1-p'
else
echo '~'
end
echo $PWD | sed -e "s|^$HOME|~|" -e 's|^/private||' -e 's-\([^/]\)[^/]*/-\1/-g'
end
else
function prompt_pwd --description "Print the current working directory, shortend to fit the prompt"
switch "$PWD"
case "$HOME"
echo '~'
case '*'
printf "%s" (echo $PWD|sed -e "s|^$HOME|~|" -e 's-/\(\.\{0,1\}[^/]\)\([^/]*\)-/\1-g')
echo $PWD|sed -n -e 's-.*/\.\{0,1\}.\([^/]*\)-\1-p'
end
echo $PWD | sed -e "s|^$HOME|~|" -e 's-\([^/]\)[^/]*/-\1/-g'
end
end