Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic support for aliases #3

Merged
merged 10 commits into from
Jul 12, 2020
25 changes: 18 additions & 7 deletions conf.d/abbr_tips.fish
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,25 @@ function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the
end
else if test "$command[1]" = "alias"
# Update abbreviations list when adding aliases
and not contains -- "$command[2]" $__ABBR_TIPS_KEYS
if test (count $command) = 2
set -l alias_key
set -l alias_value

if string match -q '*=*' "$command[2]"
gazorby marked this conversation as resolved.
Show resolved Hide resolved
set command_split (string split = $command[2])
set -a __ABBR_TIPS_KEYS $command_split[1]
set -a __ABBR_TIPS_VALUES $command_split[2]
set alias_key $command_split[1]
set alias_value $command_split[2]
set -a alias_value $command[3..-1]
else
set alias_key $command[2]
set alias_value $command[3..-1]
end

if set -l abb (contains -i -- "$command[3]" $__ABBR_TIPS_KEYS)
set __ABBR_TIPS_KEYS[$abb] $alias_key
set __ABBR_TIPS_VALUES[$abb] (string trim -c '\'"' $alias_value | string join ' ')
else
set -a __ABBR_TIPS_KEYS $command[2]
set -a __ABBR_TIPS_VALUES $command[3]
set -a __ABBR_TIPS_KEYS $alias_key
set -a __ABBR_TIPS_VALUES (string trim -c '\'"' $alias_value | string join ' ')
gazorby marked this conversation as resolved.
Show resolved Hide resolved
end
else if test "$command[1]" = "functions"
# Update abbreviations list when removing aliases
Expand All @@ -61,7 +72,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 alias | grep -q "^alias $cmd "
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
Expand Down