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