From 9fc3bd782f7b3b80d8a1280dfe285fe2ceb58923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milia=20Decaudin?= Date: Thu, 13 Feb 2025 19:48:01 -0500 Subject: [PATCH 1/3] feat(cli): add `plugin cat` command --- lib/cli.zsh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/cli.zsh b/lib/cli.zsh index 3b6308313..6bdbb9839 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -41,6 +41,7 @@ function _omz { refs=("${(@f)$(builtin cd -q "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}") _describe 'command' refs ;; plugin) subcmds=( + 'cat:Show plugin source' 'disable:Disable plugin(s)' 'enable:Enable plugin(s)' 'info:Get plugin information' @@ -203,6 +204,7 @@ Usage: ${(j: :)${(s.::.)0#_}} [options] Available commands: + cat Show the source of a plugin disable Disable plugin(s) enable Enable plugin(s) info Get information of a plugin @@ -219,6 +221,42 @@ EOF $0::$command "$@" } +function _omz::plugin::cat { + if [[ -z "$1" ]]; then + echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} " + return 1 + fi + + local plugin_source + for plugin_source in "$ZSH_CUSTOM/plugins/$1/$1.plugin.zsh" "$ZSH/plugins/$1/$1.plugin.zsh"; do + if [[ -f "$plugin_source" ]]; then + # If being piped, just cat the source + if [[ ! -t 1 ]]; then + cat "$plugin_source" + return $? + fi + + # Enrich the source display depending on the tools we have + # - glow: https://github.com/charmbracelet/glow + # - bat: https://github.com/sharkdp/bat + # - less: typical pager command + case 1 in + ${+commands[glow]}) glow -p "$plugin_source" ;; + ${+commands[bat]}) bat -l zsh --style plain "$plugin_source" ;; + ${+commands[less]}) less "$plugin_source" ;; + *) cat "$readme" ;; + esac + return $? + fi + done + + if [[ ! -d "$ZSH_CUSTOM/plugins/$1" && ! -d "$ZSH/plugins/$1" ]]; then + _omz::log error "'$1' plugin not found" + fi + + return 1 +} + function _omz::plugin::disable { if [[ -z "$1" ]]; then echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} [...]" From be58a5233cf7e519a5cb2bfb4315e20608c5c55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milia=20Decaudin?= Date: Fri, 21 Mar 2025 18:43:35 -0400 Subject: [PATCH 2/3] Change from 'cat' to 'view'. --- lib/cli.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 6bdbb9839..94ca31708 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -41,12 +41,12 @@ function _omz { refs=("${(@f)$(builtin cd -q "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}") _describe 'command' refs ;; plugin) subcmds=( - 'cat:Show plugin source' 'disable:Disable plugin(s)' 'enable:Enable plugin(s)' 'info:Get plugin information' 'list:List plugins' 'load:Load plugin(s)' + 'view:Show plugin source' ) _describe 'command' subcmds ;; pr) subcmds=('clean:Delete all Pull Request branches' 'test:Test a Pull Request') @@ -204,12 +204,12 @@ Usage: ${(j: :)${(s.::.)0#_}} [options] Available commands: - cat Show the source of a plugin disable Disable plugin(s) enable Enable plugin(s) info Get information of a plugin list List all available Oh My Zsh plugins load Load plugin(s) + view Show the source of a plugin EOF return 1 @@ -221,7 +221,7 @@ EOF $0::$command "$@" } -function _omz::plugin::cat { +function _omz::plugin::view { if [[ -z "$1" ]]; then echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} " return 1 From 73044b4eb7fc881775253c15d39eb1406571a449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milia=20Decaudin?= Date: Fri, 21 Mar 2025 18:47:56 -0400 Subject: [PATCH 3/3] Display completions from plugin if .plugin.zsh. isn't present. --- lib/cli.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli.zsh b/lib/cli.zsh index 94ca31708..194b3ee67 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -228,7 +228,7 @@ function _omz::plugin::view { fi local plugin_source - for plugin_source in "$ZSH_CUSTOM/plugins/$1/$1.plugin.zsh" "$ZSH/plugins/$1/$1.plugin.zsh"; do + for plugin_source in "$ZSH_CUSTOM/plugins/$1/$1.plugin.zsh" "$ZSH_CUSTOM/plugins/$1/_$1" "$ZSH/plugins/$1/$1.plugin.zsh" "$ZSH/plugins/$1/_$1"; do if [[ -f "$plugin_source" ]]; then # If being piped, just cat the source if [[ ! -t 1 ]]; then