diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-02-08 20:18:20 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-02-08 20:18:20 -0800 |
commit | 94be3faf70adf727be17bae416d6a13217097b86 (patch) | |
tree | 2da03ccf34ad4b158565684bb6adc4072d908564 | |
parent | dbfbebee76ad3e58ef472b2da8acd98b461857a4 (diff) | |
download | cdlog-94be3faf70adf727be17bae416d6a13217097b86.tar.gz cdlog-94be3faf70adf727be17bae416d6a13217097b86.tar.bz2 cdlog-94be3faf70adf727be17bae416d6a13217097b86.zip |
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.
-rw-r--r-- | cdlog.sh | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -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 ;; |