feat(eza): New plugin for the eza tool

The `eza` plugin provides some configurable aliases to simplify usage of
the [`eza`](https://github.com/eza-community/eza) tool.
This commit is contained in:
Pandu POLUAN 2024-02-23 19:21:38 +07:00
parent fcab8f1611
commit 5d2f62a83b
2 changed files with 105 additions and 0 deletions

62
plugins/eza/README.md Normal file
View file

@ -0,0 +1,62 @@
# eza plugin
This provides aliases that invoke the [`eza`](https://github.com/eza-community/eza) utility rather than `ls`
To use it add `eza` to the plugins array in your zshrc file:
```zsh
plugins=(... eza)
```
## Configuration
All configurations are done using the `zstyle` command in the `:omz:plugins:eza` namespace.
### `dirs-first`
```zsh
zstyle ':omz:plugins:eza' 'dirs-first' $BOOL
```
If `1`, directories will be grouped first.
Default: `0`
### `showgroup`
```zsh
zstyle ':omz:plugins:eza' 'showgroup' $BOOL
```
If `1` (default), always add `-g` flag to show the group ownership.
Default: `1`
### `time-style`
```zsh
zstyle ':omz:plugins:eza' 'time-style' $TIME_STYLE
```
Sets the `--time-style` option of `eza`. (See `man eza` for the options)
Default: Not set, which means the default behavior of `eza` will take place.
## Aliases
Note that aliases may be modified by Configuration.
| Alias | Command | Description |
| ------- | ----------------- | --------------------------------------------------------------------------- |
| `la` | `eza -la` | List all files (except . and ..) as a long list |
| `ldot` | `eza -ld .*` | List all dotfiles (directories shown as entries instead of recursed into) |
| `ll` | `eza -l` | List files as a long list |
| `ls` | `eza` | Plain eza call |
| `lS` | `eza -l -ssize` | List files as a long list, sorted by size |
| `lT` | `eza -l -snewest` | List files as a long list, sorted by date (newest last) |

View file

@ -0,0 +1,43 @@
typeset -a _EZA_HEAD
typeset -a _EZA_TAIL
function _configure_eza() {
local _val
# Get the head flags
zstyle -s ':omz:plugins:eza' 'showgroup' _val
if [[ -z $_val || $_val == 1 ]]; then
_EZA_HEAD+=("g")
fi
# Get the tail long-options
zstyle -s ':omz:plugins:eza' 'dirs-first' _val
if [[ $_val == 1 ]]; then
_EZA_TAIL+=("--group-directories-first")
fi
zstyle -s ':omz:plugins:eza' 'time-style' _val
if [[ $_val ]]; then
_EZA_TAIL+=("--time-style='$_val'")
fi
}
_configure_eza
function _alias_eza() {
local _tail
_tail="${(j: :)_EZA_TAIL}"
alias "$1"="eza -${(j::)_EZA_HEAD}$2${_tail:+ }${_tail}${3:+ }$3"
}
_alias_eza la la
_alias_eza ldot ld ".*"
_alias_eza ll l
_alias_eza ls
_alias_eza lS "l -ssize"
_alias_eza lT "l -snewest"
unfunction _alias_eza
unfunction _configure_eza
unset _EZA_HEAD
unset _EZA_TAIL