diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-03-14 09:46:07 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-03-14 09:46:07 -0700 |
commit | e306be78a574f324af674db992e8a6b26bf32a5d (patch) | |
tree | b594d81f2420ae836fcb6b0f2a3808a424bd1e7f | |
parent | 0fad745195ab537a4448cb969e30f352de1b9915 (diff) | |
download | cdlog-e306be78a574f324af674db992e8a6b26bf32a5d.tar.gz cdlog-e306be78a574f324af674db992e8a6b26bf32a5d.tar.bz2 cdlog-e306be78a574f324af674db992e8a6b26bf32a5d.zip |
pd: implement -f option.
Problem: when the cdlog contains a directory that cannot be
entered, for instance due to not existing any more, we would
like to delete it with "pd", but cannot.
* cdlog.sh (cdlog.pop): Implement -f (force) option which
will ignore the failing cd command and delete the entry
anyway. Fix typo in header comment.
* README.md: Mention -f in description of `pd` alias.
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | cdlog.sh | 9 |
2 files changed, 10 insertions, 2 deletions
@@ -34,6 +34,9 @@ most recent directory in the log, and removes that entry from the log. The secon 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`. +`pd` takes a `-f` option which means "force". This is useful when it's +not possible to change to the indicated directory, in which case `-f` +causes it to be removed in spite of this. * `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 @@ -233,13 +233,18 @@ cdlog.rot() } -# Change to most recent diretory in cdlog and remove it +# Change to most recent directory in cdlog and remove it # from the log. cdlog.pop() { declare -n d=cdlog_hist local n=1 local i + local force= + + if [ $# -gt 0 -a "$1" = "-f" ] ; then + force=y; shift + fi if [ $# -gt 0 ] ; then n=$1; shift @@ -247,7 +252,7 @@ cdlog.pop() case $n in ( [1-9] ) - if command cd "${d[$n]}" ; then + if command cd "${d[$n]}" || [ $force ]; then for ((i = n; i < ${#d[@]}; i++)); do d[$i]=${d[$((i + 1))]} done |