dotfiles/.config/fisherman/getopts
Breizh 017308719c Mises à jour diverses et nouvelles confs 2021-04-15 21:16:57 +02:00
..
man/man1 Mises à jour diverses et nouvelles confs 2021-04-15 21:16:57 +02:00
test Mises à jour diverses et nouvelles confs 2021-04-15 21:16:57 +02:00
.travis.yml Mises à jour diverses et nouvelles confs 2021-04-15 21:16:57 +02:00
LICENSE Mises à jour diverses et nouvelles confs 2021-04-15 21:16:57 +02:00
README.md Mises à jour diverses et nouvelles confs 2021-04-15 21:16:57 +02:00
getopts.fish Mises à jour diverses et nouvelles confs 2021-04-15 21:16:57 +02:00

README.md

Build Status Slack Room

Getopts

Getopts is a command line options parser for fish.

getopts -ab1 --foo=bar baz | while read -l key value
    switch $key
        case _
            echo "$value" # baz
        case a
            echo "$value" # ""
        case b
            echo "$value" # 1
        case foo
            echo "$value" # bar
    end
end

Install

With fisherman

fisher getopts

With curl.

curl -Lo ~/.config/fish/functions/getopts.fish --create-dirs git.io/getopts

Usage

Study the output in the following example

getopts -ab1 --foo=bar baz
a
b    1
foo  bar
_    baz

The items on the left are the option flags. The items on the right are the option values. The underscore _ character is the default key for bare arguments.

Use read(1) to process the generated stream and switch(1) to match patterns

getopts -ab1 --foo=bar baz | while read -l key option
    switch $key
        case _
        case a
        case b
        case foo
    end
end

Notes

  • A double dash, --, marks the end of options. Arguments after this sequence are placed in the default underscore key, _.