Skip to content

Commit

Permalink
🚸 Improve mdcat()
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Feb 11, 2024
1 parent 9b382d5 commit f4119b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://github.com/foxfriends/paper-terminal#comparison-with-other-command-line-markdown-renderers>
- [grc](https://github.com/garabik/grc): colorize the output of some commands
- [less](https://github.com/vbwagner/less): a pager

Expand Down
19 changes: 14 additions & 5 deletions functions/main.zsh
Original file line number Diff line number Diff line change
@@ -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 $@}
Expand Down

0 comments on commit f4119b6

Please sign in to comment.