diff options
author | Aditya <bluenerd@protonmail.com> | 2023-02-27 20:04:56 +0530 |
---|---|---|
committer | Aditya <bluenerd@protonmail.com> | 2023-02-27 20:04:56 +0530 |
commit | edc449275b6c04445f58b108ca0937a87c1e8430 (patch) | |
tree | 9fd484d58145b616f29a78857cc0b1c8b1c18f05 /oh-my-zsh/plugins/globalias | |
parent | 6f5424ca96c4221ef433f545642669e9c104d0ed (diff) |
add zsh
Diffstat (limited to 'oh-my-zsh/plugins/globalias')
-rw-r--r-- | oh-my-zsh/plugins/globalias/README.md | 79 | ||||
-rw-r--r-- | oh-my-zsh/plugins/globalias/globalias.plugin.zsh | 23 |
2 files changed, 102 insertions, 0 deletions
diff --git a/oh-my-zsh/plugins/globalias/README.md b/oh-my-zsh/plugins/globalias/README.md new file mode 100644 index 0000000..cd7fc3c --- /dev/null +++ b/oh-my-zsh/plugins/globalias/README.md @@ -0,0 +1,79 @@ +# Globalias plugin + +Expands all glob expressions, subcommands and aliases (including global). + +Idea from: https://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html. + +## Usage + +Add `globalias` to the plugins array in your zshrc file: + +```zsh +plugins=(... globalias) +``` + +Then just press `SPACE` to trigger the expansion of a command you've written. + +If you only want to insert a space without expanding the command line, press +`CTRL`+`SPACE`. + +if you would like to filter out any values from expanding set `GLOBALIAS_FILTER_VALUES` to +an array of said values. See [Filtered values](#filtered-values). + +## Examples + +#### Glob expressions + +``` +$ touch {1..10}<space> +# expands to +$ touch 1 2 3 4 5 6 7 8 9 10 + +$ ls **/*.json<space> +# expands to +$ ls folder/file.json anotherfolder/another.json +``` + +#### Subcommands + +``` +$ mkdir "`date -R`" +# expands to +$ mkdir Tue,\ 04\ Oct\ 2016\ 13:54:03\ +0300 +``` + +#### Aliases + +``` +# .zshrc: +alias -g G="| grep --color=auto -P" +alias l='ls --color=auto -lah' + +$ l<space>G<space> +# expands to +$ ls --color=auto -lah | grep --color=auto -P +``` + +``` +# .zsrc: +alias S="sudo systemctl" + +$ S<space> +# expands to: +$ sudo systemctl +``` + +#### Filtered values + +``` +# .zshrc +alias l='ls -lh' +alias la='ls --color=auto -lah' +GLOBALIAS_FILTER_VALUES=(l) + +$ l<space> +# does not expand +$ la<space> +# expands to: +$ ls --color=auto -lah +``` diff --git a/oh-my-zsh/plugins/globalias/globalias.plugin.zsh b/oh-my-zsh/plugins/globalias/globalias.plugin.zsh new file mode 100644 index 0000000..bd27d58 --- /dev/null +++ b/oh-my-zsh/plugins/globalias/globalias.plugin.zsh @@ -0,0 +1,23 @@ +globalias() { + # Get last word to the left of the cursor: + # (z) splits into words using shell parsing + # (A) makes it an array even if there's only one element + local word=${${(Az)LBUFFER}[-1]} + if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$word] -eq 0 ]]; then + zle _expand_alias + zle expand-word + fi + zle self-insert +} +zle -N globalias + +# space expands all aliases, including global +bindkey -M emacs " " globalias +bindkey -M viins " " globalias + +# control-space to make a normal space +bindkey -M emacs "^ " magic-space +bindkey -M viins "^ " magic-space + +# normal space during searches +bindkey -M isearch " " magic-space |