diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-01-25 16:44:39 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-01-25 16:44:39 -0800 |
commit | 000439e85de9a1163d9bdbc1773e98bb4357a50f (patch) | |
tree | ec1dddd2380c743c0ae9feaf87ff3a93cedd37b7 | |
parent | 586207ebf0872d3116b7066d1d1808b0fa9588d4 (diff) | |
download | cdlog-000439e85de9a1163d9bdbc1773e98bb4357a50f.tar.gz cdlog-000439e85de9a1163d9bdbc1773e98bb4357a50f.tar.bz2 cdlog-000439e85de9a1163d9bdbc1773e98bb4357a50f.zip |
New: mcd, mcs: menu-based cd and cs.
* cdlog.sh (cdlog.mcd): New function.
(mcd, mcs): New aliases.
* README.md: Documented.
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | cdlog.sh | 37 |
2 files changed, 43 insertions, 0 deletions
@@ -36,6 +36,12 @@ most recent directory becomes most recent and so on. * `cdlog` function shows a listing of the four most recent entries in the log. The `cl` command is an alias for this. +* The `mcd` and `mcs` are menu-selection-based analogs of `cd` and `mcs`. +They print the contents of the FIFO (all nine entries), and you can +pick which directory to change to or swap with. The terminal cursor is then +retraced back to the top of the menu, and the screen is erased from +that point to the bottom. + In addition, the `cdlog.sh` script sets the bash `direxpand` option. With the `direxpand` option, Tab completion on a directory coming from a variable name will expand that variable into the command line. @@ -113,6 +113,41 @@ cdlog() printf "3: %s\n" "$c3" printf "4: %s\n" "$c4" } + +# Menu-based cd/cs. +cdlog.mcd() +{ + local sel= + local swap= + local res=1 + local d=("" "$c1" "$c2" "$c3" "$c4" "$c5" "$c6" "$c7" "$c8" "$c9") + + if [ $# -gt 0 ] && [ "$1" = -s ] ; then + swap=y + fi + + for x in 1 2 3 4 5 6 7 8 9; do + printf "%s: %s\n" $x "${d[$x]}" + done + + read -p "? " sel + + printf "\e[10A\e[J" + + case "$sel" in + ( [1-9] ) + if [ $swap ] ; then + cdlog.rot $sel + else + if cdlog.chdir -P "${d[$sel]}" ; then + printf "%s\n" "$PWD" + fi + fi + res=$? + ;; + esac + + return $res } # Aliases. @@ -120,6 +155,8 @@ alias cd='cdlog.chdir -P' alias pd='cdlog.pop' alias cs='cdlog.rot' alias cl='cdlog' +alias mcd='cdlog.mcd' +alias mcs='cdlog.mcd -s' # Better completion for $x[Tab] shopt -s direxpand |