Hiya

I've writte a completion file for qdbus, a KDE4 interprocess communication 
tool. I can't find any documentation for the command, other than that 
suggested by interactive use - that is, I don't know if there are more options 
that the command accepts.


The similar command in KDE3, dcop, has a completion already, but it's buggy; 
in the script the command

    if eval "$com >/dev/null 2>&1"

does not behave as expected; in fact, in fish the following

    if eval "not-a-command"; echo "yes!" ; end

does indeed echo "yes!" -- I guess because the eval command is always 
considered successful, even when the command evaluated by eval failed.
I don't think that makes sense.

The dcop script can be fixed somewhat by changing the line to 

    if test ( eval "$com >/dev/null 2>&1;echo \$status" ) -eq 0

as in the attached version.


One more thing: Try typing something in fish and pressing the up arrow. This 
activates history search. Try pressing Ctrl-C, clearing the commandline, and 
then pressing the up arrow again. The history search is still active. This is 
annoying if the following happens:

- I type some command and press tab
- The completion I want isn't there e.g. because I'm in the wrong directory.
- If I'm in a directory with many files, the completions are paged so I press 
esc to leave the completion list
- I press 'up' in order to return to the previous command. This is wrong, 
because the command I just typed is still active, and history search gets 
activated
- I press Ctrl-C to leave the history search
- I press 'up' in order to return to the previous command, but history search 
i still active and I have to press Ctrl-C AND THEN return to get out.
- annoying :-o

Well I guess you can tell I like fish a lot already, despite the annoyance, so 
thanks everyone, and keep it up.

-Jakob
#
# Completions for the qdbus shell interface to dbus
#

function __fish_complete_qdbus -d "Completions for qdbus"

        set -l op (commandline -o)
        set -l nops (count $op)
        set -l endspace (echo (commandline)|grep '[[:space:]]$')
        set -l fnfilter "grep -v 'property '|sed -e 's/\w* \w* 
.*\\.\\(\w*\\)(\\([^)]*\\))/\1\t\2/g'"
        set -l propfilter "grep 'property '|sed -e 's/\w* \w* \\(\w*\\) 
.*\\.\\(\w*\\)/\2\t\1/g'"
        set -l interfacefilter "grep 'property '|sed -e 's/\w* \w* \w* 
\\(.*\\)\\.\w*/\1/g'"

        if test $endspace
                if test $nops -gt 1
                        set nops (expr $nops + 1)
                end 
        end
        
        switch $nops
                case 1
                        eval "$op | grep -o '[^[:space:]]*'"
                case 2
                        # select a name
                        qdbus | grep -o '[^[:space:]]*' #| grep -- $op[-1]
                case 3
                        # select path
                        eval "$op[1 2]"
                case 4
                        # select function
                        eval "$op[1 2 3] |$fnfilter"
                case 5
                        # Using functions Get or Set require an interface...
                        if contains $op[4] Set Get
                                eval "$op[1 2 3] |$interfacefilter"
                        end 
                case 6
                        # ... and a property name related with the interface.
                        # NOTE I haven't actually tested this with an object 
having properties related to different interfaces, but i *think* the "|grep 
$op[5]" makes sense...
                        if contains $op[4] Set Get
                                eval "$op[1 2 3] |grep $op[5]|$propfilter"
                        end 
        end
end

complete -c qdbus -x -f -a "(__fish_complete_qdbus)"
#
# Completions for the shell interface to the KDE DCOP server
#

function __fish_complete_dcop -d "Completions for kde dcop"
    set -l com (commandline)

    if test ( eval "$com >/dev/null 2>&1;echo \$status" ) -eq 0
        # use dcop output if available
        eval "$com | sed -e 's/ (default)//; s/^\w[^ ]* \(\w*\)([^)]*)\$/\1/'"

    else
        set -l op (commandline -o)

        if test (count $op) -le 2
            # select an application
            dcop | grep -- $op[-1]
        else
            # select a function
            set -l o
            for i in (seq 1 (count $op))
                # strip the \ character which causes problems
                set o[$i] (echo $op[$i] | sed -e 's/\\\//g')
            end

            set -l idx (seq 2 (expr (count $o) - 1))
            # list only function names
            dcop $o[$idx] | grep -- $o[-1] | sed -e 's/ (default)//; s/^\w[^ ]* 
\(\w*\)([^)]*)$/\1/'
        end
    end
end


complete -c dcop -l help -s h -f --description "Show help about options"
complete -c dcop -l user -x -a '(awk -F: "{print \$1}" /etc/passwd)' 
--description "Connect to the given user's DCOP server"
complete -c dcop -l all-users -f --description "Send the same DCOP call to all 
users with a running DCOP server"
complete -c dcop -l list-sessions -f --description "List all active KDE session 
for a user or all users"
complete -c dcop -l session -x -a '(dcop --list-sessions --all-users | grep 
DCOP)' --description "Send to the given KDE session"
complete -c dcop -l no-user-time -f --description "Don't update the user 
activity timestamp in the called application"
complete -c dcop -l pipe -f --description "Call DCOP for each line read from 
stdin"

complete -c dcop -x -a "(__fish_complete_dcop)"



-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to