Files
dotfiles/.local/bin/my-cli-preview

51 lines
1.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
file="$1"
print_repeated() {
local char="$1"
local lines="$2"
local columns="$3"
local linebreak="$4"
for i in `seq 1 $lines`
do
for j in `seq 1 $columns`
do
echo -n "$char"
done
echo -en "$linebreak"
done
}
mime="$(file -b --mime-type $file)"
type="$(echo $mime | cut -d/ -f1)"
if [ "$type" = "image" ] || [ "$mime" = "application/pdf" ]
then
if [ "$TERM" = "xterm-kitty" ] || [ "$TERM" = "xterm-ghostty" ]
then
exec kitten icat --clear --transfer-mode=memory --stdin=no --place=$(($FZF_PREVIEW_COLUMNS))x$(($FZF_PREVIEW_LINES-1))@$(($COLUMNS/2))x2 "$file"
else
which viu >/dev/null && exec viu -s -w $FZF_PREVIEW_COLUMNS "$file"
if [ "$mime" = "image/svg+xml" ]
then
exec batcat --color=always -pp "$file"
else
print_repeated "" $(($FZF_PREVIEW_LINES/2-2)) $FZF_PREVIEW_COLUMNS "\n"
print_repeated "" 1 $(($FZF_PREVIEW_COLUMNS/2-15)) ""
print_repeated " " 1 30 ""
print_repeated "" 1 $(($FZF_PREVIEW_COLUMNS/2-15)) "\n"
print_repeated "" 1 $(($FZF_PREVIEW_COLUMNS/2-15)) ""
echo -n " Binary cannot be previewed "
print_repeated "" 1 $(($FZF_PREVIEW_COLUMNS/2-15)) "\n"
print_repeated "" 1 $(($FZF_PREVIEW_COLUMNS/2-15)) ""
print_repeated " " 1 30 ""
print_repeated "" 1 $(($FZF_PREVIEW_COLUMNS/2-15)) "\n"
print_repeated "" $(($FZF_PREVIEW_LINES/2-1)) $FZF_PREVIEW_COLUMNS "\n"
fi
fi
else
kitten icat --clear --transfer-mode=memory --stdin=no
kitten icat --clear --transfer-mode=memory --stdin=no
exec batcat --color=always -pp "$file"
fi