aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-01-25 16:44:39 -0800
committerKaz Kylheku <kaz@kylheku.com>2024-01-25 16:44:39 -0800
commit000439e85de9a1163d9bdbc1773e98bb4357a50f (patch)
treeec1dddd2380c743c0ae9feaf87ff3a93cedd37b7
parent586207ebf0872d3116b7066d1d1808b0fa9588d4 (diff)
downloadcdlog-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.md6
-rw-r--r--cdlog.sh37
2 files changed, 43 insertions, 0 deletions
diff --git a/README.md b/README.md
index d677d3c..f3d4f3b 100644
--- a/README.md
+++ b/README.md
@@ -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.
diff --git a/cdlog.sh b/cdlog.sh
index cf60345..c7d81fb 100644
--- a/cdlog.sh
+++ b/cdlog.sh
@@ -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