6a65ac90259d87f7549c581372403405ef01b7d2

Author
Pandu E POLUAN <pepoluan@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(eza): create plugin (#12237)

Co-authored-by: Carlo Sala <carlosalag@protonmail.com>

Diff

This diff is truncated to protect this page.

  1diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
  2index 0c5f3aceece0233d1fc4f200136786499b31f782..361ed624be8f2aa30c7e0c75b622a42ce04fea38 100644
  3--- a/.github/CODEOWNERS
  4+++ b/.github/CODEOWNERS
  5@@ -1,13 +1,14 @@
  6 # Plugin owners
  7 plugins/archlinux/                  @ratijas
  8+plugins/dbt/                        @msempere
  9+plugins/eza/                        @pepoluan
 10 plugins/genpass/                    @atoponce
 11 plugins/git-lfs/                    @hellovietduc
 12 plugins/gitfast/                    @felipec
 13 plugins/react-native                @esthor
 14 plugins/sdk/                        @rgoldberg
 15 plugins/shell-proxy/                @septs
 16+plugins/starship/                   @axieax
 17 plugins/universalarchive/           @Konfekt
 18 plugins/wp-cli/                     @joshmedeski
 19 plugins/zoxide/                     @ajeetdsouza
 20-plugins/starship/                   @axieax
 21-plugins/dbt/                        @msempere
 22diff --git a/plugins/eza/README.md b/plugins/eza/README.md
 23new file mode 100644
 24index 0000000000000000000000000000000000000000..5de935c2c81e85827a2a17822cb2520251c006ba
 25--- /dev/null
 26+++ b/plugins/eza/README.md
 27@@ -0,0 +1,101 @@
 28+# eza plugin
 29+
 30+This provides aliases that invoke the [`eza`](https://github.com/eza-community/eza) utility rather than `ls`
 31+
 32+To use it add `eza` to the plugins array in your zshrc file:
 33+
 34+```zsh
 35+plugins=(... eza)
 36+```
 37+
 38+## Configuration
 39+
 40+All configurations are done using the `zstyle` command in the `:omz:plugins:eza` namespace.
 41+
 42+**NOTE:** The configuring needs to be done prior to OMZ loading the plugins. When the plugin is loaded,
 43+changing the `zstyle` won't have any effect.
 44+
 45+### `dirs-first`
 46+
 47+```zsh
 48+zstyle ':omz:plugins:eza' 'dirs-first' yes|no
 49+```
 50+
 51+If `yes`, directories will be grouped first.
 52+
 53+Default: `no`
 54+
 55+### `git-status`
 56+
 57+```zsh
 58+zstyle ':omz:plugins:eza' 'git-status' yes|no
 59+```
 60+
 61+If `yes`, always add `--git` flag to indicate git status (if tracked / in a git repo).
 62+
 63+Default: `no`
 64+
 65+### `header`
 66+
 67+```zsh
 68+zstyle ':omz:plugins:eza' 'header' yes|no
 69+```
 70+
 71+If `yes`, always add `-h` flag to add a header row for each column.
 72+
 73+Default: `no`
 74+
 75+### `show-group`
 76+
 77+```zsh
 78+zstyle ':omz:plugins:eza' 'show-group' yes|no
 79+```
 80+
 81+If `yes` (default), always add `-g` flag to show the group ownership.
 82+
 83+Default: `yes`
 84+
 85+### `size-prefix`
 86+
 87+```zsh
 88+zstyle ':omz:plugins:eza' 'size-prefix' (binary|none|si)
 89+```
 90+
 91+Choose the prefix to be used in displaying file size:
 92+
 93+- `binary` -- use [binary prefixes](https://en.wikipedia.org/wiki/Binary_prefix) such as "Ki", "Mi", "Gi" and
 94+  so on
 95+- `none` -- don't use any prefix, show size in bytes
 96+- `si` (default) -- use [Metric/S.I. prefixes](https://en.wikipedia.org/wiki/Metric_prefix)
 97+
 98+Default: `si`
 99+
100+### `time-style`
101+
102+```zsh
103+zstyle ':omz:plugins:eza' 'time-style' $TIME_STYLE
104+```
105+
106+Sets the `--time-style` option of `eza`. (See `man eza` for the options)
107+
108+Default: Not set, which means the default behavior of `eza` will take place.
109+
110+## Aliases
111+
112+**Notes:**
113+
114+- Aliases may be modified by Configuration
115+- The term "files" without "only" qualifier means both files & directories
116+
117+| Alias  | Command           | Description                                                                |
118+| ------ | ----------------- | -------------------------------------------------------------------------- |
119+| `la`   | `eza -la`         | List all files (except . and ..) as a long list                            |
120+| `ldot` | `eza -ld .*`      | List dotfiles only (directories shown as entries instead of recursed into) |
121+| `lD`   | `eza -lD`         | List only directories (excluding dotdirs) as a long list                   |
122+| `lDD`  | `eza -laD`        | List only directories (including dotdirs) as a long list                   |
123+| `ll`   | `eza -l`          | List files as a long list                                                  |
124+| `ls`   | `eza`             | Plain eza call                                                             |
125+| `lsd`  | `eza -d`          | List specified files with directories as entries, in a grid                |
126+| `lsdl` | `eza -dl`         | List specified files with directories as entries, in a long list           |
127diff --git a/plugins/eza/eza.plugin.zsh b/plugins/eza/eza.plugin.zsh
128new file mode 100644
129index 0000000000000000000000000000000000000000..6d7f720bd98d0fe7135ec56ef04381ce725a4a91
130--- /dev/null
131+++ b/plugins/eza/eza.plugin.zsh
132@@ -0,0 +1,62 @@
133+if ! (( $+commands[eza] )); then
134+  print "zsh eza plugin: eza not found. Please install eza before using this plugin." >&2
135+  return 1
136+fi
137+
138+typeset -a _EZA_HEAD
139+typeset -a _EZA_TAIL
140+
141+function _configure_eza() {
142+  local _val
143+  # Get the head flags
144+  if zstyle -T ':omz:plugins:eza' 'show-group'; then
145+    _EZA_HEAD+=("g")
146+  fi
147+  if zstyle -t ':omz:plugins:eza' 'header'; then
148+    _EZA_HEAD+=("h")
149+  fi
150+  zstyle -s ':omz:plugins:eza' 'size-prefix' _val
151+  case "${_val:l}" in
152+    binary)
153+      _EZA_HEAD+=("b")
154+      ;;
155+    none)
156+      _EZA_HEAD+=("B")
157+      ;;
158+  esac
159+  # Get the tail long-options
160+  if zstyle -t ':omz:plugins:eza' 'dirs-first'; then
161+    _EZA_TAIL+=("--group-directories-first")
162+  fi
163+  if zstyle -t ':omz:plugins:eza' 'git-status'; then
164+    _EZA_TAIL+=("--git")
165+  fi
166+  zstyle -s ':omz:plugins:eza' 'time-style' _val
167+  if [[ $_val ]]; then
168+    _EZA_TAIL+=("--time-style='$_val'")
169+  fi
170+}
171+
172+_configure_eza
173+
174+function _alias_eza() {
175+  local _head="${(j::)_EZA_HEAD}$2"
176+  local _tail="${(j: :)_EZA_TAIL}"
177+  alias "$1"="eza${_head:+ -}${_head}${_tail:+ }${_tail}${3:+ }$3"
178+}
179+
180+_alias_eza la   la
181+_alias_eza ldot ld ".*"
182+_alias_eza lD   lD
183+_alias_eza lDD  lDa
184+_alias_eza ll   l
185+_alias_eza ls
186+_alias_eza lsd  d
187+_alias_eza lsdl dl
188+_alias_eza lS   "l -ssize"
189+_alias_eza lT   "l -snewest"
190+
191+unfunction _alias_eza
192+unfunction _configure_eza
193+unset _EZA_HEAD
194+unset _EZA_TAIL