diff options
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | cdlog.sh | 29 |
2 files changed, 33 insertions, 0 deletions
@@ -52,6 +52,10 @@ the current session, or press Enter to do nothing. * The `cdalias` command is used for defining "cd aliases"; see below. +* The `cdaliases` command lists cd aliases. + +* The `cdunalias` command removes a cd alias. + In addition, the `cdlog.sh` script sets the bash `direxpand` option. With the `direxpand` option, Tab completion on a directory coming from a variable name will expand that variable into the command line. @@ -329,10 +329,37 @@ cdlog.alias() return 1 fi + if [ -z "$1" ] ; then + printf "cdlog.alias: alias may not be empty\n" + return 1 + fi + cdlog_alias[$1]=$2 return 0 } +cdlog.aliases() +{ + local alias + + for alias in "${!cdlog_alias[@]}"; do + printf "%s -> %s\n" "$alias" "${cdlog_alias[$alias]}" + done +} + +cdlog.unalias() +{ + local alias + + for alias in "$@"; do + if [ -n "${cdlog_alias[$alias]-}" ]; then + unset cdlog_alias[$alias] + else + printf "no such cdlog alias: %s\n" "$alias" + fi + done +} + # Tab completion for cd aliases cdlog.complete() @@ -372,6 +399,8 @@ alias mcd='cdlog.mcd' alias mcs='cdlog.mcd -s' alias cdr='cdlog.recover' alias cdalias='cdlog.alias' +alias cdaliases='cdlog.aliases' +alias cdunalias='cdlog.unalias' # Better completion for $x[Tab] shopt -s direxpand |