From 266ed12cdbdfc27fb8401cd7d0f9d18af717a840 Mon Sep 17 00:00:00 2001 From: Nikita Ivanov Date: Wed, 1 Jun 2022 21:09:33 +0500 Subject: [PATCH] Split prev/text.sh into 4 different previews --- prev/bat.sh | 15 +++++++++++++++ prev/cat.sh | 1 + prev/highlight.sh | 3 +++ prev/source_highlight.sh | 3 +++ prev/text.sh | 27 --------------------------- previews.h | 5 ++++- 6 files changed, 26 insertions(+), 28 deletions(-) create mode 100644 prev/bat.sh create mode 100644 prev/cat.sh create mode 100644 prev/highlight.sh create mode 100644 prev/source_highlight.sh delete mode 100644 prev/text.sh diff --git a/prev/bat.sh b/prev/bat.sh new file mode 100644 index 0000000..b3a14cc --- /dev/null +++ b/prev/bat.sh @@ -0,0 +1,15 @@ +if exists bat; then + batcmd=bat +elif exists batcat; then + batcmd=batcat +else + exit 127 +fi + +"$batcmd" \ + --color always \ + --style plain \ + --paging never \ + --terminal-width "$w" \ + --wrap character \ + -- "$f" diff --git a/prev/cat.sh b/prev/cat.sh new file mode 100644 index 0000000..926d339 --- /dev/null +++ b/prev/cat.sh @@ -0,0 +1 @@ +cat "$f" diff --git a/prev/highlight.sh b/prev/highlight.sh new file mode 100644 index 0000000..30ffe1c --- /dev/null +++ b/prev/highlight.sh @@ -0,0 +1,3 @@ +highlight \ + --replace-tabs=4 --out-format=ansi \ + --style='pablo' --force -- "$f" diff --git a/prev/source_highlight.sh b/prev/source_highlight.sh new file mode 100644 index 0000000..7dfb8a5 --- /dev/null +++ b/prev/source_highlight.sh @@ -0,0 +1,3 @@ +source-highlight \ + --tab=4 --out-format=esc \ + --style=esc256.style --failsafe -i "$f" diff --git a/prev/text.sh b/prev/text.sh deleted file mode 100644 index 9461dc1..0000000 --- a/prev/text.sh +++ /dev/null @@ -1,27 +0,0 @@ -if exists bat; then - batcmd=bat -elif exists batcat; then - batcmd=batcat -else - batcmd= -fi - -if [ -n "$batcmd" ]; then - "$batcmd" \ - --color always \ - --style plain \ - --paging never \ - --terminal-width "$w" \ - --wrap character \ - -- "$f" -elif exists highlight; then - highlight \ - --replace-tabs=4 --out-format=ansi \ - --style='pablo' --force -- "$f" -elif exists source-highlight; then - source-highlight \ - --tab=4 --out-format=esc \ - --style=esc256.style --failsafe -i "$f" -else - cat "$f" -fi diff --git a/previews.h b/previews.h index 044a9f0..35236d3 100644 --- a/previews.h +++ b/previews.h @@ -15,7 +15,10 @@ Preview previews[] = { PP(NULL, NULL, NULL, wrapper, INT_MAX), - PR(NULL, "text", NULL, text), + PR(NULL, "text", NULL, bat), + PR(NULL, "text", NULL, highlight), + PR(NULL, "text", NULL, source_highlight), + PR(NULL, "text", NULL, cat), PR(NULL, NULL, NULL, any), PR("md", NULL, NULL, markdown), PR(NULL, "application", "json", json),