diff --git a/src/awk/get.awk b/src/awk/get.awk index a94864c..c2ddb6f 100644 --- a/src/awk/get.awk +++ b/src/awk/get.awk @@ -1,8 +1,11 @@ -# Retrieve content from iCalendar files +# Retrieve content from vCard files # # Mandatory variable: `field`. # Name of field to retrieve. # +# Optional variable: `prop`. +# If `prop` is set, then the property `prop` of `field` is printed. +# # Optional variable: `format`. # If `format` is set to "csv", then the content is interpreted as # comma-separated values, and empty values are dropped. @@ -15,16 +18,19 @@ # print content of field `field` BEGIN { FS = ":"; regex = "^" field; } -BEGINFILE { type = ""; line = ""; } -/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 } -/^END:/ && $2 == type { nextfile } +BEGINFILE { line = ""; } +/^BEGIN:VCARD/ { next } +/^END:VCARD/ { nextfile } $0 ~ regex { line = $0; next; } /^ / && line { line = line substr($0, 2); next; } /^[^ ]/ && line { nextfile } ENDFILE { - if (type) { + if (line) { # Process line - content = getcontent(line) + if (prop) + content = getparam(line, prop) + else + content = getcontent(line) if (oneline) content = singleline(content) switch (format) { diff --git a/src/main.sh b/src/main.sh index 62b7832..b7a4c99 100644 --- a/src/main.sh +++ b/src/main.sh @@ -142,6 +142,7 @@ while true; do --bind="alt-o:change-query($FLAG_ORGANIZATION )" \ --bind="alt-l:change-query($FLAG_LOCATION )" \ --bind="alt-w:toggle-preview-wrap" \ + --bind="/:toggle-preview" \ --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 to continue.'; read -r tmp)" || #--color='preview-bg:#ecc297,preview-fg:black' \ diff --git a/src/sh/cliinternal.sh b/src/sh/cliinternal.sh index ae93bf4..5e4675e 100644 --- a/src/sh/cliinternal.sh +++ b/src/sh/cliinternal.sh @@ -6,6 +6,7 @@ if [ "${1:-}" = "--preview" ]; then name="$1" shift file="$ROOT/$name" + # Get info awk \ -v label_tel_text="$LABEL_TEL_TEXT" \ -v label_tel_fax="$LABEL_TEL_FAX" \ @@ -18,6 +19,20 @@ if [ "${1:-}" = "--preview" ]; then -v label_home="$LABEL_HOME" \ "$AWK_PREVIEW" "$file" | $CAT + # Get photo, if supported and if it exists + if [ "${CHAFA:-}" ]; then + photo=$(mktemp) + awk -v field="PHOTO" "$AWK_GET" "$file" | base64 -d -i >"$photo" + type=$(file --mime-type -b "$photo" | cut -d '/' -f 1) + if [ "$type" = "image" ]; then + WIDTH=80 + if [ "$FZF_PREVIEW_COLUMNS" -lt "$WIDTH" ]; then + WIDTH="$FZF_PREVIEW_COLUMNS" + fi + $CHAFA -f symbols -s "$WIDTH" "$photo" + fi + rm "$photo" + fi exit fi diff --git a/src/sh/config.sh b/src/sh/config.sh index cb6a2de..4cef7c9 100644 --- a/src/sh/config.sh +++ b/src/sh/config.sh @@ -65,4 +65,9 @@ if command -v "git" >/dev/null && [ -d "$ROOT/.git" ]; then export GIT fi +if command -v "chafa" >/dev/null; then + CHAFA="chafa" + export CHAFA +fi + export OPEN=${OPEN:-open}