From 1650b067a11f8492c4cfe1015a2424cb41b8b809 Mon Sep 17 00:00:00 2001 From: Felix Nehrke Date: Tue, 26 Aug 2025 22:17:27 +0200 Subject: [PATCH] Add alias ff and ffz for fzf and fzf into vim --- .bashrc | 2 ++ .local/bin/my-cli-preview | 50 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 .local/bin/my-cli-preview diff --git a/.bashrc b/.bashrc index 8c56354..9910ff5 100644 --- a/.bashrc +++ b/.bashrc @@ -73,6 +73,8 @@ alias markdown_pdf="docker run --rm -v \$PWD:/opt/docs auchida/markdown-pdf mark alias vimwiki='vim -c VimwikiIndex -c "cd %:p:h" -c "silent Git pull"' alias wiki='vim -c VimwikiIndex -c "cd %:p:h" -c "silent Git pull"' alias g=goto +alias ff="fd | fzf --preview 'my-cli-preview {}'" +alias ffv="ff | xargs vim" if [ -f .local/bin/lessfilter ] then diff --git a/.local/bin/my-cli-preview b/.local/bin/my-cli-preview new file mode 100755 index 0000000..3ad2ba0 --- /dev/null +++ b/.local/bin/my-cli-preview @@ -0,0 +1,50 @@ +#!/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