Last active
September 29, 2023 21:10
-
-
Save chmouel/723b88ac10e85510f7c9f7323d634577 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
TMP=$(mktemp /tmp/.mm.XXXXXX) | |
clean() { rm -f $TMP; } | |
trap clean EXIT | |
query= | |
[[ -n $@ ]] && query="--query=$@" | |
case "$(uname -a)" in | |
*Darwin*) UEBERZUG_TMP_DIR="$TMPDIR" ;; | |
*) UEBERZUG_TMP_DIR="/tmp" ;; | |
esac | |
cleanup() { | |
ueberzugpp cmd -s "$UB_SOCKET" -a exit | |
} | |
trap cleanup HUP INT QUIT TERM EXIT | |
UB_PID_FILE="$UEBERZUG_TMP_DIR/.$(uuidgen)" | |
ueberzugpp layer --no-stdin --silent --use-escape-codes --pid-file "$UB_PID_FILE" | |
UB_PID=$(cat "$UB_PID_FILE") | |
export SOCKET="$UEBERZUG_TMP_DIR"/ueberzugpp-"$UB_PID".socket | |
export X=$(($(tput cols) / 2 + 1)) | |
# --max-width $FZF_PREVIEW_COLUMNS --max-height $FZF_PREVIEW_LINES | |
# if FZF_PREVIEW_COLUMNS exists, use it, otherwise use tput cols | |
[ -z "$FZF_PREVIEW_COLUMNS" ] && max_width=$(($(tput cols) - 2)) || max_width=$FZF_PREVIEW_COLUMNS | |
[ -z "$FZF_PREVIEW_LINES" ] && max_height=$(($(tput lines) - 2)) || max_height=$FZF_PREVIEW_LINES | |
# run fzf with preview | |
cliphist list | fzf ${query} --with-nth=2.. --reverse --preview="type=$(echo {} | cut -f3);[[ {} == *'binary data image/png' ]] && { cliphist show {1} > $TMP && ueberzugpp cmd -s $SOCKET -i fzfpreview -a add -x $X -y 1 --max-width $max_width --max-> | |
ueberzugpp cmd -s "$SOCKET" -a exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment