-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make better preview displays in terminals (#758)
* Implement markdown renderer for terminal * Implement preview command for file|mime types * Introduce preview command into walk command * Drop to support KDL for now * Replace renmark with mdcat in preview command to support darwin * I might add poppler in another PR for yazi PDF preview
- Loading branch information
Showing
9 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,8 @@ | |
"nix-hash-url" | ||
"trim-github-user-prefix-for-reponame" | ||
"gredit" | ||
"renmark" | ||
"preview" | ||
] | ||
) | ||
++ [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ pkgs, ... }: | ||
pkgs.writeShellApplication rec { | ||
name = "preview"; | ||
text = builtins.readFile ./${name}.bash; | ||
# TODO: Support KDL highlight | ||
# - bat does not support KDL, however TUI editors with pipe is not to be easy handled | ||
# - Helix does not have readonly mode and the KDL highlighting is not correct | ||
# https://github.com/helix-editor/helix/discussions/9245 | ||
# - micro https://github.com/kachick/micro-kdl | ||
# - vim https://github.com/imsnif/kdl.vim | ||
runtimeInputs = | ||
(with pkgs; [ | ||
file # Detect file/mime type | ||
coreutils # For `basename` | ||
bat # code | ||
hexyl # binary | ||
# libsixel | ||
mdcat # markdown - Avoid renmark to keep compatibility in darwin | ||
]) | ||
++ [ | ||
(import ../la { inherit pkgs; }) # directory | ||
]; | ||
# Especially provided for fzf: https://github.com/junegunn/fzf/issues/2855#issuecomment-1164015794 | ||
meta.description = "Run preview commands that are suitable for the file type"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
path="$1" | ||
filename=$(basename -- "$path") | ||
extension="${filename##*.}" | ||
|
||
case "$(file --dereference --brief --mime-type "$path")" in | ||
text/html) | ||
cha "$path" | ||
;; | ||
text/*) | ||
case "$extension" in | ||
md | markdown) | ||
mdcat "$path" | ||
;; | ||
*) | ||
bat --color=always "$path" | ||
;; | ||
esac | ||
;; | ||
inode/directory) | ||
la "$path" | ||
;; | ||
application/x-executable) | ||
hexyl "$path" | ||
;; | ||
# image/*) | ||
# # TODO: Support images/PDF after using sixel supported terminals for main. Alacritty isn't | ||
# # https://github.com/alacritty/alacritty/issues/910 | ||
# img2sixel "$path" | ||
# ;; | ||
*) | ||
bat --color=always "$path" | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ pkgs, ... }: | ||
pkgs.writeShellApplication rec { | ||
name = "renmark"; | ||
text = builtins.readFile ./${name}.bash; | ||
# Old candidates | ||
# - glow, pandoc, inlyne, chawan built-in markdown renderer, mdcat, gh-markdown-preview, Lynx, w3m | ||
# | ||
# After several candidates, I think this combination is the best for now. | ||
runtimeInputs = with pkgs; [ | ||
chawan | ||
comrak | ||
]; | ||
meta.description = "RENder MARkdown in terminal. See GH-740"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
comrak "$@" | cha --type 'text/html' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters