From ec145077231c99721643f2eb5cbb1099f84bad7a Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 20 May 2018 01:21:03 -0500 Subject: [PATCH] Add function to retrieve first token This should probably be updated to use argparse at some point? --- share/functions/__fish_first_token.fish | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 share/functions/__fish_first_token.fish diff --git a/share/functions/__fish_first_token.fish b/share/functions/__fish_first_token.fish new file mode 100644 index 000000000..65b560899 --- /dev/null +++ b/share/functions/__fish_first_token.fish @@ -0,0 +1,9 @@ +# Retrieves the first non-switch argument from the command line buffer +function __fish_first_token + set -l tokens (commandline -co) + set -e tokens[1] + set -l tokens (string replace -r --filter '^([^-].*)' '$1' -- $tokens) + if set -q tokens[1] + echo $tokens[1] + end +end