diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2025-01-23 12:42:59 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2025-01-23 12:42:59 +0100 |
commit | 6479dbb2ddd5782747d2cf8c18260de1971ae99f (patch) | |
tree | 981125b040674ba6d68f88c42e1acf41b17fe48c /.local/share/bin/preview | |
parent | c7faac3480d2c52db7e952f638f7f162fb98eeec (diff) |
scripts update
Diffstat (limited to '.local/share/bin/preview')
-rwxr-xr-x | .local/share/bin/preview | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/.local/share/bin/preview b/.local/share/bin/preview index 0225848..0ca63a7 100755 --- a/.local/share/bin/preview +++ b/.local/share/bin/preview @@ -1,12 +1,25 @@ #!/bin/sh -[ $# -ne 5 ] && exit 1 -FILE="$1" -WIDTH="$2" -HEIGHT="$3" -POS_X="$4" -POS_Y="$5" +[ -n "$1" ] && FILE="$1" || { + echo "error: no input file" + exit 1 +} +[ -n "$2" ] && WIDTH="$(( "$2" - 3 ))" || WIDTH="$(tput cols)" +[ -n "$3" ] && HEIGHT="$3" || HEIGHT="$(tput lines)" +[ -n "$4" ] && POS_X="$4" || POS_X="0" +[ -n "$5" ] && POS_Y="$5" || POS_Y="0" MIMETYPE="$(file --mime-type -Lb "$FILE")" +EXT="${FILE#*.}" + +[ "$EXT" = "md" ] && [ "$MIMETYPE" = "text/plain" ] && MIMETYPE="application/markdown" + +render_manpage() { + exec groff -T utf8 -m man -rcR=1 -rIN=0 -rLL="${WIDTH}n" << EOF +.nr an-suppress-header-and-footer 1 +.TH +$(cat) +EOF +} case "$MIMETYPE" in image/*) @@ -27,11 +40,15 @@ case "$MIMETYPE" in application/x-tar|\ application/x-bzip|\ application/x-bzip2|\ + application/gzip|\ application/zip|\ application/x-7z-compressed|\ application/vnd.rar) bsdtar -tf "$FILE" ;; + application/markdown) + pandoc --from=gfm --to=man "$FILE" | render_manpage + ;; *) echo "$MIMETYPE" file -b "$FILE" | fold --width="$WIDTH" --spaces |