Compare commits
	
		
			14 Commits
		
	
	
		
			f663c200d2
			...
			main
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 1f15d53c32 | |||
| ded6a686fd | |||
| 7545a4229c | |||
| 93cb0852ea | |||
| 75acdc87f3 | |||
| 56030912d7 | |||
| b2c8d94854 | |||
| c916f46c64 | |||
| cffd89eefd | |||
| 29214c6fe5 | |||
| e0a3905a72 | |||
| 82377a4d5c | |||
| 4027366a63 | |||
| 5f05bc2e0f | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1 +1,2 @@
 | 
			
		||||
fzf-vjour
 | 
			
		||||
demo/
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										19
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								README.md
									
									
									
									
									
								
							@@ -11,6 +11,12 @@ These entries are stored as [iCalendar](https://datatracker.ietf.org/doc/html/rf
 | 
			
		||||
For instance, you could use this application as a terminal-based counterpart of [jtx Board](https://jtx.techbee.at/) in a setup
 | 
			
		||||
with a CalDav server, such as [Radicale](https://radicale.org/), and a synchronization tool like [vdirsyncer](http://vdirsyncer.pimutils.org/).
 | 
			
		||||
 | 
			
		||||
Demo
 | 
			
		||||
----
 | 
			
		||||
Run the script `./scripts/generate_demo.sh` to generate a demo.
 | 
			
		||||
 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
Installation
 | 
			
		||||
------------
 | 
			
		||||
 | 
			
		||||
@@ -72,6 +78,9 @@ item_types = ["VJOURNAL", "VTODO"]
 | 
			
		||||
 | 
			
		||||
You may also specify the location of the configuration file with the environment `CONFIGFILE`.
 | 
			
		||||
 | 
			
		||||
By default, `fzf-vjour` sets a descriptive terminal title.
 | 
			
		||||
This can be bypassed by specyfing `SET_TERMINAL_TITLE="no"` in the configuration file.
 | 
			
		||||
 | 
			
		||||
Usage
 | 
			
		||||
-----
 | 
			
		||||
Use the default `fzf` keys to navigate your notes, e.g., `ctrl-j` and `ctrl-k` for going down/up in the list.
 | 
			
		||||
@@ -90,9 +99,13 @@ 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 |
 | 
			
		||||
| `alt-w` | Toggle line-wrap in preview |
 | 
			
		||||
| `ctrl-d` | Scroll down in preview |
 | 
			
		||||
| `ctrl-u` | Scroll up in preview |
 | 
			
		||||
 | 
			
		||||
You may also invoke the script with `--help` to see further command-line options. 
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								demo/screenshot.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								demo/screenshot.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 78 KiB  | 
							
								
								
									
										58
									
								
								scripts/generate_demo.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										58
									
								
								scripts/generate_demo.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
 | 
			
		||||
set -eu
 | 
			
		||||
 | 
			
		||||
BOLD="\033[1m"
 | 
			
		||||
GREEN="\033[0;32m"
 | 
			
		||||
OFF="\033[m"
 | 
			
		||||
DEMO="demo"
 | 
			
		||||
FVJ="./fzf-vjour"
 | 
			
		||||
ROOT="$DEMO/journal/"
 | 
			
		||||
COLLECTION_LABELS="745ae7a0-d723-4cd8-80c4-75f52f5b7d90=shared 👫🏼;12cacb18-d3e1-4ad4-a1d0-e5b209012e85=work   💼;"
 | 
			
		||||
 | 
			
		||||
export CONFIGFILE="$DEMO/config"
 | 
			
		||||
rm -rf "$ROOT"
 | 
			
		||||
collection1="$(printf "%s" "$COLLECTION_LABELS" | cut -d ";" -f 1 | cut -d "=" -f 1)"
 | 
			
		||||
collection2="$(printf "%s" "$COLLECTION_LABELS" | cut -d ";" -f 2 | cut -d "=" -f 1)"
 | 
			
		||||
mkdir -p "$ROOT/$collection1"
 | 
			
		||||
mkdir -p "$ROOT/$collection2"
 | 
			
		||||
cat <<EOF >"$CONFIGFILE"
 | 
			
		||||
ROOT="$ROOT"
 | 
			
		||||
COLLECTION_LABELS="$COLLECTION_LABELS"
 | 
			
		||||
EOF
 | 
			
		||||
echo "⚙️ ${BOLD}${GREEN}Building demo$OFF"
 | 
			
		||||
## Fill in data
 | 
			
		||||
cal 2028 | $FVJ --add-note "2028 will be a leap year"
 | 
			
		||||
$FVJ --add-task "Finish proof of admissibility theorem" "tomorrow" --collection 2
 | 
			
		||||
cat <<EOF | $FVJ --add-task "Respond to referee report" "yesterday" --collection 2
 | 
			
		||||
- [x] Report 1: Answer prepared
 | 
			
		||||
- [ ] Report 2: Write response, revise manuscript
 | 
			
		||||
EOF
 | 
			
		||||
echo "Chinese" | $FVJ --add-task "Reserve dinner table" "next Sunday"
 | 
			
		||||
cat <<EOF | $FVJ --add-jour "Demo Coding"
 | 
			
		||||
### Demo code
 | 
			
		||||
Our demo now contains a script that self-generets the demo.
 | 
			
		||||
It's located in \`./scripts/\`
 | 
			
		||||
There are some upcoming steps:
 | 
			
		||||
 | 
			
		||||
1. Generate screenshot
 | 
			
		||||
2. Demonstrate attachment window
 | 
			
		||||
3. Extend code to handle timezones and alarms
 | 
			
		||||
EOF
 | 
			
		||||
cat <<EOF | $FVJ --add-note "Shopping list"
 | 
			
		||||
- [ ] Banana
 | 
			
		||||
- [ ] Bread
 | 
			
		||||
- [ ] Yoghurt
 | 
			
		||||
EOF
 | 
			
		||||
cat <<EOF | $FVJ --add-jour "Today's code" --collection 2
 | 
			
		||||
# Source code of current program
 | 
			
		||||
 | 
			
		||||
\`\`\`sh
 | 
			
		||||
$(cat "$0")
 | 
			
		||||
\`\`\`
 | 
			
		||||
EOF
 | 
			
		||||
$FVJ --add-task "Look for typos in readme" --collection 2 <"README.md"
 | 
			
		||||
## End of data
 | 
			
		||||
echo "🚀 ${BOLD}${GREEN}DONE.$OFF"
 | 
			
		||||
echo ""
 | 
			
		||||
echo "${GREEN}Run '${OFF}CONFIGFILE=$CONFIGFILE $FVJ$GREEN' to start demo$OFF"
 | 
			
		||||
							
								
								
									
										137
									
								
								src/main.sh
									
									
									
									
									
								
							
							
						
						
									
										137
									
								
								src/main.sh
									
									
									
									
									
								
							@@ -2,20 +2,30 @@
 | 
			
		||||
 | 
			
		||||
set -eu
 | 
			
		||||
 | 
			
		||||
# Always load functions
 | 
			
		||||
# Helper functions
 | 
			
		||||
. "sh/helper.sh"
 | 
			
		||||
# iCalendar routines
 | 
			
		||||
. "sh/icalendar.sh"
 | 
			
		||||
# Attachment handling
 | 
			
		||||
. "sh/attachment.sh"
 | 
			
		||||
# Categories handling
 | 
			
		||||
. "sh/categories.sh"
 | 
			
		||||
 | 
			
		||||
# Read theme
 | 
			
		||||
. "sh/theme.sh"
 | 
			
		||||
 | 
			
		||||
# Read configuration
 | 
			
		||||
. "sh/config.sh"
 | 
			
		||||
 | 
			
		||||
# Load awk scripts
 | 
			
		||||
. "sh/awkscripts.sh"
 | 
			
		||||
# Load environment variables only when not yet loaded
 | 
			
		||||
if [ ! "${SCRIPT_LOADED:-}" ]; then
 | 
			
		||||
  # Read configuration
 | 
			
		||||
  . "sh/config.sh"
 | 
			
		||||
  # Read theme
 | 
			
		||||
  . "sh/theme.sh"
 | 
			
		||||
  # Load awk scripts
 | 
			
		||||
  . "sh/awkscripts.sh"
 | 
			
		||||
  # Mark as loaded
 | 
			
		||||
  export SCRIPT_LOADED=1
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
__lines() {
 | 
			
		||||
  find "$ROOT" -type f -name '*.ics' -print0 | xargs -0 -P 0 \
 | 
			
		||||
  find "$ROOT" -mindepth 2 -maxdepth 2 -type f -name '*.ics' -print0 | xargs -0 -P 0 \
 | 
			
		||||
    awk \
 | 
			
		||||
    -v collection_labels="$COLLECTION_LABELS" \
 | 
			
		||||
    -v flag_open="$FLAG_OPEN" \
 | 
			
		||||
@@ -35,12 +45,34 @@ __lines() {
 | 
			
		||||
 | 
			
		||||
# Program starts here
 | 
			
		||||
if [ "${1:-}" = "--help" ]; then
 | 
			
		||||
  bn="$(basename "$0")"
 | 
			
		||||
  shift
 | 
			
		||||
  echo "Usage: $0 [--help | --new [FILTER..] | [FILTER..] ]
 | 
			
		||||
  --help                 Show this help and exit
 | 
			
		||||
  --new                  Create new entry and do not exit
 | 
			
		||||
  --git-init             Activate git usage and exit
 | 
			
		||||
  --git <cmd>            Run git command and exit
 | 
			
		||||
  echo "Usage: $bn [OPTION] [FILTER]...
 | 
			
		||||
 | 
			
		||||
[OPTION]
 | 
			
		||||
    --help                        Show this help and exit
 | 
			
		||||
 | 
			
		||||
  Git Integration:
 | 
			
		||||
    --git-init                    Activate git usage and exit
 | 
			
		||||
    --git <cmd>                   Run git command and exit
 | 
			
		||||
 | 
			
		||||
  Interactive Mode:
 | 
			
		||||
    --new [FILTER..]              Create new entry interactively and start
 | 
			
		||||
    [FILTER..]                    Start with the specified filter
 | 
			
		||||
 | 
			
		||||
  Non-Interactive Mode:
 | 
			
		||||
    --list [FILTER..]             List entries and exit
 | 
			
		||||
    --add-note <summary>          Read note from stdin and add it with the
 | 
			
		||||
                                  specified summary
 | 
			
		||||
    --add-task <summary> [<due>]  Read task from stdin and add it with the
 | 
			
		||||
                                  specified summary and optional due date
 | 
			
		||||
    --add-jour <summary>          Read journal from stdin and add it with the
 | 
			
		||||
                                  specified summary
 | 
			
		||||
    --collection <nr>             Select collection to which the note, task, or
 | 
			
		||||
                                  journal entry is added non-interactively. The
 | 
			
		||||
                                  argument <nr> is the ordinal describing the
 | 
			
		||||
                                  collection. It defaults to the starting value
 | 
			
		||||
                                  of 1.
 | 
			
		||||
 | 
			
		||||
[FILTER]
 | 
			
		||||
  You may specify any of these filters. Filters can be negated using the
 | 
			
		||||
@@ -49,34 +81,54 @@ if [ "${1:-}" = "--help" ]; then
 | 
			
		||||
  --no-completed is not the same as --open, and similarly, --no-open is not the
 | 
			
		||||
  same as --completed.
 | 
			
		||||
 | 
			
		||||
  --tasks                 Show tasks only
 | 
			
		||||
  --notes                 Show notes only
 | 
			
		||||
  --journal               Show jounral only
 | 
			
		||||
  --completed             Show completed tasks only
 | 
			
		||||
  --open                  Show open tasks only
 | 
			
		||||
  --filter <query>        Specify custom query"
 | 
			
		||||
  --tasks                         Show tasks only
 | 
			
		||||
  --notes                         Show notes only
 | 
			
		||||
  --journal                       Show journal only
 | 
			
		||||
  --completed                     Show completed tasks only
 | 
			
		||||
  --open                          Show open tasks only
 | 
			
		||||
  --filter <query>                Specify custom query
 | 
			
		||||
 | 
			
		||||
Examples:
 | 
			
		||||
  $bn --git log
 | 
			
		||||
  $bn --new
 | 
			
		||||
  $bn --journal
 | 
			
		||||
  $bn --no-tasks --filter \"Beauregard\"
 | 
			
		||||
  $bn --list --open
 | 
			
		||||
  $bn --add-task \"Improve code to respect timezone information\" \"next month\"
 | 
			
		||||
  cat proof.tex | $bn --add-journal \"Proof of Fixed-point Theorem\" --collection 2
 | 
			
		||||
"
 | 
			
		||||
  exit
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# iCalendar routines
 | 
			
		||||
. "sh/icalendar.sh"
 | 
			
		||||
 | 
			
		||||
# Command line arguments: Interal use
 | 
			
		||||
. "sh/cliinternal.sh"
 | 
			
		||||
 | 
			
		||||
# Command line arguments: Interal use
 | 
			
		||||
# Command line arguments
 | 
			
		||||
. "sh/cli.sh"
 | 
			
		||||
 | 
			
		||||
# Attachment handling
 | 
			
		||||
. "sh/attachment.sh"
 | 
			
		||||
# Parse command-line filter (if any)
 | 
			
		||||
. "sh/filter.sh"
 | 
			
		||||
 | 
			
		||||
# Categories handling
 | 
			
		||||
. "sh/categories.sh"
 | 
			
		||||
if [ -n "${list_option:-}" ]; then
 | 
			
		||||
  __lines |
 | 
			
		||||
    $FZF \
 | 
			
		||||
      --filter="$query" \
 | 
			
		||||
      --no-sort \
 | 
			
		||||
      --with-nth=5.. |
 | 
			
		||||
    tac
 | 
			
		||||
  exit 0
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Set terminal title
 | 
			
		||||
if [ "$SET_TERMINAL_TITLE" = "yes" ]; then
 | 
			
		||||
  printf '\033]0;%s\007' "$TERMINAL_TITLE"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
while true; do
 | 
			
		||||
  query=$(stripws "$query")
 | 
			
		||||
  selection=$(
 | 
			
		||||
    __lines | $FZF --ansi \
 | 
			
		||||
    __lines | $FZF \
 | 
			
		||||
      --ansi \
 | 
			
		||||
      --query="$query " \
 | 
			
		||||
      --no-sort \
 | 
			
		||||
      --no-hscroll \
 | 
			
		||||
@@ -89,12 +141,24 @@ 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 <enter> to continue.'; read -r tmp)" ||
 | 
			
		||||
      --bind="alt-w:toggle-preview-wrap" \
 | 
			
		||||
      --bind="ctrl-d:preview-half-page-down" \
 | 
			
		||||
      --bind="ctrl-u:preview-half-page-up" \
 | 
			
		||||
      --bind="ctrl-s:execute($SYNC_CMD; [ -n \"${GIT:-}\" ] && ${GIT:-echo} add -A && ${GIT:-echo} commit -am 'Synchronized'; printf 'Press <enter> to continue.'; read -r tmp)" ||
 | 
			
		||||
      true
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
@@ -103,7 +167,7 @@ while true; do
 | 
			
		||||
  # Line 3: relative file path
 | 
			
		||||
  lines=$(echo "$selection" | wc -l)
 | 
			
		||||
  if [ "$lines" -eq 1 ]; then
 | 
			
		||||
    return 0
 | 
			
		||||
    exit 0
 | 
			
		||||
  fi
 | 
			
		||||
  query=$(echo "$selection" | head -n 1)
 | 
			
		||||
  key=$(echo "$selection" | head -n 2 | tail -n 1)
 | 
			
		||||
@@ -124,7 +188,8 @@ while true; do
 | 
			
		||||
    __attachment_view "$file"
 | 
			
		||||
    ;;
 | 
			
		||||
  "ctrl-t")
 | 
			
		||||
    query="'$(__select_category)'"
 | 
			
		||||
    cat="$(__select_category)"
 | 
			
		||||
    [ -n "$cat" ] && query="'$cat'"
 | 
			
		||||
    ;;
 | 
			
		||||
  "")
 | 
			
		||||
    __edit "$file"
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,9 @@ __add_attachment() {
 | 
			
		||||
  file="$1"
 | 
			
		||||
  shift
 | 
			
		||||
  sel=$(
 | 
			
		||||
    $FZF --prompt="Select attachment> " \
 | 
			
		||||
    $FZF \
 | 
			
		||||
      --ansi \
 | 
			
		||||
      --prompt="Select attachment> " \
 | 
			
		||||
      --walker="file,hidden" \
 | 
			
		||||
      --walker-root="$HOME" \
 | 
			
		||||
      --expect="ctrl-c,ctrl-g,ctrl-q,esc"
 | 
			
		||||
@@ -137,6 +139,7 @@ __attachment_view() {
 | 
			
		||||
  att=$(
 | 
			
		||||
    awk "$AWK_ATTACHLS" "$file" |
 | 
			
		||||
      $FZF \
 | 
			
		||||
        --ansi \
 | 
			
		||||
        --delimiter="\t" \
 | 
			
		||||
        --accept-nth=1,2,3,4 \
 | 
			
		||||
        --with-nth="Attachment {1}: \"{2}\" {3} ({5})" \
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,9 @@ __select_category() {
 | 
			
		||||
    sort |
 | 
			
		||||
    uniq |
 | 
			
		||||
    grep '.' |
 | 
			
		||||
    $FZF --prompt="Select category> " \
 | 
			
		||||
    $FZF \
 | 
			
		||||
      --ansi \
 | 
			
		||||
      --prompt="Select category> " \
 | 
			
		||||
      --no-sort \
 | 
			
		||||
      --tac \
 | 
			
		||||
      --margin="30%,30%" \
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										164
									
								
								src/sh/cli.sh
									
									
									
									
									
								
							
							
						
						
									
										164
									
								
								src/sh/cli.sh
									
									
									
									
									
								
							@@ -1,5 +1,5 @@
 | 
			
		||||
# Git
 | 
			
		||||
if [ "${1:-}" = "--git-init" ]; then
 | 
			
		||||
case "${1:-}" in
 | 
			
		||||
"--git-init")
 | 
			
		||||
  shift
 | 
			
		||||
  if [ -n "${GIT:-}" ]; then
 | 
			
		||||
    err "Git already enabled"
 | 
			
		||||
@@ -13,9 +13,8 @@ if [ "${1:-}" = "--git-init" ]; then
 | 
			
		||||
  git -C "$ROOT" add -A
 | 
			
		||||
  git -C "$ROOT" commit -m 'Initial commit: Start git tracking'
 | 
			
		||||
  exit
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if [ "${1:-}" = "--git" ]; then
 | 
			
		||||
  ;;
 | 
			
		||||
"--git")
 | 
			
		||||
  shift
 | 
			
		||||
  if [ -z "${GIT:-}" ]; then
 | 
			
		||||
    err "Git not supported, run \`$0 --git-init\` first"
 | 
			
		||||
@@ -23,72 +22,101 @@ if [ "${1:-}" = "--git" ]; then
 | 
			
		||||
  fi
 | 
			
		||||
  $GIT "$@"
 | 
			
		||||
  exit
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Generate new entry
 | 
			
		||||
if [ "${1:-}" = "--new" ]; then
 | 
			
		||||
  ;;
 | 
			
		||||
"--new")
 | 
			
		||||
  shift
 | 
			
		||||
  __new
 | 
			
		||||
fi
 | 
			
		||||
  export next_filter=1
 | 
			
		||||
  ;;
 | 
			
		||||
"--list")
 | 
			
		||||
  shift
 | 
			
		||||
  export next_filter=1
 | 
			
		||||
  export list_option=1
 | 
			
		||||
  ;;
 | 
			
		||||
esac
 | 
			
		||||
 | 
			
		||||
# Build query
 | 
			
		||||
while [ -n "${1:-}" ]; do
 | 
			
		||||
if [ -z "${next_filter:-}" ]; then
 | 
			
		||||
  # else [FILTER] are the next options
 | 
			
		||||
  # Here, we have --add-xyz with --collection or nothign
 | 
			
		||||
  case "${1:-}" in
 | 
			
		||||
  "--completed")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $FLAG_COMPLETED"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-completed")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$FLAG_COMPLETED"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--open")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $FLAG_OPEN"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-open")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$FLAG_OPEN"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--tasks")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $FLAG_OPEN | $FLAG_COMPLETED"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-tasks")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$FLAG_COMPLETED !$FLAG_OPEN"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--notes")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $FLAG_NOTE"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-notes")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$FLAG_NOTE"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--journal")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $FLAG_JOURNAL"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-journal")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$FLAG_JOURNAL"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--filter")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $1"
 | 
			
		||||
    shift
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-filter")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$1"
 | 
			
		||||
    shift
 | 
			
		||||
    ;;
 | 
			
		||||
  *)
 | 
			
		||||
    err "Unknown option \"$1\""
 | 
			
		||||
    exit 1
 | 
			
		||||
  "--add-note" | "--add-task" | "--add-jour" | "--collection")
 | 
			
		||||
    noninteractive=1
 | 
			
		||||
    ;;
 | 
			
		||||
  esac
 | 
			
		||||
done
 | 
			
		||||
query=${cliquery:-!$FLAG_COMPLETED}
 | 
			
		||||
export query
 | 
			
		||||
  if [ -n "${noninteractive:-}" ]; then
 | 
			
		||||
    while [ -n "${1:-}" ]; do
 | 
			
		||||
      case "$1" in
 | 
			
		||||
      "--add-note" | "--add-task" | "--add-jour")
 | 
			
		||||
        if [ -n "${add_option:-}" ]; then
 | 
			
		||||
          err "What do you want to add?"
 | 
			
		||||
          exit 1
 | 
			
		||||
        fi
 | 
			
		||||
        add_option="$1"
 | 
			
		||||
        shift
 | 
			
		||||
        summary=${1-}
 | 
			
		||||
        if [ -z "$summary" ]; then
 | 
			
		||||
          err "You did not give a summary"
 | 
			
		||||
          exit 1
 | 
			
		||||
        fi
 | 
			
		||||
        shift
 | 
			
		||||
        if [ "$add_option" = "--add-task" ] && [ -n "${1:-}" ]; then
 | 
			
		||||
          case "$1" in
 | 
			
		||||
          "--"*)
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
          *)
 | 
			
		||||
            due=$(printf "%s" "$1" | tr -dc "[:alnum:][:blank:]")
 | 
			
		||||
            shift
 | 
			
		||||
            if [ -z "$due" ] || ! date -d "$due" >/dev/null 2>&1; then
 | 
			
		||||
              err "Invalid due date"
 | 
			
		||||
              exit 1
 | 
			
		||||
            fi
 | 
			
		||||
            ;;
 | 
			
		||||
          esac
 | 
			
		||||
        fi
 | 
			
		||||
        ;;
 | 
			
		||||
      "--collection")
 | 
			
		||||
        shift
 | 
			
		||||
        collection="$(printf "%s" "$COLLECTION_LABELS" |
 | 
			
		||||
          cut -d ";" -f "${1:-}" 2>/dev/null |
 | 
			
		||||
          cut -d "=" -f 1 2>/dev/null)"
 | 
			
		||||
        if [ -z "$collection" ]; then
 | 
			
		||||
          err "Invalid collection"
 | 
			
		||||
          exit 1
 | 
			
		||||
        fi
 | 
			
		||||
        shift
 | 
			
		||||
        ;;
 | 
			
		||||
      *)
 | 
			
		||||
        err "Unknown non-interactive option: $1"
 | 
			
		||||
        exit 1
 | 
			
		||||
        ;;
 | 
			
		||||
      esac
 | 
			
		||||
    done
 | 
			
		||||
  fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if [ -n "${noninteractive:-}" ]; then
 | 
			
		||||
  if [ -z "${add_option:-}" ]; then
 | 
			
		||||
    err "Specified collection, but nothing to add"
 | 
			
		||||
    exit 1
 | 
			
		||||
  fi
 | 
			
		||||
  if [ -z "${collection:-}" ]; then
 | 
			
		||||
    collection="$(
 | 
			
		||||
      printf "%s" "$COLLECTION_LABELS" |
 | 
			
		||||
        cut -d ";" -f 1 |
 | 
			
		||||
        cut -d "=" -f 1
 | 
			
		||||
    )"
 | 
			
		||||
  fi
 | 
			
		||||
  case "$add_option" in
 | 
			
		||||
  "--add-note")
 | 
			
		||||
    __add_note "$collection" "$summary"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--add-task")
 | 
			
		||||
    __add_task "$collection" "$summary" "${due:-}"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--add-jour")
 | 
			
		||||
    __add_jour "$collection" "$summary"
 | 
			
		||||
    ;;
 | 
			
		||||
  esac
 | 
			
		||||
  exit 0
 | 
			
		||||
fi
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
CONFIGFILE="${CONFIGFILE:-$HOME/.config/fzf-vjour/config}"
 | 
			
		||||
export TERMINAL_TITLE="🗃️ fzf-vjour | Journal, notes, and tasks"
 | 
			
		||||
if [ ! -f "$CONFIGFILE" ]; then
 | 
			
		||||
  err "Configuration '$CONFIGFILE' not found."
 | 
			
		||||
  exit 1
 | 
			
		||||
@@ -6,17 +7,36 @@ fi
 | 
			
		||||
# shellcheck source=/dev/null
 | 
			
		||||
. "$CONFIGFILE"
 | 
			
		||||
if [ -z "${ROOT:-}" ] || [ -z "${COLLECTION_LABELS:-}" ]; then
 | 
			
		||||
  err "Configuration is incomplete."
 | 
			
		||||
  err "Configuration '$CONFIGFILE' is incomplete."
 | 
			
		||||
  exit 1
 | 
			
		||||
fi
 | 
			
		||||
if [ ! -d "$ROOT" ]; then
 | 
			
		||||
  err "Directory '$ROOT' does not exist."
 | 
			
		||||
  exit 1
 | 
			
		||||
fi
 | 
			
		||||
SYNC_CMD="${SYNC_CMD:-}"
 | 
			
		||||
SET_TERMINAL_TITLE="${SET_TERMINAL_TITLE:-yes}"
 | 
			
		||||
export ROOT
 | 
			
		||||
export SYNC_CMD
 | 
			
		||||
export COLLECTION_LABELS
 | 
			
		||||
export SET_TERMINAL_TITLE
 | 
			
		||||
for i in $(seq 9); do
 | 
			
		||||
  collection=$(printf "%s" "$COLLECTION_LABELS" | cut -d ';' -f "$i" | cut -d '=' -f 1)
 | 
			
		||||
  label=$(printf "%s" "$COLLECTION_LABELS" | cut -d ';' -f "$i" | cut -d '=' -f 2)
 | 
			
		||||
  if [ -n "$label" ] && [ ! -d "$ROOT/$collection" ]; then
 | 
			
		||||
    err "Collection directory for '$label' does not exist."
 | 
			
		||||
    exit 1
 | 
			
		||||
  fi
 | 
			
		||||
  if [ -z "$label" ]; then
 | 
			
		||||
    export COLLECTION_COUNT=$((i - 1))
 | 
			
		||||
    break
 | 
			
		||||
  fi
 | 
			
		||||
  export "COLLECTION$i=$label"
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# Tools
 | 
			
		||||
if command -v "fzf" >/dev/null; then
 | 
			
		||||
  FZF="fzf"
 | 
			
		||||
  FZF="fzf --black"
 | 
			
		||||
else
 | 
			
		||||
  err "Did not find the command-line fuzzy finder fzf."
 | 
			
		||||
  exit 1
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										61
									
								
								src/sh/filter.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								src/sh/filter.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
# Build query
 | 
			
		||||
while [ -n "${1:-}" ]; do
 | 
			
		||||
  case "${1:-}" in
 | 
			
		||||
  "--completed")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $FLAG_COMPLETED"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-completed")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$FLAG_COMPLETED"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--open")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $FLAG_OPEN"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-open")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$FLAG_OPEN"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--tasks")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $FLAG_OPEN | $FLAG_COMPLETED"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-tasks")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$FLAG_COMPLETED !$FLAG_OPEN"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--notes")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $FLAG_NOTE"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-notes")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$FLAG_NOTE"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--journal")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $FLAG_JOURNAL"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-journal")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$FLAG_JOURNAL"
 | 
			
		||||
    ;;
 | 
			
		||||
  "--filter")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} $1"
 | 
			
		||||
    shift
 | 
			
		||||
    ;;
 | 
			
		||||
  "--no-filter")
 | 
			
		||||
    shift
 | 
			
		||||
    cliquery="${cliquery:-} !$1"
 | 
			
		||||
    shift
 | 
			
		||||
    ;;
 | 
			
		||||
  *)
 | 
			
		||||
    err "Unknown option \"$1\""
 | 
			
		||||
    exit 1
 | 
			
		||||
    ;;
 | 
			
		||||
  esac
 | 
			
		||||
done
 | 
			
		||||
query=${cliquery:-!$FLAG_COMPLETED}
 | 
			
		||||
export query
 | 
			
		||||
@@ -1,5 +1,100 @@
 | 
			
		||||
# Interface to modify iCalendar files
 | 
			
		||||
 | 
			
		||||
# Wrapper to add entry from markdown file
 | 
			
		||||
#
 | 
			
		||||
# @input $1: path to markdown file
 | 
			
		||||
# @input $2: collection to add to
 | 
			
		||||
__add_from_md() {
 | 
			
		||||
  tmpmd="$1"
 | 
			
		||||
  shift
 | 
			
		||||
  collection="$1"
 | 
			
		||||
  shift
 | 
			
		||||
  file=""
 | 
			
		||||
  while [ -f "$file" ] || [ -z "$file" ]; do
 | 
			
		||||
    uuid=$($UUIDGEN)
 | 
			
		||||
    file="$ROOT/$collection/$uuid.ics"
 | 
			
		||||
  done
 | 
			
		||||
  tmpfile="$tmpmd.ics"
 | 
			
		||||
  if awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"; then
 | 
			
		||||
    if [ ! -d "$ROOT/$collection" ]; then
 | 
			
		||||
      mkdir -p "$ROOT/$collection"
 | 
			
		||||
    fi
 | 
			
		||||
    mv "$tmpfile" "$file"
 | 
			
		||||
    if [ -n "${GIT:-}" ]; then
 | 
			
		||||
      $GIT add "$file"
 | 
			
		||||
      $GIT commit -q -m "File added" -- "$file"
 | 
			
		||||
    fi
 | 
			
		||||
  else
 | 
			
		||||
    rm -f "$tmpfile"
 | 
			
		||||
    err "Failed to create new entry."
 | 
			
		||||
  fi
 | 
			
		||||
  rm "$tmpmd"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Noninteractively add note, and fill description from stdin
 | 
			
		||||
#
 | 
			
		||||
# @input $1: Collection
 | 
			
		||||
# @input $2: Summary
 | 
			
		||||
__add_note() {
 | 
			
		||||
  collection="$1"
 | 
			
		||||
  shift
 | 
			
		||||
  summary="$1"
 | 
			
		||||
  shift
 | 
			
		||||
  tmpmd=$(mktemp --suffix='.md')
 | 
			
		||||
  {
 | 
			
		||||
    echo "# $summary"
 | 
			
		||||
    echo ""
 | 
			
		||||
  } >"$tmpmd"
 | 
			
		||||
  if [ ! -t 0 ]; then
 | 
			
		||||
    cat /dev/stdin >>"$tmpmd"
 | 
			
		||||
  fi
 | 
			
		||||
  __add_from_md "$tmpmd" "$collection"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Noninteractively add task, and fill description from stdin
 | 
			
		||||
#
 | 
			
		||||
# @input $1: Collection
 | 
			
		||||
# @input $2: Summary
 | 
			
		||||
# @input $3: Due date (optional)
 | 
			
		||||
__add_task() {
 | 
			
		||||
  collection="$1"
 | 
			
		||||
  shift
 | 
			
		||||
  summary="$1"
 | 
			
		||||
  shift
 | 
			
		||||
  due="${1:-}"
 | 
			
		||||
  tmpmd=$(mktemp --suffix='.md')
 | 
			
		||||
  {
 | 
			
		||||
    echo "::: <| $due"
 | 
			
		||||
    echo "# $summary"
 | 
			
		||||
    echo ""
 | 
			
		||||
  } >"$tmpmd"
 | 
			
		||||
  if [ ! -t 0 ]; then
 | 
			
		||||
    cat /dev/stdin >>"$tmpmd"
 | 
			
		||||
  fi
 | 
			
		||||
  __add_from_md "$tmpmd" "$collection"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Noninteractively add jounral, and fill description from stdin
 | 
			
		||||
#
 | 
			
		||||
# @input $1: Collection
 | 
			
		||||
# @input $2: Summary
 | 
			
		||||
__add_jour() {
 | 
			
		||||
  collection="$1"
 | 
			
		||||
  shift
 | 
			
		||||
  summary="$1"
 | 
			
		||||
  shift
 | 
			
		||||
  tmpmd=$(mktemp --suffix='.md')
 | 
			
		||||
  {
 | 
			
		||||
    echo "::: |> <!-- keep this line to associate the entry to _today_ -->"
 | 
			
		||||
    echo "# $summary"
 | 
			
		||||
    echo ""
 | 
			
		||||
  } >"$tmpmd"
 | 
			
		||||
  if [ ! -t 0 ]; then
 | 
			
		||||
    cat /dev/stdin >>"$tmpmd"
 | 
			
		||||
  fi
 | 
			
		||||
  __add_from_md "$tmpmd" "$collection"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Toggle completed status of VTODO
 | 
			
		||||
#
 | 
			
		||||
# @input $1: Relative path to iCalendar file
 | 
			
		||||
@@ -109,7 +204,23 @@ __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 \
 | 
			
		||||
      --ansi \
 | 
			
		||||
      --prompt="Choose collection> " \
 | 
			
		||||
      --select-1 \
 | 
			
		||||
      --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)
 | 
			
		||||
@@ -132,6 +243,9 @@ __new() {
 | 
			
		||||
  while [ "$checksum" != "$(cksum "$tmpmd")" ]; do
 | 
			
		||||
    tmpfile="$tmpmd.ics"
 | 
			
		||||
    if awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"; then
 | 
			
		||||
      if [ ! -d "$ROOT/$collection" ]; then
 | 
			
		||||
        mkdir -p "$ROOT/$collection"
 | 
			
		||||
      fi
 | 
			
		||||
      mv "$tmpfile" "$file"
 | 
			
		||||
      if [ -n "${GIT:-}" ]; then
 | 
			
		||||
        $GIT add "$file"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user