f4423ebd09fbc7670815c3c20cc86c81b7319e5f
- Author
- Marc Cornellà <marc@mcornella.com>
- Committer
- Marc Cornellà <marc@mcornella.com>
- Date
Message
feat(cli): style plugin README in `omz plugin info`
Diff
1diff --git a/lib/cli.zsh b/lib/cli.zsh
2index 383b0cfb04c33edee171b6eeafb65158ebf193d3..d1896f18dcbe65782ad2089465c23700f01b2752 100644
3--- a/lib/cli.zsh
4+++ b/lib/cli.zsh
5@@ -397,8 +397,23 @@ function _omz::plugin::info {
6 local readme
7 for readme in "$ZSH_CUSTOM/plugins/$1/README.md" "$ZSH/plugins/$1/README.md"; do
8 if [[ -f "$readme" ]]; then
9- (( ${+commands[less]} )) && less "$readme" || cat "$readme"
10- return 0
11+ # If being piped, just cat the README
12+ if [[ ! -t 1 ]]; then
13+ cat "$readme"
14+ return $?
15+ fi
16+
17+ # Enrich the README display depending on the tools we have
18+ # - glow: https://github.com/charmbracelet/glow
19+ # - bat: https://github.com/sharkdp/bat
20+ # - less: typical pager command
21+ case 1 in
22+ ${+commands[glow]}) glow -p "$readme" ;;
23+ ${+commands[bat]}) bat -l md --style plain "$readme" ;;
24+ ${+commands[less]}) less "$readme" ;;
25+ *) cat "$readme" ;;
26+ esac
27+ return $?
28 fi
29 done
30