From 5becd2963c0ff9f20cb2cee8aa9966de946024ad Mon Sep 17 00:00:00 2001 From: Matias Javier Rossi Date: Mon, 14 Jun 2021 12:22:56 -0700 Subject: [PATCH 1/2] Fix string manipulation for leading dashes --- functions/__abbr_tips_bind_newline.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/__abbr_tips_bind_newline.fish b/functions/__abbr_tips_bind_newline.fish index 36ac381..d9b3122 100644 --- a/functions/__abbr_tips_bind_newline.fish +++ b/functions/__abbr_tips_bind_newline.fish @@ -1,6 +1,6 @@ function __abbr_tips_bind_newline if test $__abbr_tips_used != 1 - if abbr -q (string trim (commandline)) + if abbr -q (string trim -- (commandline)) set -g __abbr_tips_used 1 else set -g __abbr_tips_used 0 From 48c886a947d08a2b304e28ad83b7e81519a3d14e Mon Sep 17 00:00:00 2001 From: Matias Javier Rossi Date: Mon, 14 Jun 2021 12:23:51 -0700 Subject: [PATCH 2/2] Prevent dashes in strings from becoming arguments --- conf.d/abbr_tips.fish | 20 ++++++++++---------- functions/__abbr_tips_bind_newline.fish | 2 +- functions/__abbr_tips_init.fish | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/conf.d/abbr_tips.fish b/conf.d/abbr_tips.fish index 8fc10a5..cb0b6c7 100644 --- a/conf.d/abbr_tips.fish +++ b/conf.d/abbr_tips.fish @@ -25,8 +25,8 @@ function __abbr_tips_install --on-event abbr_tips_install end function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the current command" - set -l command (string split ' ' "$argv") - set -l cmd (string replace -r -a '\\s+' ' ' "$argv" ) + set -l command (string split ' ' -- "$argv") + set -l cmd (string replace -r -a '\\s+' ' ' -- "$argv" ) # Update abbreviations lists when adding/removing abbreviations if test "$command[1]" = "abbr" @@ -46,7 +46,7 @@ function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the if string match -q '*=*' -- "$command[2]" if test (count $command) = 2 - set command_split (string split = $command[2]) + set command_split (string split '=' -- $command[2]) set alias_key "a__$command_split[1]" set alias_value $command_split[2] set -a alias_value $command[3..-1] @@ -82,7 +82,7 @@ function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the else if abbr -q "$cmd" or not type -q "$command[1]" return - else if string match -q "alias $cmd *" (alias) + else if string match -q -- "alias $cmd *" (alias) return else if test (type -t "$command[1]") = 'function' and count $ABBR_TIPS_ALIAS_WHITELIST >/dev/null @@ -100,18 +100,18 @@ function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the end if test -n "$abb" - if string match -q "a__*" "$__ABBR_TIPS_KEYS[$abb]" - set -l alias (string sub -s 4 "$__ABBR_TIPS_KEYS[$abb]") + if string match -q "a__*" -- "$__ABBR_TIPS_KEYS[$abb]" + set -l alias (string sub -s 4 -- "$__ABBR_TIPS_KEYS[$abb]") if functions -q "$alias" - echo -e (string replace -a '{{ .cmd }}' "$__ABBR_TIPS_VALUES[$abb]" \ - (string replace -a '{{ .abbr }}' "$alias" "$ABBR_TIPS_PROMPT")) + echo -e (string replace -a '{{ .cmd }}' -- "$__ABBR_TIPS_VALUES[$abb]" \ + (string replace -a '{{ .abbr }}' -- "$alias" "$ABBR_TIPS_PROMPT")) else set -e __ABBR_TIPS_KEYS[$abb] set -e __ABBR_TIPS_VALUES[$abb] end else - echo -e (string replace -a '{{ .cmd }}' "$__ABBR_TIPS_VALUES[$abb]" \ - (string replace -a '{{ .abbr }}' "$__ABBR_TIPS_KEYS[$abb]" "$ABBR_TIPS_PROMPT")) + echo -e (string replace -a '{{ .cmd }}' -- "$__ABBR_TIPS_VALUES[$abb]" \ + (string replace -a '{{ .abbr }}' -- "$__ABBR_TIPS_KEYS[$abb]" "$ABBR_TIPS_PROMPT")) end end diff --git a/functions/__abbr_tips_bind_newline.fish b/functions/__abbr_tips_bind_newline.fish index d9b3122..8cc8992 100644 --- a/functions/__abbr_tips_bind_newline.fish +++ b/functions/__abbr_tips_bind_newline.fish @@ -1,6 +1,6 @@ function __abbr_tips_bind_newline if test $__abbr_tips_used != 1 - if abbr -q (string trim -- (commandline)) + if abbr -q -- (string trim -- (commandline)) set -g __abbr_tips_used 1 else set -g __abbr_tips_used 0 diff --git a/functions/__abbr_tips_init.fish b/functions/__abbr_tips_init.fish index e0be923..44ccd88 100644 --- a/functions/__abbr_tips_init.fish +++ b/functions/__abbr_tips_init.fish @@ -5,7 +5,7 @@ function __abbr_tips_init -d "Initialize abbreviations variables for fish-abbr-t set -Ux __ABBR_TIPS_VALUES set -l i 1 - set -l abb (string replace -r '.*-- ' '' (abbr -s)) + set -l abb (string replace -r '.*-- ' '' -- (abbr -s)) while test $i -le (count $abb) set -l current_abb (string split -m1 ' ' "$abb[$i]") set -a __ABBR_TIPS_KEYS "$current_abb[1]" @@ -14,7 +14,7 @@ function __abbr_tips_init -d "Initialize abbreviations variables for fish-abbr-t end set -l i 1 - set -l abb (string replace -r '.*-- ' '' (alias -s)) + set -l abb (string replace -r '.*-- ' '' -- (alias -s)) while test $i -le (count $abb) set -l current_abb (string split -m2 ' ' "$abb[$i]") set -a __ABBR_TIPS_KEYS "a__$current_abb[2]"