* Completion for qdbus
@ 2015-01-11 15:28 Thomas Mitterfellner
2015-01-11 17:37 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Mitterfellner @ 2015-01-11 15:28 UTC (permalink / raw)
To: zsh-workers
Hello!
I wrote a completion function for qdbus (a command line tool for
communicating with dbus-enabled programs, like kmix, krusader,
pulseaudio…) which I want to share in the hope that it will be useful.
Comments, suggestions, testing, corrections etc. are welcome!
Best regards,
Thomas
_qdbus
#compdef qdbus
#
# Copyright (C) 2015 Thomas Mitterfellner <thomas.mitterfellner@gmail.com>
#
# This file is released under the GPLv2.
#
# version 0.1
# get the type of a method: 1 means function, 2 means property
getType () {
case "$1" in
"method"*) echo 1 ;;
"property"*) echo 2 ;;
*) echo 0 ;;
esac
}
# get the index of a method in an array of methods
getIndex () {
local e
local index
local type_
index=0
for e in "${@:2}"; do
index=$(( index + 1 ))
type_=$(getType "$e")
if [[ $type_ == 1 ]] ; then
if [[ "$e" == *"$1("* ]] ; then
echo $index
return 0
fi
elif [[ $type_ == 2 ]] ; then
if [[ "$e" == *"$1" ]] ; then
echo $index
return 0
fi
fi
done
echo 0
}
_qdbus() {
local curcontext="$curcontext" state line
local services
local path_
local methods
local names
local types
local properties
local index
typeset -A opt_args
_arguments "--system[connect to system bus]"\
"--literal[print literal replies]"\
"1:service name:->service"\
"2:path:->path"\
"3:method:->method"\
"*:arguments:->arguments"
case $state in
service)
services=( $(qdbus ${words[@]:1:-1} | grep -E '^([^:])') )
compadd "$@" $services
;;
path)
path_=( $(qdbus ${words[@]:1:-1} 2>/dev/null) )
compadd "$@" $path_
;;
method)
IFS=$'\n'
methods=( $(qdbus ${words[@]:1:-1} | \
grep -e "^method" | \
sed -r 's/method (.+) (.+)\((.*)\)/\2:\1(\3)/g' 2>/dev/null) )
properties=( $(qdbus ${words[@]:1:-1} | \
grep -e "^property" | \
sed -r 's/property (.+) (.+) (.+)/\3:\1 \2/g' 2>/dev/null) )
_describe properties properties -J properties
_describe methods methods -J methods
;;
arguments)
IFS=$'\n'
path_pos=$(( ${(M)#words:#--*} + 2))
method_pos=$(( $path_pos + 2))
names=( $(qdbus ${words[@]:1:$path_pos} | grep -e '^[mp]'
2>/dev/null) )
index=$(getIndex "${words[$method_pos]}" $names[@])
method=$names[$index]
arg_pos=$(( ${#words} - $method_pos ))
if [[ $(getType "$method") -eq 1 ]] ; then
method_args="$(echo $method | sed -r 's/(.+) (.+)
(.+)\((.*)\)/\4/g')"
IFS=$',' method_args_=(${=method_args})
num_args=${#method_args_}
if [[ $arg_pos -le $num_args ]] ; then
_message "${method_args_[$arg_pos]}"
fi
else
property_=$(echo "$method" |\
sed -r 's/property (.+) (.+) (.+)/\1 \2/g')
if [[ $arg_pos -eq 1 ]] ; then
_message ${property_}
fi
fi
;;
esac
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Completion for qdbus
2015-01-11 15:28 Completion for qdbus Thomas Mitterfellner
@ 2015-01-11 17:37 ` Peter Stephenson
0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2015-01-11 17:37 UTC (permalink / raw)
To: Thomas Mitterfellner, zsh-workers
On Sun, 11 Jan 2015 16:28:19 +0100
Thomas Mitterfellner <thomas.mitterfellner@gmail.com> wrote:
> I wrote a completion function for qdbus (a command line tool for
> communicating with dbus-enabled programs, like kmix, krusader,
> pulseaudio…) which I want to share in the hope that it will be useful.
Thanks, it's already been added, though now I look I see one extra tweak
would be useful...
diff --git a/Completion/Linux/Command/_qdbus b/Completion/Linux/Command/_qdbus
index d665c7a..95a4d52 100644
--- a/Completion/Linux/Command/_qdbus
+++ b/Completion/Linux/Command/_qdbus
@@ -110,3 +110,5 @@ _qdbus() {
;;
esac
}
+
+_qdbus "$@"
pws
^ permalink raw reply [flat|nested] 3+ messages in thread
* Completion for qdbus
@ 2015-01-09 22:45 Thomas Mitterfellner
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Mitterfellner @ 2015-01-09 22:45 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 295 bytes --]
Hello!
I wrote a completion function for qdbus (a command line tool for
communicating with dbus-enabled programs, like kmix, krusader,
pulseaudio…) which I want to share in the hope that it will be useful.
Comments, suggestions, testing, corrections etc. are welcome!
Best regards,
Thomas
[-- Attachment #2: _qdbus --]
[-- Type: text/plain, Size: 2735 bytes --]
#compdef qdbus
#
# Copyright (C) 2015 Thomas Mitterfellner <thomas.mitterfellner@gmail.com>
#
# This file is released under the GPLv2.
#
# version 0.1
# get the type of a method: 1 means function, 2 means property
getType () {
case "$1" in
"method"*) echo 1 ;;
"property"*) echo 2 ;;
*) echo 0 ;;
esac
}
# get the index of a method in an array of methods
getIndex () {
local e
local index
local type_
index=0
for e in "${@:2}"; do
index=$(( index + 1 ))
type_=$(getType "$e")
if [[ $type_ == 1 ]] ; then
if [[ "$e" == *"$1("* ]] ; then
echo $index
return 0
fi
elif [[ $type_ == 2 ]] ; then
if [[ "$e" == *"$1" ]] ; then
echo $index
return 0
fi
fi
done
echo 0
}
_qdbus() {
local curcontext="$curcontext" state line
local services
local path_
local methods
local names
local types
local properties
local index
typeset -A opt_args
_arguments "--system[connect to system bus]"\
"--literal[print literal replies]"\
"1:service name:->service"\
"2:path:->path"\
"3:method:->method"\
"*:arguments:->arguments"
case $state in
service)
services=( $(qdbus ${words[@]:1:-1} | grep -E '^([^:])') )
compadd "$@" $services
;;
path)
path_=( $(qdbus ${words[@]:1:-1} 2>/dev/null) )
compadd "$@" $path_
;;
method)
IFS=$'\n'
methods=( $(qdbus ${words[@]:1:-1} | \
grep -e "^method" | \
sed -r 's/method (.+) (.+)\((.*)\)/\2:\1(\3)/g' 2>/dev/null) )
properties=( $(qdbus ${words[@]:1:-1} | \
grep -e "^property" | \
sed -r 's/property (.+) (.+) (.+)/\3:\1 \2/g' 2>/dev/null) )
_describe properties properties -J properties
_describe methods methods -J methods
;;
arguments)
IFS=$'\n'
path_pos=$(( ${(M)#words:#--*} + 2))
method_pos=$(( $path_pos + 2))
names=( $(qdbus ${words[@]:1:$path_pos} | grep -e '^[mp]' 2>/dev/null) )
index=$(getIndex "${words[$method_pos]}" $names[@])
method=$names[$index]
arg_pos=$(( ${#words} - $method_pos ))
if [[ $(getType "$method") -eq 1 ]] ; then
method_args="$(echo $method | sed -r 's/(.+) (.+) (.+)\((.*)\)/\4/g')"
IFS=$',' method_args_=(${=method_args})
num_args=${#method_args_}
if [[ $arg_pos -le $num_args ]] ; then
_message "${method_args_[$arg_pos]}"
fi
else
property_=$(echo "$method" |\
sed -r 's/property (.+) (.+) (.+)/\1 \2/g')
if [[ $arg_pos -eq 1 ]] ; then
_message ${property_}
fi
fi
;;
esac
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-11 17:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-11 15:28 Completion for qdbus Thomas Mitterfellner
2015-01-11 17:37 ` Peter Stephenson
-- strict thread matches above, loose matches on Subject: below --
2015-01-09 22:45 Thomas Mitterfellner
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).