diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-02-20 12:25:43 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-02-20 12:25:43 -0800 |
commit | d4aec2c73cbf130f8c7ef174340eb959ca52fd7f (patch) | |
tree | e6a253c1dcb9a40b19dedfe245bd1d7cece7a577 | |
parent | b39cd46c89139ac9bb42bdd8be96e301e296738f (diff) | |
download | cdlog-d4aec2c73cbf130f8c7ef174340eb959ca52fd7f.tar.gz cdlog-d4aec2c73cbf130f8c7ef174340eb959ca52fd7f.tar.bz2 cdlog-d4aec2c73cbf130f8c7ef174340eb959ca52fd7f.zip |
cdalias: take zero, one or two args.
* cdlog.sh (cdlog.alias): Behave like cdlog.aliases in the
zero argument case, and in the one argument case list
the specified alias, if it exists.
* README.md: Updated. The cdaliases command becomes
deprecated.
-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" |