diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-02-03 21:51:12 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-02-03 21:51:12 -0800 |
commit | daf140a6a54968a20920f8f5c167cdd27709a83c (patch) | |
tree | e7c0b1c8c31a50660e8d9e94c8bd072ae433af47 | |
parent | be4d728fe35561af37d98e9f51a6e89232a1e53e (diff) | |
download | cdlog-daf140a6a54968a20920f8f5c167cdd27709a83c.tar.gz cdlog-daf140a6a54968a20920f8f5c167cdd27709a83c.tar.bz2 cdlog-daf140a6a54968a20920f8f5c167cdd27709a83c.zip |
pd: support optional argument about which entry to pop.
* cdlog.sh (cdlog.pop): Rewritten to take argument 1-9, and
iterate from there.
* README.md: Documented.
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | cdlog.sh | 31 |
2 files changed, 28 insertions, 11 deletions
@@ -29,9 +29,11 @@ arguments, it rotates among those. The directory is changed to the by the second item, the second by the third and so on. The last item receives the previously current directory. -* `pd` (pop dir) is an alias for a command which changes to the most recent -directory in the log, and removes that entry from the log. The second -most recent directory becomes most recent and so on. +* `pd` (pop dir) is an alias for a command which changes to (by default) the +most recent directory in the log, and removes that entry from the log. The second most +recent directory becomes most recent and so on. If it is given an argument +value in the range 1 to 9, it changes to the specified entry, and removes it, +moving the others down to close the gap. Thus `pd 1` is equivalent to `pd`. * `cdlog` function shows a listing of the four most recent entries in the log, or all nine if given the `-l` argument. The `cl` command is an alias for @@ -91,17 +91,32 @@ cdlog.rot() # from the log. cdlog.pop() { - if [ -n "$c1" ] && command cd "$c1"; then - c1=$c2; c2=$c3; c3=$c4 - c4=$c5; c5=$c6; c6=$c7 - c7=$c8; c8=$c9; - - c9= + local d=("" "$c1" "$c2" "$c3" "$c4" "$c5" "$c6" "$c7" "$c8" "$c9") + local n=1 + local i - cdlog.nicks + unset d[0] - printf "%s\n" "$PWD" + if [ $# -gt 0 ] ; then + n=$1; shift fi + + case $n in + ( [1-9] ) + if command cd "${d[$n]}" ; then + for ((i = n; i <= 8; i++)); do + d[$i]=${d[$((i + 1))]} + done + d[9]= + cdlog.args "${d[@]}" + printf "%s\n" "$PWD" + fi + ;; + ( * ) + printf "cdlog.pop: bad argument: %s\n" "$n" + return 1 + ;; + esac } # Print four recent cdlog entries. |