diff options
author | Derek Harland <donkopotamus@users.noreply.github.com> | 2015-07-09 14:54:49 +1200 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2015-07-12 12:20:44 -0700 |
commit | 05daedf7c6b8ad7cc84d0be644e9a2cb8a140128 (patch) | |
tree | f2206e0e1bb699625cfcd93a658bbc96c84cdd4b /share/functions/dirs.fish | |
parent | f07d59c55df1b6ea51f49c9fef0411c1d02e1a27 (diff) |
Improve dirs output and add -c option
Adds behaviour similar to bash:
- shorten dirs output by representing $HOME as ~;
- provide a '-c' option to clear the stack
Diffstat (limited to 'share/functions/dirs.fish')
-rw-r--r-- | share/functions/dirs.fish | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/share/functions/dirs.fish b/share/functions/dirs.fish index 64660e34..207f6632 100644 --- a/share/functions/dirs.fish +++ b/share/functions/dirs.fish @@ -1,9 +1,18 @@ -function dirs --description "Print directory stack" - echo -n (command pwd)" " - for i in $dirstack - echo -n $i" " - end - echo -end - +function dirs --description 'Print directory stack' + # process options + if count $argv >/dev/null + switch $argv[1] + case -c + # clear directory stack + set -e -g dirstack + return 0 + end + end + # replace $HOME with ~ + echo -n (echo (command pwd) | sed -e "s|^$HOME|~|")" " + for i in $dirstack + echo -n (echo $i | sed -e "s|^$HOME|~|")" " + end + echo +end |