From 1bca0a6205c0c22bc0e23c642f47da18d5164766 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 26 May 2017 20:46:48 +1200 Subject: Remove ad() It has no real advantages over and isn't as clever as just cd /a*/b*/c* --- IDEAS.markdown | 3 -- README.markdown | 2 -- bash/bash_completion.d/ad.bash | 2 -- sh/shrc.d/ad.sh | 80 ------------------------------------------ 4 files changed, 87 deletions(-) delete mode 100644 bash/bash_completion.d/ad.bash delete mode 100644 sh/shrc.d/ad.sh diff --git a/IDEAS.markdown b/IDEAS.markdown index 083df51b..4cac76f7 100644 --- a/IDEAS.markdown +++ b/IDEAS.markdown @@ -8,8 +8,5 @@ Ideas * Have eds(1df) accept stdin with the "starting content" for the script * Convert all the manual pages to mandoc maybe? * qmp(1df)--quick man page -* ad() could be more intelligent; if there's only one directory that matches - the *whole pattern*, we can assume it's safe to use that one, rather than - stopping each time any node has more than one match * The solution to chn(1df) not running in parallel is probably backgrounded processes and mkfifo(1). diff --git a/README.markdown b/README.markdown index 4cd8ebd0..9d16abe5 100644 --- a/README.markdown +++ b/README.markdown @@ -189,8 +189,6 @@ in `sh/shrc.d` to be loaded by any POSIX interactive shell. Those include: * `pmd()` prints the marked directory. * `xd()` swaps the current and marked directories. * Ten other directory management and navigation functions: - * `ad()` is a `cd` shortcut accepting targets like `/u/l/b` for - `/usr/local/bin`, as long as they are unique. * `bd()` changes into a named ancestor of the current directory. * `gt()` changes into a directory or into a file's directory. * `lgt()` runs `gt()` on the first result from a `loc(1df)` search. diff --git a/bash/bash_completion.d/ad.bash b/bash/bash_completion.d/ad.bash deleted file mode 100644 index 390fcb00..00000000 --- a/bash/bash_completion.d/ad.bash +++ /dev/null @@ -1,2 +0,0 @@ -# Completion function for ad(); just directories -complete -A directory ad 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 -- "$@" -} -- cgit v1.2.3