From 5f05bc2e0f937d8cf498fc9ba71f175ec5f41eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Fri, 4 Jul 2025 13:57:05 +0200 Subject: [PATCH] feat: keybindings for collections --- README.md | 7 ++++--- src/main.sh | 19 ++++++++++++++----- src/sh/config.sh | 8 ++++++++ src/sh/icalendar.sh | 16 +++++++++++++++- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 61edb63..be31729 100644 --- a/README.md +++ b/README.md @@ -90,9 +90,10 @@ In addition, there are the following keybindings: | `ctrl-t` | Filter by category | | `alt-v` | View bare iCalendar file | | `alt-0` | Default view: Journal, notes, and _open_ tasks | -| `alt-1` | Display journal entries | -| `alt-2` | Display notes | -| `alt-3` | Display all tasks | +| `alt-j` | Display journal entries | +| `alt-n` | Display notes | +| `alt-t` | Display all tasks | +| `alt-[1-9]` | Display first, second, ... collection | You may also invoke the script with `--help` to see further command-line options. diff --git a/src/main.sh b/src/main.sh index 5819dc1..06fa948 100644 --- a/src/main.sh +++ b/src/main.sh @@ -89,12 +89,21 @@ while true; do --bind="ctrl-x:reload($0 --reload --toggle-completed {4})" \ --bind="alt-up:reload($0 --reload --change-priority '+1' {4})" \ --bind="alt-down:reload($0 --reload --change-priority '-1' {4})" \ - --bind="alt-0:change-query(!✅)" \ - --bind="alt-1:change-query(📘)" \ - --bind="alt-2:change-query(🗒️)" \ - --bind="alt-3:change-query(✅ | 🔲)" \ + --bind="alt-0:change-query(!$FLAG_COMPLETED )" \ + --bind="alt-1:change-query(${COLLECTION1:-} )" \ + --bind="alt-2:change-query(${COLLECTION2:-} )" \ + --bind="alt-3:change-query(${COLLECTION3:-} )" \ + --bind="alt-4:change-query(${COLLECTION4:-} )" \ + --bind="alt-5:change-query(${COLLECTION5:-} )" \ + --bind="alt-6:change-query(${COLLECTION6:-} )" \ + --bind="alt-7:change-query(${COLLECTION7:-} )" \ + --bind="alt-8:change-query(${COLLECTION8:-} )" \ + --bind="alt-9:change-query(${COLLECTION9:-} )" \ + --bind="alt-j:change-query($FLAG_JOURNAL )" \ + --bind="alt-n:change-query($FLAG_NOTE )" \ + --bind="alt-t:change-query($FLAG_COMPLETED | $FLAG_OPEN )" \ --bind='focus:transform:[ {3} = "VTODO" ] && echo "rebind(ctrl-x)+rebind(alt-up)+rebind(alt-down)" || echo "unbind(ctrl-x)+unbind(alt-up)+unbind(alt-down)"' \ - --bind="ctrl-s:execute($SYNC_CMD; [ -n \"${GIT:-}\" ] && ${GIT:-echo} add -A; ${GIT:-echo} commit -am 'Synchronized'; printf 'Press to continue.'; read -r tmp)" || + --bind="ctrl-s:execute($SYNC_CMD; [ -n \"${GIT:-}\" ] && ${GIT:-echo} add -A && ${GIT:-echo} commit -am 'Synchronized'; printf 'Press to continue.'; read -r tmp)" || true ) diff --git a/src/sh/config.sh b/src/sh/config.sh index 0ad7ed6..88407ac 100644 --- a/src/sh/config.sh +++ b/src/sh/config.sh @@ -13,6 +13,14 @@ SYNC_CMD="${SYNC_CMD:-}" export ROOT export SYNC_CMD export COLLECTION_LABELS +for i in $(seq 9); do + label=$(printf "%s" "$COLLECTION_LABELS" | cut -d ';' -f "$i" | cut -d '=' -f 2) + if [ -z "$label" ]; then + export COLLECTION_COUNT=$((i - 1)) + break + fi + export "COLLECTION$i=$label" +done # Tools if command -v "fzf" >/dev/null; then diff --git a/src/sh/icalendar.sh b/src/sh/icalendar.sh index 51b28cc..9829624 100644 --- a/src/sh/icalendar.sh +++ b/src/sh/icalendar.sh @@ -109,7 +109,21 @@ __delete() { # Add file __new() { - collection=$(printf "%s" "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1) + collection=$(printf "%s" "$COLLECTION_LABELS" | + tr ';' '\n' | + $FZF \ + --prompt="Choose collection> " \ + --no-sort \ + --tac \ + --margin="30%,30%" \ + --delimiter='=' \ + --border=bold \ + --border-label="Collections" \ + --with-nth=2 \ + --accept-nth=1 || true) + if [ -z "$collection" ]; then + return + fi file="" while [ -f "$file" ] || [ -z "$file" ]; do uuid=$($UUIDGEN)