forked from astrand/xclip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxclip.bash-completion
59 lines (51 loc) · 1.51 KB
/
xclip.bash-completion
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
56
57
58
59
# -*- shell-script -*-
# bash completion for xclip, xclip-{copy,cut,paste}file.
# This file is part of the xclip program.
# This lists available TARGETS for -t, available selections for -se,
# available options for -, and files otherwise.
_getselection() {
# Did the user specify which selection to use already?
# Look through words for "-selection" then return next word.
# (This affects which TARGETS are returned.)
local w nextandbreak
for w in "${COMP_WORDS[@]}"; do
[[ -z "$nextandbreak" ]] || break
[[ $w == -se* ]] && nextandbreak=1
done
if [[ "$w" && $w != -se* ]]; then
echo "$w"
else
echo "Primary"
fi
}
_xclip()
{
local cur prev selection options
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
case $prev in
-t*)
selection=$( _getselection )
options=$( xclip -selection $selection -target TARGETS 2>/dev/null )
COMPREPLY=( $( compgen -W "$options" -- $cur ) )
return 0
;;
-se*)
options="Primary Secondary Clipboard Buffer-cut"
COMPREPLY=( $( compgen -W "$options" -- ${cur^} ) )
return 0
;;
esac
# Begins with -, so command line option (or badly named file, I suppose)
if [[ "$cur" == -* ]]; then
options="-in -out -loops -display -help -selection"
options+=" -c -noutf8 -target -T -rmlastnl -version"
options+=" -silent -quiet -verbose"
COMPREPLY=( $( compgen -W "$options" -- $cur ) )
return 0
fi
# Fall back to files
COMPREPLY=( $( compgen -f -- $cur ) )
}
complete -F _xclip xclip