fisher/functions/getopts.fish
Jorge Bucaran 2cbbb00dcb Fisherman 1.0 RC
* Deprecate fisher --list in favor of a new command fisher list.
  The behavior is roughly the same. See fisher help list for
  usage. tl;dr: Use list to query the local system / cache and
  search to query the index.

* Teach fisher_plugin_walk about fish_postexec,
  fish_command_not_found and fish_preexec event emitters and
  erase them during uninstall if they were defined in a snippet.

* Fisherman now recognizes the following aliases by default:
  i for install, u for update, l for list, s for search and h
  for help.

* Large documentation rewrite. Better, simpler, more concise
  and more consistent.

* Fisherman now detects if users have modified their fish
  prompt using fish_config and if so, uninstalls $fisher_prompt.
2016-02-29 23:13:29 +09:00

31 lines
1.1 KiB
Fish

function getopts -d "Parse command line options"
if not set -q argv[1]
return 1
end
printf "%s\n" $argv | sed -E '
s/^-([A-Za-z]+)/- \1 /
s/^--([A-Za-z0-9_-]+)(!?)=?(.*)/-- \1 \3 \2 /' | awk '
function out(k,v) { if (!seen[k v]++) print k (v == "" ? "" : " "v) }
function pop() { return len <= 0 ? "_" : opt[len--] }
!/^ *$/ {
if (done) out("_" , $1$2$3)
else if ($1 == "--" && !$2) done = 1
else if ($2 == "" || $1 !~ /^-|^--/ ) out(pop(), $0)
else {
while (len) out(pop())
if ($3) for (i = 4; i <= NF; i++) $3 = $3" "$i
if ($1 == "--") if ($3 == "") opt[++len] = $2; else out($2, $3)
if ($1 == "-") {
if ($2 == "") { print $1; next } else n = split($2, keys, "")
if ($3 == "") opt[++len] = keys[n]; else out(keys[n], $3)
for (i = 1; i < n; i++) out(keys[i])
}
}
}
END { while (len) out(pop()) }
'
end