From 0ec9acf0f0cbf0f5c915805ded16e2488ea29581 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Mon, 3 Jul 2017 13:05:50 -0700 Subject: [PATCH] harden `abbr` against undef vars This is only needed if we make undefined vars an error as proposed in issue #4163 but it's a good idea anyway. --- share/functions/abbr.fish | 8 +++++++- tests/abbr.in | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/share/functions/abbr.fish b/share/functions/abbr.fish index e09651c58..23a2d08e3 100644 --- a/share/functions/abbr.fish +++ b/share/functions/abbr.fish @@ -96,8 +96,10 @@ function abbr --description "Manage abbreviations" end # Bail out early if the exact abbr is already in - contains -- "$mode_arg" $fish_user_abbreviations + set -q fish_user_abbreviations + and contains -- "$mode_arg" $fish_user_abbreviations and return 0 + set -l key $mode_arg[1] set -e mode_arg[1] set -l value "$mode_arg" @@ -186,6 +188,10 @@ function __fish_abbr_get_by_key echo "__fish_abbr_get_by_key: expected one argument, got none" >&2 return 2 end + + set -q fish_user_abbreviations + or return 1 + # Going through all entries is still quicker than calling `seq` set -l keys for kv in $fish_user_abbreviations diff --git a/tests/abbr.in b/tests/abbr.in index 5ed22c346..26b421171 100644 --- a/tests/abbr.in +++ b/tests/abbr.in @@ -11,7 +11,7 @@ abbr __abbr1 alpha beta gamma abbr | grep __abbr1 # Replacing -abbr __abbr1 delta +abbr __abbr1 delta abbr | grep __abbr1 # -s and --show tests