-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmux-fzf-copy-pattern
executable file
·55 lines (51 loc) · 1.62 KB
/
tmux-fzf-copy-pattern
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# extract URLs from current tmux pane, select one via fzf and copy it into
# clipboard
# exec &> /tmp/x
# date
# set -x
# echo $PATH
set -e
set -u
set -o pipefail
if [[ -z ${TMUX} ]]; then
echo "Error: tmux isn't running." 1>&2
exit 1
fi
if [[ $# -ge 1 ]] && ([[ $1 == "-f" ]] || [[ $1 == "-F" ]]); then
# capture everything in this pane instead of only the visible part
# -S -
prompt='Copy filename'
cmd=(xsel -i)
if [[ $1 == "-F" ]]; then
prompt='Paste filename'
cmd=(tmux load-buffer -)
fi
set +e
(tmux capture-pane && tmux save-buffer - | xfiles -o | xurls -v | sort | uniq | dmenu -i -l 10 -p "${prompt}" | perl -pe 'chomp if eof' | "${cmd[@]}") 2>/dev/null
if [[ $? -eq 0 ]] && [[ $1 == "-F" ]]; then
tmux paste-buffer
fi
set -e
elif [[ $# -ge 1 ]] && ([[ $1 == "-u" ]] || [[ $1 == "-U" ]]); then
prompt='Copy URL'
cmd=(xsel -i)
if [[ $1 == "-U" ]]; then
prompt='Open URL'
cmd=(xargs -r x-www-browser)
fi
(tmux capture-pane && tmux save-buffer - | xurls -o | sort | uniq | dmenu -i -l 10 -p "${prompt}" | perl -pe 'chomp if eof' | "${cmd[@]}") &>/dev/null || true
elif [[ $# -ge 1 ]] && ([[ $1 == "-l" ]] || [[ $1 == "-L" ]]); then
prompt='Copy line'
cmd=(xsel -i)
if [[ $1 == "-L" ]]; then
prompt='Paste line'
cmd=(tmux load-buffer -)
fi
set +e
(tmux capture-pane && tmux save-buffer - | grep -v '^$' | tac | dmenu -i -l 10 -p "${prompt}" | perl -pe 'chomp if eof' | "${cmd[@]}") 2>/dev/null
if [[ $? -eq 0 ]] && [[ $1 == "-L" ]]; then
tmux paste-buffer
fi
set -e
fi