aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/prompt_pwd.fish
diff options
context:
space:
mode:
authorGravatar Ian Ray <ianjray@me.com>2015-09-30 23:59:46 +0300
committerGravatar Fabian Homborg <FHomborg@gmail.com>2015-10-04 12:36:49 +0200
commit16061d06a91b4ac7aa97819a3b0a2d9af5e413ab (patch)
treec857779de1c6f3ee4ed9dc585c74e7cf55189551 /share/functions/prompt_pwd.fish
parentaeaacedf75a99b06a93d8fe873ed7a795ed4f3dd (diff)
prompt_pwd: zero fork prompt in general case
Now only one fork (uname) occurs on first load.
Diffstat (limited to 'share/functions/prompt_pwd.fish')
-rw-r--r--share/functions/prompt_pwd.fish17
1 files changed, 9 insertions, 8 deletions
diff --git a/share/functions/prompt_pwd.fish b/share/functions/prompt_pwd.fish
index e44b9649..59b6da91 100644
--- a/share/functions/prompt_pwd.fish
+++ b/share/functions/prompt_pwd.fish
@@ -1,14 +1,15 @@
-set -l args_pre
-set -l args_post
+set -l s1
+set -l r1
switch (uname)
case Darwin
- set args_pre $args_pre -e 's|^/private/|/|'
+ set s1 '^/private/'
+ set r1 /
case 'CYGWIN_*'
- set args_pre $args_pre -e 's|^/cygdrive/\(.\)|\1/:|'
- set args_post $args_post -e 's-^\([^/]\)/:/\?-\u\1:/-'
+ set s1 '^/cygdrive/(.)'
+ set r1 '$1:'
end
-function prompt_pwd -V args_pre -V args_post --description "Print the current working directory, shortened to fit the prompt"
- set -l realhome ~
- echo $PWD | sed -e "s|^$realhome\$|~|" -e "s|^$realhome/|~/|" $args_pre -e 's-\([^/.]\)[^/]*/-\1/-g' $args_post
+function prompt_pwd -V s1 -V r1 --description "Print the current working directory, shortened to fit the prompt"
+ set realhome ~
+ string replace -r '^'"$realhome"'($|/)' '~$1' $PWD | string replace -r "$s1" "$r1" | string replace -ar '([^/.])[^/]*/' '$1/'
end