From ae878ed6eab3690f299da2f509dfacfc890eb63e Mon Sep 17 00:00:00 2001 From: patroclo7 Date: Tue, 18 Dec 2007 09:03:15 +1000 Subject: [PATCH] option-absent-function Add a function which checks that an option has not been used (useful to avoid incompatible combinations of options and necessary for the completions for the pacman package manager. darcs-hash:20071217230315-782a0-be39b1258832f0d2427765200d051e5d688b041b.gz --- share/functions/__fish_not_contain_opt.fish | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 share/functions/__fish_not_contain_opt.fish diff --git a/share/functions/__fish_not_contain_opt.fish b/share/functions/__fish_not_contain_opt.fish new file mode 100644 index 000000000..0a7e0f561 --- /dev/null +++ b/share/functions/__fish_not_contain_opt.fish @@ -0,0 +1,51 @@ +function __fish_not_contain_opt -d "Checks that a specific option is not in the current commandline" + set -l next_short + + set -l short_opt + set -l long_opt + + for i in $argv + if test $next_short + set next_short + set short_opt $short_opt $i + else + switch $i + case -s + set next_short 1 + case '-*' + echo __fish_contains_opt: Unknown option $i + return 1 + + case '**' + set long_opt $long_opt $i + end + end + end + + for i in $short_opt + + if test -z $i + continue + end + + if commandline -cpo | sgrep -- "^-"$i"\|^-[^-]*"$i >/dev/null + return 1 + end + + if commandline -ct | sgrep -- "^-"$i"\|^-[^-]*"$i >/dev/null + return 1 + end + end + + for i in $long_opt + if test -z $i + continue + end + + if contains -- --$i (commandline -cpo) + return 1 + end + end + + return 0 +end