Skip to content

Commit

Permalink
Customized ZLE word movement and modification (#280)
Browse files Browse the repository at this point in the history
Before the `WORDCHARS` environment variable that is set and used by the
ZSH line editor [1] included characters which didn't allow to move
between different segments of paths or dash-separated words.
Therefore the value has been adjusted to remove the slash, period,
angle brackets and dash characters.

The documentation now also includes a section about ZSH key bindings and
the handling of differences between different OS and terminals.

[1]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html

Closes GH-279

Co-authored-by: Sven Greb <[email protected]>
  • Loading branch information
arcticicestudio and svengreb authored May 8, 2020
1 parent 8a72f50 commit ca31290
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
36 changes: 34 additions & 2 deletions snowblocks/zsh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ The ▶ “arrow“ character is always rendered and not bound by a condition.
# Colors

This _snowblock_ is designed for the usage with [Nord][] through one of it‘s terminal [port projects][nord-ports].
In order to simplify the usage of the [color palettes][nord-docs-colors] in scripts and commands, the [`igloo-use_nord_colors` function][gh-blob-lib-funcs-nord_colors] can be _autoloaded_. It‘ll create and populate the `IGLOO_ZSH_NORD_COLORS` array with the _Nord_ colors either using the hexadecimal values or the 16 ANSI base colors of the terminal. That depends on whether the [`igloo-has_true_color`][gh-blob-func-true_color] detected that the used [terminal supports “true colors“][gist-true_colors], otherwise it falls back to the ANSI colors `0` to `15`.
In order to simplify the usage of the [color palettes][nord-docs-colors] in scripts and commands, the [`igloo-use_nord_colors` function][gh-blob-lib-funcs-nord_colors] can be _autoloaded_. It‘ll create and populate the `IGLOO_ZSH_NORD_COLORS` array with the _Nord_ colors either using the hexadecimal values or the 16 ANSI base colors of the terminal. That depends on whether the [`igloo-has_true_color`][gh-blob-lib-func-true_color] detected that the used [terminal supports “true colors“][gist-true_colors], otherwise it falls back to the ANSI colors `0` to `15`.

# Plugins

Expand All @@ -172,6 +172,34 @@ They are defined and configured per host / OS in `plugins-*.zsh` files located i
- [zsh-autosuggestions][] — Fish-like autosuggestions for commands while typing based on history and completions.
- [zsh-syntax-highlighting][] — Fish-like syntax highlighting for commands whilst they are typed.

# Key Bindings

The [`key_bindings.zsh`][gh-blob-lib-key_bind] creates and populates a `zkbd` compatible hash with [`terminfo(5)`][wiki-terminfo] mappings and defines basic key bindings.
In addition to the custom key bindings the [`zle.zsh`][gh-blob-config-zle] file sets _ZSH line editor_ specific configurations including the `WORDCHARS` environment variable. It contains characters used to determine the next / previous cursor column position when moving back and forth between words based on the defined characters. This allow e.g. to move between different segments of paths or dash-separated words.
See the [official ZSH line editor documentation][zsh-docs-zle] for more details.

## OS & Terminal Configurations

I/O events like keystrokes are always interpreted a little differently by the OS and terminal. Sometimes additional configurations are required in order to make the key bindings work properly.
The following sections provide guides how to set these configurations for OS / applications supported by this _igloo_.

### iTerm2 Profile Keys

The default key preset of [iTerm2][] profiles don't include shortcuts for the left <kbd>⌥</kbd> (_Options_/<kbd>Alt</kbd>) key when used with the <kbd>←</kbd> and <kbd>→</kbd> arrow keys to move between words. Therefore it is required to add both key shortcuts and configure the left <kbd>⌥</kbd> (_Options_/<kbd>Alt</kbd>) key to behave in _escape sequence_ mode “Esc+“:

1. Open the preferences via **iTerm2****Preferences** or press the <kbd>⌘</kbd><kbd>,</kbd> shortcut.
2. Switch to the **Profiles** tab, select your profile and change to the **Keys** sub-tab.
3. Select the “Esc+“ option radio box for **Left Option (⌥) Key**.
4. Click on the <kbd>+</kbd> button to add the new key shortcuts using the following values:
- **Keyboard Shortcut**: `⌥←`
**Action**: `Send Escape Sequence`
**Esc+**: `b`
- **Keyboard Shortcut**: `⌥→`
**Action**: `Send Escape Sequence`
**Esc+**: `f`

<p align="center"><img src="https://raw.githubusercontent.com/arcticicestudio/igloo/master/assets/sb-zsh-zle-iterm2-key_shortcuts.png" /></p>

# Resources

## Official ZSH Documentations
Expand All @@ -196,11 +224,13 @@ They are defined and configured per host / OS in `plugins-*.zsh` files located i
[fzf-gh-tree-shell]: https://github.com/junegunn/fzf/tree/master/shell
[fzf-tab]: https://github.com/Aloxaf/fzf-tab
[fzf]: https://github.com/junegunn/fzf
[gh-blob-config-zle]: https://github.com/arcticicestudio/igloo/blob/master/snowblocks/zsh/config/zle.zsh
[gh-blob-env.zsh]: https://github.com/arcticicestudio/igloo/blob/master/snowblocks/zsh/env.zsh
[gh-blob-func-true_color]: https://github.com/arcticicestudio/igloo/blob/master/snowblocks/zsh/lib/functions/igloo-has_true_color
[gh-blob-lib-config.zsh]: https://github.com/arcticicestudio/igloo/blob/master/snowblocks/zsh/lib/config.zsh
[gh-blob-lib-env.zsh]: https://github.com/arcticicestudio/igloo/blob/master/snowblocks/zsh/lib/env.zsh
[gh-blob-lib-func-true_color]: https://github.com/arcticicestudio/igloo/blob/master/snowblocks/zsh/lib/functions/igloo-has_true_color
[gh-blob-lib-funcs-nord_colors]: https://github.com/arcticicestudio/igloo/blob/master/snowblocks/zsh/lib/functions/igloo-use_nord_colors
[gh-blob-lib-key_bind]: https://github.com/arcticicestudio/igloo/blob/master/snowblocks/zsh/lib/key_bindings.zsh
[gh-blob-lib-plugins_base]: https://github.com/arcticicestudio/igloo/blob/master/snowblocks/zsh/lib/plugins-base.zsh
[gh-blob-lib-themes-igloo]: https://github.com/arcticicestudio/igloo/blob/master/snowblocks/zsh/lib/themes/igloo.zsh
[gh-blob-login.zsh]: https://github.com/arcticicestudio/igloo/blob/master/snowblocks/zsh/login.zsh
Expand All @@ -216,11 +246,13 @@ They are defined and configured per host / OS in `plugins-*.zsh` files located i
[git-blob-git_prompt.sh]: https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
[git-docs-appx-other_envs]: https://git-scm.com/book/en/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Zsh
[git]: https://git-scm.com
[iterm2]: https://www.iterm2.com
[man7-linux-manpath]: http://man7.org/linux/man-pages/man5/manpath.5.html
[nord-docs-colors]: https://www.nordtheme.com/docs/colors-and-palettes
[nord-ports]: https://www.nordtheme.com/ports
[nord]: https://www.nordtheme.com
[wiki-path_var]: https://en.wikipedia.org/wiki/PATH_(variable)
[wiki-terminfo]: https://en.wikipedia.org/wiki/Terminfo
[zplug]: https://github.com/zplug/zplug
[zsh-autosuggestions]: https://github.com/zsh-users/zsh-autosuggestions
[zsh-docs-compl_sys]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html
Expand Down
15 changes: 15 additions & 0 deletions snowblocks/zsh/config/zle.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2016-present Arctic Ice Studio <[email protected]>
# Copyright (c) 2016-present Sven Greb <[email protected]>

# Project: igloo
# Repository: https://github.com/arcticicestudio/igloo
# License: MIT

# Configurations for the ZSH line editor.
# See:
# 1. http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html

# Remove the slash, period, angle brackets and dash characters from the default list.
# This allows to move backward and forward between words include these characters or when
# trying to only delete until the next character, e.g. for paths or dash-separated words.
export WORDCHARS='*?_[]~=&;!#$%^(){}'
1 change: 1 addition & 0 deletions snowblocks/zsh/rc.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function {
[[ -f $ZDOTDIR/config/options.zsh ]] && source $ZDOTDIR/config/options.zsh
[[ -f $ZDOTDIR/config/style.zsh ]] && source $ZDOTDIR/config/style.zsh
[[ -f $ZDOTDIR/config/hooks.zsh ]] && source $ZDOTDIR/config/hooks.zsh
[[ -f $ZDOTDIR/config/zle.zsh ]] && source $ZDOTDIR/config/zle.zsh

# Load all package configurations and aliases.
function {
Expand Down
4 changes: 4 additions & 0 deletions snowblocks/zsh/snowblock.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"create": true,
"path": "config/style.zsh"
},
"$IGLOO_PATH_USER_CONFIG/zsh/config/zle.zsh": {
"create": true,
"path": "config/zle.zsh"
},
"$IGLOO_PATH_USER_CONFIG/zsh/lib/functions": {
"create": true,
"path": "lib/functions"
Expand Down

0 comments on commit ca31290

Please sign in to comment.