File: xargs

package info (click to toggle)
yash 2.60-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,152 kB
  • sloc: ansic: 34,578; makefile: 851; sh: 808; sed: 16
file content (85 lines) | stat: -rw-r--r-- 3,530 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# (C) 2010 magicant

# Completion script for the "xargs" command.
# Supports POSIX 2008, GNU findutils 4.5.9, FreeBSD 8.1, OpenBSD 4.8,
# NetBSD 5.0, Darwin 10.6.4, SunOS 5.10, HP-UX 11i v3.

function completion/xargs {

        case $("${WORDS[1]}" --version 2>/dev/null) in
                (*'findutils'*) typeset type=GNU ;;
                (*)             typeset type="$(uname 2>/dev/null)" ;;
        esac
        case $type in
                (GNU) typeset long=true ;;
                (*)   typeset long= ;;
        esac
        case $type in
                (GNU|SunOS|HP-UX) typeset short=true ;;
                (*)               typeset short= ;;
        esac

        typeset OPTIONS ARGOPT PREFIX
        OPTIONS=( #>#
        "E: ${short:+e::} ${long:+--eof::}; specify a string to treat as end of input"
        "I: ${short:+i::} ${long:+--replace::}; specify a string replaced by input words"
        "L: ${short:+l::} ${long:+--max-lines::}; specify the max number of input lines to use at once"
        "n: ${long:+--max-args:}; specify the max number of input words to use at once"
        "p ${long:+--interactive}; confirm before each command invocation"
        "s: ${long:+--max-chars:}; specify the max length of executed command lines in bytes"
        "t ${long:+--verbose}; print each executed command line before execution"
        "x ${long:+--exit}; abort when executed command line length exceeds the limit"
        ) #<#

        case $type in (GNU|*BSD|Darwin)
                OPTIONS=("$OPTIONS" #>#
                "0 ${long:+--null}; assume input words are separated by null bytes"
                "P: ${long:+--max-procs:}; specify the max number of commands executed at once"
                ) #<#
                case $type in (GNU)
                        OPTIONS=("$OPTIONS" #>#
                        "a: --arg-file:; specify the file to read words from"
                        "d: --delimiter:; specify the delimiter that separates words"
                        "--help"
                        "--version"
                        ) #<#
                esac
                case $type in (*BSD|Darwin)
                        OPTIONS=("$OPTIONS" #>#
                        "J:; like -I, but replace the first exact match only"
                        "o; reopen standard input as /dev/tty when executing commands"
                        "R:; specify the max number of operands replaced in -I"
                        ) #<#
                        case $type in (FreeBSD|NetBSD)
                                OPTIONS=("$OPTIONS" #>#
                                "S:; specify how long the command line can grow in -I"
                                ) #<#
                        esac
                esac
                case $type in (GNU|OpenBSD)
                        OPTIONS=("$OPTIONS" #>#
                        "r ${long:+--no-run-if-empty}; don't execute the command at all if input is empty"
                        ) #<#
                esac
        esac

        command -f completion//parseoptions
        case $ARGOPT in
        (-)
                command -f completion//completeoptions
                ;;
        ([dEeIiJLlnPRSs]|--delimiter|--eof|--replace|--max-*)
                ;;
        (a|--arg-file)
                complete -P "$PREFIX" -f
                ;;
        ('')
                command -f completion//getoperands
                command -f completion//reexecute -e
                ;;
        esac

}


# vim: set ft=sh ts=8 sts=8 sw=8 et: