aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-05-26 20:46:48 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-05-26 20:48:56 +1200
commit1bca0a6205c0c22bc0e23c642f47da18d5164766 (patch)
tree05fd360aed42f204a934a235b7de52debfc8ef1d /sh
parent0eca7eafffbd667b7e5f4d2423adb54ea5582165 (diff)
downloaddotfiles-1bca0a6205c0c22bc0e23c642f47da18d5164766.tar.gz
Remove ad()
It has no real advantages over and isn't as clever as just cd /a*/b*/c*
Diffstat (limited to 'sh')
-rw-r--r--sh/shrc.d/ad.sh80
1 files changed, 0 insertions, 80 deletions
diff --git a/sh/shrc.d/ad.sh b/sh/shrc.d/ad.sh
deleted file mode 100644
index 55866683..00000000
--- a/sh/shrc.d/ad.sh
+++ /dev/null
@@ -1,80 +0,0 @@
-# Find an abbreviated path
-ad() {
-
- # Check argument count
- if [ "$#" -ne 1 ] ; then
- printf >&2 'ad(): Need just one argument\n'
- return 2
- fi
-
- # Change the positional parameters from the abbreviated request
- # to any matched directory
- set -- "$(
-
- # Clean up and anchor the request
- req=${1%/}/
- case $req in
- (/*) ;;
- (*) req=${PWD%/}/${req#/} ;;
- esac
-
- # Start building the target directory; go through the request piece by
- # piece until it is used up
- dir=
- while [ -n "$req" ] ; do
-
- # Chop the next front bit off the request and add it to the dir
- dir=${dir%/}/${req%%/*}
- req=${req#*/}
-
- # If that exists, all is well and we can keep iterating
- [ -d "$dir" ] && continue
-
- # Set the positional parameters to a glob expansion of the
- # abbreviated directory given
- set -- "$dir"*
-
- # Iterate through the positional parameters filtering out
- # directories; we need to run right through the whole list to check
- # that we have at most one match
- entd=
- for ent ; do
- [ -d "$ent" ] || continue
-
- # If we already found a match and have found another one, bail
- # out
- if [ -n "$entd" ] ; then
- printf >&2 'ad(): More than one matching dir for %s*:\n' \
- "$dir"
- printf >&2 '%s\n' "$@"
- exit 1
- fi
-
- # Otherwise, this can be our first one
- entd=$ent
- done
-
- # If we found no match, bail out
- if [ -z "$entd" ] ; then
- printf >&2 'ad(): No matching dirs: %s*\n' "$dir"
- exit 1
- fi
-
- # All is well, tack on what we have found and keep going
- dir=$entd
-
- done
-
- # Print the target with trailing slash to work around newline stripping
- printf '%s/' "${dir%/}"
- )"
-
- # Remove trailing slash
- set -- "${1%/}"
-
- # If the subshell printed nothing, return with failure
- [ -n "$1" ] || return
-
- # Try to change into the determined directory
- command cd -- "$@"
-}