From f4119b659bed4bc18c9e70e2073e342ae6b8d8f6 Mon Sep 17 00:00:00 2001 From: Wu Zhenyu Date: Sun, 11 Feb 2024 22:15:08 +0800 Subject: [PATCH] :children_crossing: Improve mdcat() --- README.md | 3 ++- functions/main.zsh | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2c13f33..c976a3c 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,8 @@ You need some optional tools: - [pandoc](https://github.com/jgm/pandoc): convert any kind of file to markdown. Any generated cache file will be store in same `/tmp/zsh-fzf-tab-$USER` as [fzf-tab](https://github.com/Aloxaf/fzf-tab) -- [mdcat](https://github.com/swsnr/mdcat): render markdown +- render markdown: Refer + - [grc](https://github.com/garabik/grc): colorize the output of some commands - [less](https://github.com/vbwagner/less): a pager diff --git a/functions/main.zsh b/functions/main.zsh index b685664..a24f74e 100644 --- a/functions/main.zsh +++ b/functions/main.zsh @@ -1,14 +1,23 @@ # define some functions to avoid any error that these programs don't exist # treat bat -lXXX as cat -(($+commands[bat])) && bat() {command bat --color=always -p $@} || - bat() {command cat} -(($+commands[pandoc])) || pandoc() {command cat ${@[-1]}} -(($+commands[mdcat])) || mdcat() {bat -lmarkdown} -(($+commands[grc])) || grc() {eval ${@[2,-1]}} +# currently, only bat supports highlight --help +(($+commands[bat])) && bat() {command bat --color=always -p $@} || bat() {command cat} +if ((! $+commands[mdcat])); then + if (($+commands[paper])); then + mdcat() {command paper $@} + elif (($+commands[mdless])); then + mdcat() {command mdless $@} + else + # use bat() as fallback + mdcat() {bat -lmarkdown} + fi +fi if ((! $+commands[finger])); then (($+commands[pinky])) && finger() {command pinky $@} || finger() {command whoami} fi +(($+commands[pandoc])) || pandoc() {command cat ${@[-1]}} +(($+commands[grc])) || grc() {eval ${@[2,-1]}} # https://github.com/Freed-Wu/fzf-tab-source/issues/6 if (($+commands[less])) && [ -x ~/.lessfilter ]; then less() {~/.lessfilter $@ || command less $@}