From 708f80d8559844564e30f0bfedcbf06503815c56 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sun, 13 Nov 2016 14:07:03 -0800 Subject: [PATCH] handle unexpected args to binding mode functions Fixes #3472 --- share/functions/__fish_shared_key_bindings.fish | 12 ++++++++++-- share/functions/fish_default_key_bindings.fish | 12 +++++++++++- share/functions/fish_vi_key_bindings.fish | 10 +++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index 015980d81..056d05cf2 100644 --- a/share/functions/__fish_shared_key_bindings.fish +++ b/share/functions/__fish_shared_key_bindings.fish @@ -3,7 +3,14 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod # They are supposed to be unrelated to text-editing (or movement). # This takes $argv so the vi-bindings can pass the mode they are valid in. + if contains -- -h $argv + or contains -- --help $argv + echo "Sorry but this function doesn't support -h or --help" + return 1 + end + bind $argv \cy yank + or return # protect against invalid $argv bind $argv \ey yank-pop # Left/Right arrow @@ -81,10 +88,11 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod bind $argv -k f1 __fish_man_page bind $argv \eh __fish_man_page - # This will make sure the output of the current command is paged using the default pager when you press Meta-p. + # This will make sure the output of the current command is paged using the default pager when + # you press Meta-p. # If none is set, less will be used. bind $argv \ep '__fish_paginate' - + # Make it easy to turn an unexecuted command into a comment in the shell history. Also, # remove the commenting chars so the command can be further edited then executed. bind $argv \e\# __fish_toggle_comment_commandline diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish index 2e8307487..3156404be 100644 --- a/share/functions/fish_default_key_bindings.fish +++ b/share/functions/fish_default_key_bindings.fish @@ -1,4 +1,10 @@ function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fish" + if contains -- -h $argv + or contains -- --help $argv + echo "Sorry but this function doesn't support -h or --help" + return 1 + end + if not set -q argv[1] # Clear earlier bindings, if any bind --erase --all @@ -6,16 +12,20 @@ function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fis # Allow the user to set the variable universally set -q fish_key_bindings or set -g fish_key_bindings - set fish_key_bindings fish_default_key_bindings # This triggers the handler, which calls us again and ensures the user_key_bindings are executed + # This triggers the handler, which calls us again and ensures the user_key_bindings + # are executed. + set fish_key_bindings fish_default_key_bindings return end end # These are shell-specific bindings that we share with vi mode. __fish_shared_key_bindings $argv + or return # protect against invalid $argv # This is the default binding, i.e. the one used if no other binding matches bind $argv "" self-insert + or exit # protect against invalid $argv bind $argv \n execute bind $argv \r execute diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index 1e03359df..49a7f2fa4 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -1,4 +1,10 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' + if contains -- -h $argv + or contains -- --help $argv + echo "Sorry but this function doesn't support -h or --help" + return 1 + end + # Erase all bindings if not explicitly requested otherwise to # allow for hybrid bindings. # This needs to be checked here because if we are called again @@ -16,7 +22,9 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' # Allow the user to set the variable universally set -q fish_key_bindings or set -g fish_key_bindings - set fish_key_bindings fish_vi_key_bindings # This triggers the handler, which calls us again and ensures the user_key_bindings are executed + # This triggers the handler, which calls us again and ensures the user_key_bindings + # are executed. + set fish_key_bindings fish_vi_key_bindings return end