All Projects → jorgebucaran → Getopts.fish

jorgebucaran / Getopts.fish

Licence: mit
Parse CLI options in Fish.

Programming Languages

shell
77523 projects

Labels

Projects that are alternatives of or similar to Getopts.fish

Fish Utils
🔧 My utility belt of fish functions, writing these has saved me many hours in the long run... I hope...
Stars: ✭ 94 (-43.37%)
Mutual labels:  fish
Fish Bd
Quickly go back to a parent directory up in your current working directory tree. Don't write 'cd ../../..' redundantly, use bd instead.
Stars: ✭ 113 (-31.93%)
Mutual labels:  fish
Sdkman For Fish
Adds support for SDKMAN! to fish
Stars: ✭ 139 (-16.27%)
Mutual labels:  fish
Cookbook.fish
Tips and recipes for Fish, from shell to plate. 🍣
Stars: ✭ 1,360 (+719.28%)
Mutual labels:  fish
Fish Irssi
FiSH is an encryption add-on module for irssi.
Stars: ✭ 110 (-33.73%)
Mutual labels:  fish
Up
Quickly navigate to a parent directory via tab-completion.
Stars: ✭ 126 (-24.1%)
Mutual labels:  fish
Dotfiles
👾 ~/
Stars: ✭ 91 (-45.18%)
Mutual labels:  fish
Dotfiles
My personal dotfiles.
Stars: ✭ 162 (-2.41%)
Mutual labels:  fish
Dotfiles
If there is a shell, there is a way!
Stars: ✭ 112 (-32.53%)
Mutual labels:  fish
Packages Main
Primary Oh My Fish package repository.
Stars: ✭ 138 (-16.87%)
Mutual labels:  fish
Grayfish
light weight phishing framework with 18+ pages.
Stars: ✭ 101 (-39.16%)
Mutual labels:  fish
Forgit
💤 A utility tool powered by fzf for using git interactively.
Stars: ✭ 1,823 (+998.19%)
Mutual labels:  fish
Dots
Personal *nix configuration files
Stars: ✭ 136 (-18.07%)
Mutual labels:  fish
Mac Bootstrap
💻 Provision a new Mac for web development with dotfiles + Fish/Zsh, Neovim, and Tmux
Stars: ✭ 96 (-42.17%)
Mutual labels:  fish
Dotfiles
Config for vim sublime awesome xmonad etc.
Stars: ✭ 140 (-15.66%)
Mutual labels:  fish
Zsh to fish
How to make zsh like fish?
Stars: ✭ 93 (-43.98%)
Mutual labels:  fish
Xxh
🚀 Bring your favorite shell wherever you go through the ssh.
Stars: ✭ 2,559 (+1441.57%)
Mutual labels:  fish
Z.lua
⚡ A new cd command that helps you navigate faster by learning your habits.
Stars: ✭ 2,164 (+1203.61%)
Mutual labels:  fish
Gh
Easily manage your local git repos
Stars: ✭ 156 (-6.02%)
Mutual labels:  fish
Hydro
Ultra-pure, lag-free prompt with async Git status. Designed for Fish.
Stars: ✭ 137 (-17.47%)
Mutual labels:  fish

getopts.fish

Parse CLI options in Fish.

Getopts is a CLI options parser for Fish based on the POSIX Utility Syntax Guidelines. Think argparse without the domain specific language, implicit variables, complex option spec, or companion commands.

Installation

Install with Fisher:

fisher install jorgebucaran/getopts.fish

Quickstart

The getopts command splits your arguments into key-value records that can be read into variables.

$ engage --quadrant=delta -w9 <coordinates.dat
function engage -d "activate the warp drive"
    set -l warp 1
    set -l quadrant alpha
    set -l coordinates

    getopts $argv | while read -l key value
        switch $key
            case _
                while read -l target
                    set coordinates $coordinates $target
                end < $value
            case q quadrant
                set quadrant $value
            case w warp
                set warp $value
            case h help
                _engage_help >&2
                return
            case v version
                _engage_version >&2
                return
        end
    end

    if not set -q coordinates[3]
        echo "engage: invalid coordinates" >&2
        return 1
    end

    _engage_activate $warp $quadrant $coordinates
end

Parsing Rules

Short Options

A short option consists of a hyphen - followed by a single alphabetic character. Multiple short options can be clustered together without spaces. A short option will be true unless followed by an operand or if immediately adjacent to one or more non-alphabetic characters matching the regular expression /[email protected][-`{-~/.

$ getopts -ab -c
a true
b true
c true
$ getopts -a alppha
a alpha

The argument following a short or a long option (which is not an option itself) will be parsed as its value. That means only the last character in a cluster of options can receive a value other than true.

$ getopts -ab1 -c -d
a true
b 1
c true
d true

Symbols, numbers and other non-alphabetic characters can be used as an option if they're the first character after a hyphen.

$ getopts -9 [email protected] -/0.01
9 true
@ 10
/ 0.01

Long Options

A long option consists of two hyphens -- followed by one or more characters. Any character, including symbols, and numbers can be used to create a long option except for the = symbol, which separates the option's key and value.

$ getopts --turbo --warp=10
turbo true
warp 10
$ getopts --warp=e=mc\^2
warp e=mc^2
$ getopts ---- alpha
-- alpha

Operands

Every non-option standalone argument will be treated as an operand, and its key will be an underscore _.

$ getopts alpha -w9
_ alpha
w 9
$ getopts --code=alpha beta
code alpha
_ beta

Every argument after the first double-hyphen sequence -- will be treated as an operand.

$ getopts --alpha -- --beta gamma
alpha true
_ --beta
_ gamma

A single hyphen - is always an operand.

$ getopts --alpha -
alpha true
_ -

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].