diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-04-10 16:29:56 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-04-10 16:29:56 -0700 |
commit | c068e59e179c92b2a7b27e5dbf737ef767e340b9 (patch) | |
tree | 6fa951415dafb9030bcdce9c747a59758388bd5c | |
parent | 5977af54dc0806445445a8732905c8d7ba572e41 (diff) | |
download | cdlog-c068e59e179c92b2a7b27e5dbf737ef767e340b9.tar.gz cdlog-c068e59e179c92b2a7b27e5dbf737ef767e340b9.tar.bz2 cdlog-c068e59e179c92b2a7b27e5dbf737ef767e340b9.zip |
Allow cdalias by number or @ search.
* cdlog.sh (cdlog.alias): Remove unused local variable ali.
Check for a digit or argument starting with @ and
expand accordingly, checking for failure.
* README.md: Documented.
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | cdlog.sh | 24 |
2 files changed, 30 insertions, 2 deletions
@@ -82,6 +82,14 @@ array. The `cdlog.chdir` function recognizes an alias only if it is invoked as `cdlog.chdir -p <alias>`, which is the way `cd` invokes it. +If the replacement (second argument) of `cdalias` is a digit +from 1 to 9, then it refers to that entry in the `cdlog`. +The path at that index will be retrieved and used as the alias value. + +If the replacement begins with `@` then it is a search. If +the search succeeds, then the result will be used as the alias +value. + ## Searches Search are arguments which begin with `@`. The rest @@ -402,7 +402,6 @@ cdlog.mcd() cdlog.alias() { - local ali= local def= if [ $# -ne 2 ] ; then @@ -415,7 +414,28 @@ cdlog.alias() return 1 fi - cdlog_alias[$1]=$2 + def=$2 + + case "$def" in + ( @* ) + if ! def=$(cdlog.at2path "$2"); then + printf "cdlog.alias: no match for %s\n" "$2" + return 1 + fi + ;; + ( [1-9] ) + def=${cdlog_hist[$2]} + if [ -z "$def" ] ; then + printf "cdlog.alias: %s position empty\n" "$2" + return 1 + fi + ;; + ( * ) + def=$2 + ;; + esac + + cdlog_alias[$1]=$def return 0 } |