From 94be3faf70adf727be17bae416d6a13217097b86 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 8 Feb 2024 20:18:20 -0800 Subject: Implement context cloning. The user can copy a given context into the newly allocated one, rather than switch to a given context. * cdlog.sh (cdlog.init): Allow the user to input a context number prefixed by c. In that case, we copy the specified context file into the $cdlog_dirs file, leaving that variable alone. --- cdlog.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cdlog.sh b/cdlog.sh index c909d65..99c3338 100644 --- a/cdlog.sh +++ b/cdlog.sh @@ -84,14 +84,19 @@ cdlog.init() if [ $# -gt 0 -a $1 != ~/.cdlog.'*'.dirs ] ; then printf "These cdlog contexts exist:\n" - i=1 + i=0 for dir in "$@"; do - printf "[%d]: %s\n" $((i++)) "$(date -r "$dir")" + printf "[%d]: %s\n" $((++i)) "$(date -r "$dir")" sed -e '/^$/d' "$dir" done while true; do - printf "Make a selection or press Enter for new context: " + if [ $i -eq 1 ] ; then + printf "Use 1 to select context, c1 to clone,\n" + else + printf "Use 1-%s to select context, c1-c%s to clone,\n" $i $i + fi + printf "or Enter for new blank ontext: " read sel case $sel in ( [1-9] ) @@ -101,6 +106,13 @@ cdlog.init() break fi ;; + ( c[1-9] ) + sel=$(cdlog.get_param ${sel#c} "$@") + if [ -n "$sel" ] ; then + cp "$sel" "$cdlog_dirs" + break + fi + ;; ( "" ) break ;; -- cgit v1.2.3