File: dcut-completion

package info (click to toggle)
dput-ng 1.44
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,052 kB
  • sloc: python: 3,927; makefile: 154; sh: 10
file content (65 lines) | stat: -rw-r--r-- 2,152 bytes parent folder | download | duplicates (3)
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
60
61
62
63
64
65
#-*- mode: shell-script;-*-

# Debian dcut(1) completion
# Copyright 2002 Roland Mas <lolando@debian.org>
# Copyright 2012 Salvatore Bonaccorso <carnil@debian.org>
# Copyright 2013 Luca Falavigna <dktrkranz@debian.org>
# Copyright 2018 Salvo 'LtWorf' Tomaselli <tiposchi@tiscali.it>

_dcut()
{
    local cur prev options paroptions hosts

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}
    options='-c --config -d --debug -f --force -k --keyid -m --maintainer \
             -O --output -P --passive -s --simulate -v --version'

    hosts=$(
    {
        user_dput_cf="${XDG_CONFIG_HOME:-$HOME/.config}/dput/dput.cf"
        test -r "$user_dput_cf" || user_dput_cf="$HOME/.dput.cf"
        grep "^\[.*\]" "$user_dput_cf" 2> /dev/null | tr -d [] || /bin/true
        grep "^\[.*\]" /etc/dput.cf 2> /dev/null | tr -d [] || /bin/true
        for file in $(ls $HOME/.dput.d/profiles/*.json 2> /dev/null); do \
            basename $file .json; \
        done || /bin/true
        for file in $(ls /etc/dput.d/profiles/*.json 2> /dev/null); do \
            basename $file .json; \
        done || /bin/true
        for file in $(ls /usr/share/dput-ng/profiles/*.json 2> /dev/null); do \
            basename $file .json; \
        done || /bin/true
    } | grep -v '^DEFAULT$' | sort -u)

    commands=$(
    {
        cmd="import dput\n"
        cmd=$cmd"try:\n"
        cmd=$cmd"    profile = dput.profile.load_profile('$prev')\n"
        cmd=$cmd"    cmds = dput.command.load_commands(profile)\n"
        cmd=$cmd"except dput.exceptions.DputConfigurationError:\n"
        cmd=$cmd"    cmds = []\n"
        cmd=$cmd"print(' '.join([x.name_and_purpose()[0] for x in cmds]))"
        echo $cmd | sed 's/\\n/\'$'\n/g' | python3
    } | sort -u)

    paroptions="$options $hosts $commands"

    case $prev in
    --config|-c)
        COMPREPLY=( $( compgen -o filenames -G "$cur*" ) )
        ;;
    *)
        COMPREPLY=( $(
            compgen -G "${cur}*.changes"
            compgen -W "$paroptions" | grep "^$cur"
        ) )
        ;;
    esac

    return 0

}
complete -F _dcut -o filenames -o plusdirs dcut