From 9fb70371742d4f666b6ac2ea438d9b23cd75643b Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 4 Jul 2017 22:52:14 +0200 Subject: [PATCH] fish_key_reader: Add --version option This should be there anyway, and we try to find fish_key_reader for .app bundles, so this stops us from defining aliases to the command. See #4179. --- doc_src/fish_key_reader.txt | 2 ++ share/functions/fish_key_reader.fish | 2 +- src/fish_key_reader.cpp | 8 +++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc_src/fish_key_reader.txt b/doc_src/fish_key_reader.txt index 863583183..d1d5db2ab 100644 --- a/doc_src/fish_key_reader.txt +++ b/doc_src/fish_key_reader.txt @@ -21,6 +21,8 @@ The following options are available: - `-h` or `--help` prints usage information. +- `-v` or `--version` prints fish_key_reader's version and exits. + \subsection fish_key_reader-usage-notes Usage Notes The delay in milliseconds since the previous character was received is included in the diagnostic information written to stderr. This information may be useful to determine the optimal `fish_escape_delay_ms` setting or learn the amount of lag introduced by tools like `ssh`, `mosh` or `tmux`. diff --git a/share/functions/fish_key_reader.fish b/share/functions/fish_key_reader.fish index da9b4488b..c47baf183 100644 --- a/share/functions/fish_key_reader.fish +++ b/share/functions/fish_key_reader.fish @@ -1,7 +1,7 @@ # check if command fish_key_reader works and is the same version that # came with this fish. This will happen one time. command -sq fish_key_reader -and command fish_key_reader --version 2>&1 | string match -rq $FISH_VERSION +and command fish_key_reader --version 2>&1 | string match -q -- $FISH_VERSION # if alias doesn't define the function here, this is an autoloaded "nothing". # the command (if there is one) will be used by default. or alias fish_key_reader=(string escape $__fish_bin_dir/fish_key_reader) diff --git a/src/fish_key_reader.cpp b/src/fish_key_reader.cpp index 97bd22046..00c06276f 100644 --- a/src/fish_key_reader.cpp +++ b/src/fish_key_reader.cpp @@ -26,6 +26,7 @@ #include "common.h" #include "env.h" #include "fallback.h" // IWYU pragma: keep +#include "fish_version.h" #include "input.h" #include "input_common.h" #include "print_help.h" @@ -331,11 +332,12 @@ static bool parse_debug_frames_flag() { } static bool parse_flags(int argc, char **argv, bool *continuous_mode) { - const char *short_opts = "+cd:D:h"; + const char *short_opts = "+cd:D:hv"; const struct option long_opts[] = {{"continuous", no_argument, NULL, 'c'}, {"debug-level", required_argument, NULL, 'd'}, {"debug-stack-frames", required_argument, NULL, 'D'}, {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0}}; int opt; bool error = false; @@ -358,6 +360,10 @@ static bool parse_flags(int argc, char **argv, bool *continuous_mode) { error = !parse_debug_frames_flag(); break; } + case 'v': { + fwprintf(stdout, L"%s\n", get_fish_version()); + return false; + } default: { // We assume getopt_long() has already emitted a diagnostic msg. error = true;