dots/chezmoi/dot_config/tmux/plugins/tmux-fzf/scripts/executable_clipboard.sh
aleidk 224c7ed45c Migrate to chezmoi
Move config files from config to chezmoi
Add script to auto install packages with DNF and Cargo
2024-03-01 20:26:02 -03:00

31 lines
1.5 KiB
Bash

#!/usr/bin/env bash
FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select clipboard history. Press TAB to mark multiple items.'"
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$CURRENT_DIR/.envs"
if ! [ -x "$(command -v copyq)" ]; then
action="buffer"
elif [ -z "$1" ]; then
action="system"
else
action="$1"
fi
if [[ "$action" == "system" ]]; then
item_numbers=$(copyq count)
contents="[cancel]\n"
index=0
while [ "$index" -lt "$item_numbers" ]; do
_content="$(copyq read ${index} | tr '\n' ' ' | tr '\\n' ' ')"
contents="${contents}copy${index}: ${_content}\n"
index=$((index + 1))
done
copyq_index=$(printf "$contents" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS --preview=\"echo {} | sed -e 's/^copy//' -e 's/: .*//' | xargs -I{} copyq read {}\"" | sed -e 's/^copy//' -e 's/: .*//')
[[ "$copyq_index" == "[cancel]" || -z "$copyq_index" ]] && exit
echo "$copyq_index" | xargs -I{} sh -c 'tmux set-buffer -b _temp_tmux_fzf "$(copyq read {})" && tmux paste-buffer -b _temp_tmux_fzf && tmux delete-buffer -b _temp_tmux_fzf'
elif [[ "$action" == "buffer" ]]; then
selected_buffer=$(tmux list-buffers | sed -e 's/:.*bytes//' -e '1s/^/[cancel]\n/' -e 's/: "/: /' -e 's/"$//' | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS --preview=\"echo {} | sed -e 's/\[cancel\]//' -e 's/:.*$//' | head -1 | xargs tmux show-buffer -b\"" | sed 's/:.*$//')
[[ "$selected_buffer" == "[cancel]" || -z "$selected_buffer" ]] && exit
echo "$selected_buffer" | xargs -I{} sh -c 'tmux paste-buffer -b {}'
fi