From 6e91ecb14fdbb35b3659fe3ad8deb60d96b28e76 Mon Sep 17 00:00:00 2001 From: Marie-Helene Burle Date: Thu, 30 May 2019 17:16:33 -0700 Subject: Add preview support to .rtf, .doc, .docx, .xlsx, .xls --- ranger/data/scope.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index ae09fe39..da467efa 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -85,6 +85,31 @@ handle_extension() { odt2txt "${FILE_PATH}" && exit 5 exit 1;; + ## RTF and DOC + rtf|doc) + ## Preview as markdown conversion + ## note: catdoc does not always work for .doc files + catdoc "${FILE_PATH}" && exit 5 + exit 1;; + + ## DOCX + docx) + ## Preview as markdown conversion + pandoc -t markdown "${FILE_PATH}" && exit 5 + exit 1;; + + ## XLSX + xlsx) + ## Preview as csv conversion + xlsx2csv "${FILE_PATH}" && exit 5 + exit 1;; + + ## XLS + xls) + ## Preview as csv conversion + xls2csv "${FILE_PATH}" && exit 5 + exit 1;; + ## HTML htm|html|xhtml) ## Preview as text conversion @@ -304,7 +329,6 @@ handle_fallback() { exit 1 } - MIMETYPE="$( file --dereference --brief --mime-type -- "${FILE_PATH}" )" if [[ "${PV_IMAGE_ENABLED}" == 'True' ]]; then handle_image "${MIMETYPE}" -- cgit 1.4.1-2-gfad0 From 7739de585d5b61e48728461a74c5ea6d80485be8 Mon Sep 17 00:00:00 2001 From: Marie-Helene Burle Date: Thu, 30 May 2019 17:31:15 -0700 Subject: Fix typo in a comment of previous commit --- ranger/data/scope.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index da467efa..f9b9498b 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -87,7 +87,7 @@ handle_extension() { ## RTF and DOC rtf|doc) - ## Preview as markdown conversion + ## Preview as text conversion ## note: catdoc does not always work for .doc files catdoc "${FILE_PATH}" && exit 5 exit 1;; -- cgit 1.4.1-2-gfad0 From 2b50f82faa04838f78bc8de5dc33d4a106e50461 Mon Sep 17 00:00:00 2001 From: Marie-Helene Burle Date: Fri, 31 May 2019 11:03:03 -0700 Subject: Add information on how to get xls2csv and xlsx2csv applications --- ranger/data/scope.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index f9b9498b..9a9f5160 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -89,6 +89,7 @@ handle_extension() { rtf|doc) ## Preview as text conversion ## note: catdoc does not always work for .doc files + ## catdoc: http://www.wagner.pp.ru/~vitus/software/catdoc/ catdoc "${FILE_PATH}" && exit 5 exit 1;; @@ -101,12 +102,15 @@ handle_extension() { ## XLSX xlsx) ## Preview as csv conversion + ## Uses: https://github.com/dilshod/xlsx2csv xlsx2csv "${FILE_PATH}" && exit 5 exit 1;; ## XLS xls) ## Preview as csv conversion + ## xls2csv comes with catdoc: + ## http://www.wagner.pp.ru/~vitus/software/catdoc/ xls2csv "${FILE_PATH}" && exit 5 exit 1;; -- cgit 1.4.1-2-gfad0 From 600347778cddcbaf3f7b0ff5924fdec94fe501de Mon Sep 17 00:00:00 2001 From: Marie-Helene Burle Date: Fri, 31 May 2019 18:12:10 -0700 Subject: Add -s flag to pandoc By default, pandoc produces a document fragment. Adding the --standalone flag allows to get the title of the document. --- ranger/data/scope.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index 9a9f5160..2cba7d0e 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -96,7 +96,7 @@ handle_extension() { ## DOCX docx) ## Preview as markdown conversion - pandoc -t markdown "${FILE_PATH}" && exit 5 + pandoc -s -t markdown "${FILE_PATH}" && exit 5 exit 1;; ## XLSX -- cgit 1.4.1-2-gfad0 From f6d7d5ca4b07f7d8687e3121877f329d1c64d791 Mon Sep 17 00:00:00 2001 From: Marie-Helene Burle Date: Sat, 1 Jun 2019 10:27:01 -0700 Subject: Add pandoc support for odt, epub, and fb2 --- ranger/data/scope.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index 2cba7d0e..1fde1de5 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -85,6 +85,12 @@ handle_extension() { odt2txt "${FILE_PATH}" && exit 5 exit 1;; + ## ODT (using pandoc) + # odt) + # # Preview as markdown conversion + # pandoc -s -t markdown "${FILE_PATH}" && exit 5 + # exit 1;; + ## RTF and DOC rtf|doc) ## Preview as text conversion @@ -93,8 +99,10 @@ handle_extension() { catdoc "${FILE_PATH}" && exit 5 exit 1;; - ## DOCX - docx) + ## DOCX, EPUB, FB2 (using pandoc) + ## you might want to remove EPUB and/or FB2 if you have uncommented + ## other methods to preview those formats + docx|epub|fb2) ## Preview as markdown conversion pandoc -s -t markdown "${FILE_PATH}" && exit 5 exit 1;; -- cgit 1.4.1-2-gfad0 From 42a5cff42021b75f3a9efd4ad126dba5add9c4a9 Mon Sep 17 00:00:00 2001 From: Marie-Helene Burle Date: Sat, 1 Jun 2019 10:37:48 -0700 Subject: More sensible way to add pandoc support for ePub, FB2, and ODT --- ranger/data/scope.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index 1fde1de5..56ec51fb 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -83,6 +83,7 @@ handle_extension() { odt|ods|odp|sxw) ## Preview as text conversion odt2txt "${FILE_PATH}" && exit 5 + pandoc -s -t markdown "${FILE_PATH}" && exit 5 exit 1;; ## ODT (using pandoc) @@ -102,7 +103,7 @@ handle_extension() { ## DOCX, EPUB, FB2 (using pandoc) ## you might want to remove EPUB and/or FB2 if you have uncommented ## other methods to preview those formats - docx|epub|fb2) + docx) ## Preview as markdown conversion pandoc -s -t markdown "${FILE_PATH}" && exit 5 exit 1;; @@ -207,6 +208,12 @@ handle_image() { # >/dev/null && exit 6 # exit 1;; + # ePub, FB2 (using pandoc) + # epub|fb2) + # # Preview as markdown conversion + # pandoc -s -t markdown "${FILE_PATH}" && exit 5 + # exit 1;; + ## Font application/font*|application/*opentype) preview_png="/tmp/$(basename "${IMAGE_CACHE_PATH%.*}").png" -- cgit 1.4.1-2-gfad0 From 6dd43b8854affba979b75783d84b06aa15ca915b Mon Sep 17 00:00:00 2001 From: Marie-Helene Burle Date: Sat, 1 Jun 2019 10:40:40 -0700 Subject: Fix minor comment inconsistency --- ranger/data/scope.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index 56ec51fb..bad000a3 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -83,6 +83,7 @@ handle_extension() { odt|ods|odp|sxw) ## Preview as text conversion odt2txt "${FILE_PATH}" && exit 5 + # Preview as markdown conversion pandoc -s -t markdown "${FILE_PATH}" && exit 5 exit 1;; -- cgit 1.4.1-2-gfad0 From f090ef18c29ba5de0098ad54f87f84ef6f536086 Mon Sep 17 00:00:00 2001 From: Marie-Helene Burle Date: Sat, 1 Jun 2019 11:01:08 -0700 Subject: Move pandoc support for ePub and FB2 back to handle_extension() --- ranger/data/scope.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index bad000a3..bf8cdd36 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -104,7 +104,7 @@ handle_extension() { ## DOCX, EPUB, FB2 (using pandoc) ## you might want to remove EPUB and/or FB2 if you have uncommented ## other methods to preview those formats - docx) + docx|epub|fb2) ## Preview as markdown conversion pandoc -s -t markdown "${FILE_PATH}" && exit 5 exit 1;; @@ -209,13 +209,6 @@ handle_image() { # >/dev/null && exit 6 # exit 1;; - # ePub, FB2 (using pandoc) - # epub|fb2) - # # Preview as markdown conversion - # pandoc -s -t markdown "${FILE_PATH}" && exit 5 - # exit 1;; - - ## Font application/font*|application/*opentype) preview_png="/tmp/$(basename "${IMAGE_CACHE_PATH%.*}").png" if fontimage -o "${preview_png}" \ -- cgit 1.4.1-2-gfad0 From e30459d31a61a1baf05b72880b743878dbdbe86c Mon Sep 17 00:00:00 2001 From: Marie-Helene Burle Date: Sat, 1 Jun 2019 11:07:06 -0700 Subject: Minor change in comment --- ranger/data/scope.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index bf8cdd36..ff7aa85e 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -101,9 +101,9 @@ handle_extension() { catdoc "${FILE_PATH}" && exit 5 exit 1;; - ## DOCX, EPUB, FB2 (using pandoc) - ## you might want to remove EPUB and/or FB2 if you have uncommented - ## other methods to preview those formats + ## DOCX, ePub, FB2 (using markdown) + ## You might want to remove "|epub" and/or "|fb2" below if you have + ## uncommented other methods to preview those formats docx|epub|fb2) ## Preview as markdown conversion pandoc -s -t markdown "${FILE_PATH}" && exit 5 -- cgit 1.4.1-2-gfad0 From b1e6eeeb602978c343a5c2a6284a2e26786099c8 Mon Sep 17 00:00:00 2001 From: Marie-Helene Burle Date: Sat, 1 Jun 2019 17:11:17 -0700 Subject: Add '--', empty lines, and pandoc fallback support for html and json --- ranger/data/scope.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index ff7aa85e..94257d0a 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -47,6 +47,7 @@ PYGMENTIZE_STYLE=${PYGMENTIZE_STYLE:-autumn} OPENSCAD_IMGSIZE=${RNGR_OPENSCAD_IMGSIZE:-1000,1000} OPENSCAD_COLORSCHEME=${RNGR_OPENSCAD_COLORSCHEME:-Tomorrow Night} + handle_extension() { case "${FILE_EXTENSION_LOWER}" in ## Archive @@ -84,7 +85,7 @@ handle_extension() { ## Preview as text conversion odt2txt "${FILE_PATH}" && exit 5 # Preview as markdown conversion - pandoc -s -t markdown "${FILE_PATH}" && exit 5 + pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 exit 1;; ## ODT (using pandoc) @@ -98,7 +99,7 @@ handle_extension() { ## Preview as text conversion ## note: catdoc does not always work for .doc files ## catdoc: http://www.wagner.pp.ru/~vitus/software/catdoc/ - catdoc "${FILE_PATH}" && exit 5 + catdoc -- "${FILE_PATH}" && exit 5 exit 1;; ## DOCX, ePub, FB2 (using markdown) @@ -106,14 +107,14 @@ handle_extension() { ## uncommented other methods to preview those formats docx|epub|fb2) ## Preview as markdown conversion - pandoc -s -t markdown "${FILE_PATH}" && exit 5 + pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 exit 1;; ## XLSX xlsx) ## Preview as csv conversion ## Uses: https://github.com/dilshod/xlsx2csv - xlsx2csv "${FILE_PATH}" && exit 5 + xlsx2csv -- "${FILE_PATH}" && exit 5 exit 1;; ## XLS @@ -121,7 +122,7 @@ handle_extension() { ## Preview as csv conversion ## xls2csv comes with catdoc: ## http://www.wagner.pp.ru/~vitus/software/catdoc/ - xls2csv "${FILE_PATH}" && exit 5 + xls2csv -- "${FILE_PATH}" && exit 5 exit 1;; ## HTML @@ -130,12 +131,14 @@ handle_extension() { w3m -dump "${FILE_PATH}" && exit 5 lynx -dump -- "${FILE_PATH}" && exit 5 elinks -dump "${FILE_PATH}" && exit 5 - ;; + pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 + ;; ## JSON json) jq --color-output . "${FILE_PATH}" && exit 5 python -m json.tool -- "${FILE_PATH}" && exit 5 + pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 ;; ## Direct Stream Digital/Transfer (DSDIFF) and wavpack aren't detected @@ -342,6 +345,7 @@ handle_fallback() { exit 1 } + MIMETYPE="$( file --dereference --brief --mime-type -- "${FILE_PATH}" )" if [[ "${PV_IMAGE_ENABLED}" == 'True' ]]; then handle_image "${MIMETYPE}" -- cgit 1.4.1-2-gfad0 From 0af275b0b36a7c48390ad468dec39530663305a5 Mon Sep 17 00:00:00 2001 From: Marie-Helene Burle Date: Sun, 2 Jun 2019 13:03:52 -0700 Subject: remove pandoc fallback support for json files --- ranger/data/scope.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index 94257d0a..b041b6ea 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -138,7 +138,6 @@ handle_extension() { json) jq --color-output . "${FILE_PATH}" && exit 5 python -m json.tool -- "${FILE_PATH}" && exit 5 - pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 ;; ## Direct Stream Digital/Transfer (DSDIFF) and wavpack aren't detected -- cgit 1.4.1-2-gfad0 From 7615fdde77757dee3cf5479f1b1533340d482da3 Mon Sep 17 00:00:00 2001 From: toonn Date: Mon, 30 Dec 2019 20:31:56 +0100 Subject: Move new methods to handle_mime The MIME type handler is preferable because it can match files that have the "wrong" extension or a ".backup" suffix for example. Fixes #1633 --- ranger/data/scope.sh | 77 ++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index b041b6ea..eb8b6348 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -47,7 +47,6 @@ PYGMENTIZE_STYLE=${PYGMENTIZE_STYLE:-autumn} OPENSCAD_IMGSIZE=${RNGR_OPENSCAD_IMGSIZE:-1000,1000} OPENSCAD_COLORSCHEME=${RNGR_OPENSCAD_COLORSCHEME:-Tomorrow Night} - handle_extension() { case "${FILE_EXTENSION_LOWER}" in ## Archive @@ -84,55 +83,18 @@ handle_extension() { odt|ods|odp|sxw) ## Preview as text conversion odt2txt "${FILE_PATH}" && exit 5 - # Preview as markdown conversion - pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 + ## Preview as markdown conversion + pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 exit 1;; - ## ODT (using pandoc) - # odt) - # # Preview as markdown conversion - # pandoc -s -t markdown "${FILE_PATH}" && exit 5 - # exit 1;; - - ## RTF and DOC - rtf|doc) - ## Preview as text conversion - ## note: catdoc does not always work for .doc files - ## catdoc: http://www.wagner.pp.ru/~vitus/software/catdoc/ - catdoc -- "${FILE_PATH}" && exit 5 - exit 1;; - - ## DOCX, ePub, FB2 (using markdown) - ## You might want to remove "|epub" and/or "|fb2" below if you have - ## uncommented other methods to preview those formats - docx|epub|fb2) - ## Preview as markdown conversion - pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 - exit 1;; - - ## XLSX - xlsx) - ## Preview as csv conversion - ## Uses: https://github.com/dilshod/xlsx2csv - xlsx2csv -- "${FILE_PATH}" && exit 5 - exit 1;; - - ## XLS - xls) - ## Preview as csv conversion - ## xls2csv comes with catdoc: - ## http://www.wagner.pp.ru/~vitus/software/catdoc/ - xls2csv -- "${FILE_PATH}" && exit 5 - exit 1;; - ## HTML htm|html|xhtml) ## Preview as text conversion w3m -dump "${FILE_PATH}" && exit 5 lynx -dump -- "${FILE_PATH}" && exit 5 elinks -dump "${FILE_PATH}" && exit 5 - pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 - ;; + pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 + ;; ## JSON json) @@ -295,6 +257,37 @@ handle_image() { handle_mime() { local mimetype="${1}" case "${mimetype}" in + ## RTF and DOC + text/rtf|*/msword) + ## Preview as text conversion + ## note: catdoc does not always work for .doc files + ## catdoc: http://www.wagner.pp.ru/~vitus/software/catdoc/ + catdoc -- "${FILE_PATH}" && exit 5 + exit 1;; + + ## DOCX, ePub, FB2 (using markdown) + ## You might want to remove "|epub" and/or "|fb2" below if you have + ## uncommented other methods to preview those formats + *wordprocessingml.document|*/epub+zip|*/x-fictionbook+xml) + ## Preview as markdown conversion + pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 + exit 1;; + + ## XLSX + *spreadsheetml.sheet) + ## Preview as csv conversion + ## Uses: https://github.com/dilshod/xlsx2csv + xlsx2csv -- "${FILE_PATH}" && exit 5 + exit 1;; + + ## XLS + */ms-excel) + ## Preview as csv conversion + ## xls2csv comes with catdoc: + ## http://www.wagner.pp.ru/~vitus/software/catdoc/ + xls2csv -- "${FILE_PATH}" && exit 5 + exit 1;; + ## Text text/* | */xml) ## Syntax highlight -- cgit 1.4.1-2-gfad0 From b3c1bedb1edb66408501719558f903850f6ab771 Mon Sep 17 00:00:00 2001 From: toonn Date: Mon, 30 Dec 2019 21:01:51 +0100 Subject: Move xlsx back to handle_extension Xlsx files aren't properly recognized by `file(1)`. --- ranger/data/scope.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh index eb8b6348..f403ed83 100755 --- a/ranger/data/scope.sh +++ b/ranger/data/scope.sh @@ -87,6 +87,13 @@ handle_extension() { pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 exit 1;; + ## XLSX + xlsx) + ## Preview as csv conversion + ## Uses: https://github.com/dilshod/xlsx2csv + xlsx2csv -- "${FILE_PATH}" && exit 5 + exit 1;; + ## HTML htm|html|xhtml) ## Preview as text conversion @@ -173,6 +180,7 @@ handle_image() { # >/dev/null && exit 6 # exit 1;; + ## Font application/font*|application/*opentype) preview_png="/tmp/$(basename "${IMAGE_CACHE_PATH%.*}").png" if fontimage -o "${preview_png}" \ @@ -258,7 +266,7 @@ handle_mime() { local mimetype="${1}" case "${mimetype}" in ## RTF and DOC - text/rtf|*/msword) + text/rtf|*msword) ## Preview as text conversion ## note: catdoc does not always work for .doc files ## catdoc: http://www.wagner.pp.ru/~vitus/software/catdoc/ @@ -273,15 +281,8 @@ handle_mime() { pandoc -s -t markdown -- "${FILE_PATH}" && exit 5 exit 1;; - ## XLSX - *spreadsheetml.sheet) - ## Preview as csv conversion - ## Uses: https://github.com/dilshod/xlsx2csv - xlsx2csv -- "${FILE_PATH}" && exit 5 - exit 1;; - ## XLS - */ms-excel) + *ms-excel) ## Preview as csv conversion ## xls2csv comes with catdoc: ## http://www.wagner.pp.ru/~vitus/software/catdoc/ -- cgit 1.4.1-2-gfad0