aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-05-27 21:17:34 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-05-27 21:21:15 +1200
commit1a672fccf7d8c9b41e02d86c1f7f39a5d025aaf6 (patch)
treed7ae4f9192ff7508894f9a611387806083b212b7 /sh
parent8571498f0f8c27b35a2ed813ace1b0c04e2c1dfd (diff)
downloaddotfiles-1a672fccf7d8c9b41e02d86c1f7f39a5d025aaf6.tar.gz
More refinements to bd()
Diffstat (limited to 'sh')
-rw-r--r--sh/shrc.d/bd.sh39
1 files changed, 11 insertions, 28 deletions
diff --git a/sh/shrc.d/bd.sh b/sh/shrc.d/bd.sh
index 9b877faf..1b253e3d 100644
--- a/sh/shrc.d/bd.sh
+++ b/sh/shrc.d/bd.sh
@@ -20,44 +20,27 @@ bd() {
return 2
;;
- # Otherwise, we'll try to find a matching ancestor and then shift the
- # initial request off the argument list
+ # Otherwise, add and keep chopping at the current directory until it's
+ # empty or it matches the request, then shift the request off
*)
-
- # Push the current directory onto the stack
set -- "$1" "$PWD"
-
- # Keep chopping at the current directory until it's empty or it
- # matches the request
while : ; do
-
- # Make certain there are no trailing slashes to foul us up
- while : ; do
- case $2 in
- */) set -- "$1" "${2%/}" ;;
- *) break ;;
- esac
- done
-
- # Strip a path element
- set -- "$1" "${2%/*}"
-
- # Check whether we're arrived
case $2 in
- */"$1") break ;;
- */*) ;;
- *)
- printf >&2 'bd(): No match\n'
- return 1
- ;;
+ */"$1"|'') break ;;
+ */) set -- "$1" "${2%/}" ;;
+ *) set -- "$1" "${2%/*}" ;;
esac
done
-
- # If the first argument ended up empty, we have no match
shift
;;
esac
+ # If we have nothing to change into, there's an error
+ if [ -z "$1" ] ; then
+ printf >&2 'bd(): No match\n'
+ return 1
+ fi
+
# We have a match; try and change into it
command cd -- "$1"
}