feat: basic image viewer
This commit is contained in:
parent
4ba328934b
commit
adaff4e285
@ -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,15 +18,18 @@
|
||||
|
||||
# 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
|
||||
if (prop)
|
||||
content = getparam(line, prop)
|
||||
else
|
||||
content = getcontent(line)
|
||||
if (oneline)
|
||||
content = singleline(content)
|
||||
|
@ -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 <enter> to continue.'; read -r tmp)" || #--color='preview-bg:#ecc297,preview-fg:black' \
|
||||
|
@ -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
|
||||
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user