aboutsummaryrefslogtreecommitdiff
path: root/config/fish/functions/upto.fish
diff options
context:
space:
mode:
Diffstat (limited to 'config/fish/functions/upto.fish')
-rw-r--r--config/fish/functions/upto.fish29
1 files changed, 29 insertions, 0 deletions
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