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
35 changes: 33 additions & 2 deletions conf.d/abbr_tips.fish
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ function __abbr_tips --on-event fish_postexec -d "Abbreviation reminder for the
set -e __ABBR_TIPS_KEYS[$abb]
set -e __ABBR_TIPS_VALUES[$abb]
end
else if test "$command[1]" = "alias"
# Update abbreviations list when adding aliases
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 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 $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
and string match -q -r '^--erase|-e$' -- "$command[2]"
and set -l abb (contains -i -- "$command[3]" $__ABBR_TIPS_KEYS)
gazorby marked this conversation as resolved.
Show resolved Hide resolved
set -e __ABBR_TIPS_KEYS[$abb]
set -e __ABBR_TIPS_VALUES[$abb]
end

# Exit in the following cases :
Expand All @@ -44,9 +72,12 @@ 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)
return
else if test (type -t "$command[1]") = 'function'
and not contains "$command[1]" $ABBR_TIPS_ALIAS_WHITELIST
return
and count $ABBR_TIPS_ALIAS_WHITELIST >/dev/null
and not contains "$command[1]" $ABBR_TIPS_ALIAS_WHITELIST
return
end

set -l abb
Expand Down
9 changes: 9 additions & 0 deletions functions/__abbr_tips_init.fish
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ function __abbr_tips_init -d "Initialize abbreviations variables for fish-abbr-t
set -a __ABBR_TIPS_VALUES (string trim -c '\'' "$current_abb[2]")
set i (math $i + 1)
end

set -l i 1
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 "$current_abb[2]"
set -a __ABBR_TIPS_VALUES (string trim -c '\'' "$current_abb[3]")
set i (math $i + 1)
end
end