|
Packit Service |
1d8f1c |
# vim:set et ts=4 sts=4:
|
|
Packit Service |
1d8f1c |
# bash completion for ibus
|
|
Packit Service |
1d8f1c |
#
|
|
Packit Service |
1d8f1c |
# ibus - The Input Bus
|
|
Packit Service |
1d8f1c |
#
|
|
Packit Service |
1d8f1c |
# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com>
|
|
Packit Service |
1d8f1c |
# Copyright (c) 2007-2010 Red Hat, Inc.
|
|
Packit Service |
1d8f1c |
#
|
|
Packit Service |
1d8f1c |
# This library is free software; you can redistribute it and/or
|
|
Packit Service |
1d8f1c |
# modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
1d8f1c |
# License as published by the Free Software Foundation; either
|
|
Packit Service |
1d8f1c |
# version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
1d8f1c |
#
|
|
Packit Service |
1d8f1c |
# This library is distributed in the hope that it will be useful,
|
|
Packit Service |
1d8f1c |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
1d8f1c |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
1d8f1c |
# Lesser General Public License for more details.
|
|
Packit Service |
1d8f1c |
#
|
|
Packit Service |
1d8f1c |
# You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
1d8f1c |
# License along with this library; if not, write to the Free Software
|
|
Packit Service |
1d8f1c |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
Packit Service |
1d8f1c |
# USA
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
|
|
Packit Service |
1d8f1c |
if [[ -z ${ZSH_VERSION:+set} ]]; then
|
|
Packit Service |
1d8f1c |
_get_comp_words_by_ref ()
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
local exclude cur_ words_ cword_
|
|
Packit Service |
1d8f1c |
if [ "$1" = "-n" ]; then
|
|
Packit Service |
1d8f1c |
exclude=$2
|
|
Packit Service |
1d8f1c |
shift 2
|
|
Packit Service |
1d8f1c |
fi
|
|
Packit Service |
1d8f1c |
__git_reassemble_comp_words_by_ref "$exclude"
|
|
Packit Service |
1d8f1c |
cur_=${words_[cword_]}
|
|
Packit Service |
1d8f1c |
while [ $# -gt 0 ]; do
|
|
Packit Service |
1d8f1c |
case "$1" in
|
|
Packit Service |
1d8f1c |
cur)
|
|
Packit Service |
1d8f1c |
cur=$cur_
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
prev)
|
|
Packit Service |
1d8f1c |
prev=${words_[$cword_-1]}
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
words)
|
|
Packit Service |
1d8f1c |
words=("${words_[@]}")
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
cword)
|
|
Packit Service |
1d8f1c |
cword=$cword_
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
esac
|
|
Packit Service |
1d8f1c |
shift
|
|
Packit Service |
1d8f1c |
done
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
else
|
|
Packit Service |
1d8f1c |
_get_comp_words_by_ref ()
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
while [ $# -gt 0 ]; do
|
|
Packit Service |
1d8f1c |
case "$1" in
|
|
Packit Service |
1d8f1c |
cur)
|
|
Packit Service |
1d8f1c |
cur=${COMP_WORDS[COMP_CWORD]}
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
prev)
|
|
Packit Service |
1d8f1c |
prev=${COMP_WORDS[COMP_CWORD-1]}
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
words)
|
|
Packit Service |
1d8f1c |
words=("${COMP_WORDS[@]}")
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
cword)
|
|
Packit Service |
1d8f1c |
cword=$COMP_CWORD
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
-n)
|
|
Packit Service |
1d8f1c |
# assume COMP_WORDBREAKS is already set sanely
|
|
Packit Service |
1d8f1c |
shift
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
esac
|
|
Packit Service |
1d8f1c |
shift
|
|
Packit Service |
1d8f1c |
done
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
fi
|
|
Packit Service |
1d8f1c |
fi
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
__ibus_engine()
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
if [[ "$cmd" == "$prev" ]]; then
|
|
Packit Service |
1d8f1c |
local imes=$( ibus list-engine --name-only 2>/dev/null )
|
|
Packit Service |
1d8f1c |
COMPREPLY=( $( compgen -W "$imes" -- "$cur" | sed "s/^$cur/$cur_/" ))
|
|
Packit Service |
1d8f1c |
fi
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
__ibus_list_engine()
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
if [[ "$cur" == -* ]]; then
|
|
Packit Service |
1d8f1c |
local options=( --name-only )
|
|
Packit Service |
1d8f1c |
COMPREPLY=( $( compgen -W '${options[@]}' -- "$cur" ))
|
|
Packit Service |
1d8f1c |
fi
|
|
Packit Service |
1d8f1c |
}
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
__ibus()
|
|
Packit Service |
1d8f1c |
{
|
|
Packit Service |
1d8f1c |
COMPREPLY=()
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
local cur_=$2 prev_=$3 cur words cword prev
|
|
Packit Service |
1d8f1c |
_get_comp_words_by_ref -n =: cur words cword prev
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
# echo
|
|
Packit Service |
1d8f1c |
# echo "cur='$cur'"
|
|
Packit Service |
1d8f1c |
# echo "prev='$prev'"
|
|
Packit Service |
1d8f1c |
# echo "words='${words[@]}'"
|
|
Packit Service |
1d8f1c |
# echo "cwords='${cwords[@]}'"
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
# Commands
|
|
Packit Service |
1d8f1c |
local cmds=( engine list-engine watch restart exit )
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
local i c cmd subcmd
|
|
Packit Service |
1d8f1c |
for (( i=1; i < ${#words[@]}-1; i++)) ; do
|
|
Packit Service |
1d8f1c |
[[ -n $cmd ]] && subcmd=${words[i]} && break
|
|
Packit Service |
1d8f1c |
for c in ${cmds[@]}; do
|
|
Packit Service |
1d8f1c |
[[ ${words[i]} == $c ]] && cmd=$c && break
|
|
Packit Service |
1d8f1c |
done
|
|
Packit Service |
1d8f1c |
done
|
|
Packit Service |
1d8f1c |
|
|
Packit Service |
1d8f1c |
case $cmd in
|
|
Packit Service |
1d8f1c |
engine)
|
|
Packit Service |
1d8f1c |
__ibus_engine;
|
|
Packit Service |
1d8f1c |
return 0
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
list-engine)
|
|
Packit Service |
1d8f1c |
__ibus_list_engine;
|
|
Packit Service |
1d8f1c |
return 0
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
watch)
|
|
Packit Service |
1d8f1c |
return 0
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
*)
|
|
Packit Service |
1d8f1c |
COMPREPLY=( $( compgen -W '${cmds[@]}' -- "$cur" ))
|
|
Packit Service |
1d8f1c |
return 0
|
|
Packit Service |
1d8f1c |
;;
|
|
Packit Service |
1d8f1c |
esac
|
|
Packit Service |
1d8f1c |
} &&
|
|
Packit Service |
1d8f1c |
complete -o bashdefault -o default -o nospace -F __ibus ibus
|