diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-03-07 11:44:35 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-03-07 11:44:35 -0800 |
commit | 0fad745195ab537a4448cb969e30f352de1b9915 (patch) | |
tree | f47c443365212eff4fcb5ec7d0888d2e2d9b3283 | |
parent | 5431aa1f4346feea1cb9680945639d8f1b180c9c (diff) | |
download | cdlog-0fad745195ab537a4448cb969e30f352de1b9915.tar.gz cdlog-0fad745195ab537a4448cb969e30f352de1b9915.tar.bz2 cdlog-0fad745195ab537a4448cb969e30f352de1b9915.zip |
Commands for listing and deleting cd aliases.
* cdlog.sh (cdlog.alias): Check against empty alias name.
(cdlog.aliases, cdlog.unalias): New functions.
(cdaliases, cdunalias): New aliases.
* README.md: Documented.
-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 |