-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f079c1b
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# ZSH Autosuggest Abbr History | ||
This plugin defines a strategy called `abbr_history` for zsh-autosuggestions | ||
that works similar to the standard history strategy but takes `zsh-abbr` into | ||
account. | ||
|
||
## Example | ||
Lets say you have the following abbr setup: | ||
```sh | ||
abbr dc="docker compose" | ||
``` | ||
|
||
And you typed `dc ps` which expanded to `docker compose ps`. If you now type | ||
type `dc` again this will not match the `docker compose ps` entry in your | ||
history and thus the standard history strategy will not suggest anything. | ||
|
||
With the strategy of this plugin instead it will suggest `dc ps` and on | ||
suggestion accept expand that to `docker compose ps` for you. | ||
|
||
## Sidenotes | ||
At the moment zsh-autosuggestions only supports appending a suggestion. Since | ||
this plugin has to expand the abbreviation this is not enough. So at the moment | ||
this plugin only works with my fork of zsh-autosuggestions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function _zsh_autosuggest_strategy_abbr_history() { | ||
emulate -L zsh | ||
setopt EXTENDED_GLOB | ||
|
||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}" | ||
local pattern="($prefix*" | ||
IFS=$'\n' | ||
for line in $(abbr list); do | ||
if [[ $line =~ '^"(.*)"="(.*)"$' ]]; then | ||
local abbr=$match[1] | ||
local command=$match[2] | ||
if [[ $abbr == "$prefix"* ]]; then | ||
pattern+="|$command(| *)" | ||
fi | ||
fi | ||
done | ||
pattern+=")" | ||
|
||
suggestion="${history[(r)$pattern]}" | ||
|
||
for line in $(abbr list); do | ||
if [[ $line =~ '^"(.*)"="(.*)"$' ]]; then | ||
local abbr=$match[1] | ||
local command=$match[2] | ||
if [[ $abbr == "$prefix"* && $suggestion == "$command"(| *) ]]; then | ||
new_buffer=$suggestion | ||
suggestion=$abbr${suggestion:${#command}} | ||
break | ||
fi | ||
fi | ||
done | ||
} |