diff options
Diffstat (limited to 'config/fish')
| -rw-r--r-- | config/fish/completions/upto.fish | 1 | ||||
| -rw-r--r-- | config/fish/config.fish | 2 | ||||
| -rw-r--r-- | config/fish/functions/upto.fish | 29 |
3 files changed, 31 insertions, 1 deletions
diff --git a/config/fish/completions/upto.fish b/config/fish/completions/upto.fish new file mode 100644 index 0000000..96ba3b2 --- /dev/null +++ b/config/fish/completions/upto.fish @@ -0,0 +1 @@ +complete -c upto -x -a "(string split '/' $PWD)" diff --git a/config/fish/config.fish b/config/fish/config.fish index 736f8bd..37ee23a 100644 --- a/config/fish/config.fish +++ b/config/fish/config.fish @@ -1,6 +1,6 @@ # autoload functions and completions in .dotfiles set fish_function_path $HOME/.dotfiles/config/fish/functions $fish_function_path -set fish_completion_path $HOME/.dotfiles/config/fish/completions $fish_completion_path +set fish_complete_path $HOME/.dotfiles/config/fish/completions $fish_complete_path # add git-alias subdirectory to functions path diff --git a/config/fish/functions/upto.fish b/config/fish/functions/upto.fish new file mode 100644 index 0000000..9c3bc25 --- /dev/null +++ b/config/fish/functions/upto.fish @@ -0,0 +1,29 @@ +function upto --description 'go up in directory tree' --argument expr + if test -z $expr + echo "A directory expression must be provided." >&2 + return 1 + end + if test $expr = "/" + cd / + return 0 + end + set current_dir $PWD + set matched_dir "" + set matching true + + while test $matching = "true" + if string match -q "*$expr*" $current_dir + set matched_dir $current_dir + set current_dir (dirname $current_dir) + else + set matching false + end + end + if test -n $matched_dir + cd $matched_dir + return 0 + else + echo "No match." >&2 + return 1 + end +end |
