aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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