diff options
-rw-r--r-- | README.md | 14 | ||||
-rw-r--r-- | cdlog.sh | 23 |
2 files changed, 31 insertions, 6 deletions
@@ -64,9 +64,7 @@ current again that new new session that `cdlog` had allocated on startup. That new session does not appear in the numbered list of recoverable sessions unless it has been already persisted by the execution of a directory-changing command. -* The `cdalias` command is used for defining "cd aliases"; see below. - -* The `cdaliases` command lists cd aliases. +* The `cdalias` command is used for defining or listing "cd aliases"; see below. * The `cdunalias` command removes a cd alias. @@ -107,6 +105,16 @@ If the replacement begins with `@` then it is a search. If the search succeeds, then the result will be used as the alias value. +When `cdalias` is invoked with no arguments, it lists all the +currently defined aliases. + +When `cdalias` is invoked with one argument, and that argument +names an alias, it lists that alias. Otherwise it fails +with an error message. + +The deprecated `cdaliases` command also lists aliases; it +will disappear in a future version of `cdlog`. + ## Searches A search is an arguments which begins with `@`. The rest @@ -437,10 +437,27 @@ cdlog.alias() { local def= - if [ $# -ne 2 ] ; then - printf "cdlog.alias: two arguments required\n" + case $# in + ( 0 ) + cdlog.aliases + return $? + ;; + ( 1 ) + if [ ${cdlog_alias[$1]+y} ] ; then + printf "%s -> %s\n" "$1" "${cdlog_alias[$1]}" + return 0 + else + printf "cdlog.alias; %s: not defined\n" "$1" + return 1 + fi + ;; + ( 2 ) + ;; + ( * ) + printf "cdlog.alias: one or two arguments required\n" return 1 - fi + ;; + esac if [ -z "$1" ] ; then printf "cdlog.alias: alias may not be empty\n" |