diff options
-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 } |