summaryrefslogtreecommitdiff
path: root/tmuxsh/_snippetmulti,--.copy.a.snippet.textblock
blob: 7b5525c5535cc30f052e2f8e02d3d28248a8d91a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env sh
# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry)
#         https://www.youtube.com/user/gotbletu
# DESC:   copy textblock to clipboard
# DEMO:   https://www.youtube.com/watch?v=Zew0mgJwAh8

DIR="$HOME/.config/snippetmulti"
FZF_ARG() {
  fzf -e -i --delimiter / --with-nth -1 --preview 'cat {}' --prompt="Copy textblock to clipboard: " --info=hidden --layout=reverse --tiebreak=index
}
selected="$(find "$DIR"/ -type f | sort | FZF_ARG)"
[ -z "$selected" ] && exit

# copy to X11 (linux,bsd)
xsel -b < "$selected" || xclip -selection clipboard "$selected"
# copy to Wayland (linux,bsd)
wl-copy < "$selected"
# copy to WindowsOS (Vista+)
clip < "$selected"
# copy to Cygwin (WindowsOS)
cat "$selected" > /dev/clipboard
# copy to MacOS
pbcopy < "$selected"
# copy to Termux (Android)
cat "$selected" | termux-clipboard-set
# copy to tmux
tmux load-buffer "$selected"
tmux display-message "Copied contents to clipboard"