summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-11-02 00:14:11 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-11-02 00:15:39 +0900
commit69176fc5f4251b33cd91fbdc43699eb0eaf76b23 (patch)
tree0070553832ab9d57d15571a8b9ea13a017535a0b /bin
parent278dce9ba6f383930654b9a591f1143b0c422907 (diff)
fzf-preview.sh: Fall back to `stty size` (#2544)
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fzf-preview.sh10
1 files changed, 8 insertions, 2 deletions
diff --git a/bin/fzf-preview.sh b/bin/fzf-preview.sh
index 1818f044..ae4c6521 100755
--- a/bin/fzf-preview.sh
+++ b/bin/fzf-preview.sh
@@ -15,6 +15,11 @@ fi
file=${1/#\~\//$HOME/}
type=$(file --mime-type "$file")
+dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}
+if [[ $dim = x ]]; then
+ dim=$(stty size | awk '{print $2 "x" $1}')
+fi
+
if [[ ! $type =~ image/ ]]; then
# Sometimes bat is installed as batcat.
if command -v batcat > /dev/null; then
@@ -34,9 +39,10 @@ elif [[ $KITTY_WINDOW_ID ]]; then
# 2. The last line of the output is the ANSI reset code without newline.
# This confuses fzf and makes it render scroll offset indicator.
# So we remove the last line and append the reset code to its previous line.
- kitty icat --clear --transfer-mode=memory --stdin=no --place="${FZF_PREVIEW_COLUMNS}x$((FZF_PREVIEW_LINES))@0x0" "$file" | sed '$d' | sed $'$s/$/\e[m/'
+ kitty icat --clear --transfer-mode=memory --stdin=no --place="$dim@0x0" "$file" | sed '$d' | sed $'$s/$/\e[m/'
elif command -v chafa > /dev/null; then
- chafa -f sixel -s "${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}" "$file"
+ chafa -f sixel -s "$dim" "$file"
+ echo
else
file "$file"
fi