From df65ed86960904fb9ee0ebfd25aa2ccbf648bcb4 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Thu, 13 Jul 2017 11:53:29 -0700 Subject: [PATCH] update `dirs` to use `argparse` --- share/functions/dirs.fish | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/share/functions/dirs.fish b/share/functions/dirs.fish index 7fd5b0494..3017a148d 100644 --- a/share/functions/dirs.fish +++ b/share/functions/dirs.fish @@ -1,15 +1,20 @@ function dirs --description 'Print directory stack' - # process options - if set -q argv[1] - switch $argv[1] - case -c - # clear directory stack - set -e -g dirstack - return 0 - end + set -l options 'h/help' 'c' + argparse -n dirs --max-args=0 $options -- $argv + or return + + if set -q _flag_help + __fish_print_help dirs + return 0 end - # replace $HOME with ~ + if set -q _flag_c + # Clear directory stack. + set -e -g dirstack + return 0 + end + + # Replace $HOME with ~. string replace -r '^'"$HOME"'($|/)' '~$1' -- $PWD $dirstack | string join " " echo end