Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions xclip.bash-completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,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