Clipboard: use a simpler working one

This commit is contained in:
Peritia 2026-03-04 09:07:51 +01:00
parent ce5fd8b332
commit 6d9e75776d

View file

@ -21,15 +21,13 @@
home.file.".local/bin/TermClipboardManager" = {
executable = true;
text = ''
text = lib.mkForce ''
#!/usr/bin/env bash
set -euo pipefail
preview() {
ID=$(awk '{print $1}' <<< "$1")
TMP=$(mktemp)
cliphist decode "$ID" > "$TMP" 2>/dev/null || {
cliphist decode "$1" > "$TMP" 2>/dev/null || {
echo "Failed to decode"
rm -f "$TMP"
return
@ -40,16 +38,11 @@
if [[ "$MIME" == image/* ]]; then
DIM=$(identify -format "%wx%h" "$TMP" 2>/dev/null || echo "unknown")
echo "Image $MIME $DIM"
echo ""
# Dynamic scaling to preview pane
timg --quiet --center \
--fit \
--max-size="''${FZF_PREVIEW_COLUMNS}x''${FZF_PREVIEW_LINES}" \
"$TMP"
echo "----------------------------------------"
timg --quiet --center --fit "$TMP"
else
echo "Text $MIME"
echo ""
echo "----------------------------------------"
bat --style=plain --color=always "$TMP" 2>/dev/null || cat "$TMP"
fi
@ -58,27 +51,21 @@
export -f preview
HELP="Enter: Copy & Close | Ctrl-Y: Copy (stay) | DEL: Delete | Ctrl-D: Wipe | Ctrl-O: Open Image | Ctrl-I: Toggle Preview"
while true; do
SELECTION=$(
cliphist list | \
fzf \
--height=100% \
--border \
--header="$HELP" \
--preview 'bash -c "preview \"$1\"" _ {}' \
--preview-window=right:60% \
--bind "del:execute-silent(bash -c 'ID=$(cut -d\" \" -f1 <<< \"$1\"); cliphist delete \"$ID\"' _ {})+reload(cliphist list)" \
--bind "ctrl-d:execute-silent(cliphist wipe)+reload(cliphist list)" \
--bind "ctrl-y:execute-silent(bash -c 'ID=$(cut -d\" \" -f1 <<< \"$1\"); cliphist decode \"$ID\" | wl-copy' _ {})" \
--bind "ctrl-o:execute-silent(bash -c 'ID=$(cut -d\" \" -f1 <<< \"$1\"); cliphist decode \"$ID\" > /tmp/clipimg && imv /tmp/clipimg' _ {})" \
--bind "ctrl-i:change-preview-window(hidden)" )
cliphist list | \
fzf \
--height=100% \
--border \
--preview "bash -c 'preview \"\$1\"' _ {}" \
--preview-window=right:60% \
--bind "del:execute-silent(bash -c 'cliphist delete \"\$1\"' _ {})+reload(cliphist list)" \
--bind "ctrl-d:execute-silent(cliphist wipe)+reload(cliphist list)"
)
[[ -z "$SELECTION" ]] && exit 0
ID=$(awk '{print $1}' <<< "$SELECTION")
cliphist decode "$ID" | wl-copy
cliphist decode <<< "$SELECTION" | wl-copy
exit 0
done
'';