我使用 Ranger 作为文件浏览器,顺便说一句,它很棒......
我有一个问题,因为 Ranger 可以显示当前所选文件的预览。这非常有用,但对于大文件来说会出现问题。实际上,对于大文件,创建预览需要花费大量时间和资源。
我的问题是:有没有办法设置 Ranger 不会尝试显示预览的最大尺寸?
我找到了解决方案,至少对于文本文件,问题出在突出显示... Ranger 试图突出显示长文件...我找到的解决方法显示在以下摘录中 ~/.config/ranger/scope.sh
#!/usr/bin/env sh
path="$1" # Full path of the selected file
width="$2" # Width of the preview pane (number of fitting characters)
height="$3" # Height of the preview pane (number of fitting characters)
maxln=54 # Stop after $maxln lines. Can be used like ls | head -n $maxln
# Find out something about the file:
mimetype=$(file --mime-type -Lb "$path")
extension=${path##*.}
try() { output=$(eval '"$@"'); }
dump() { echo "$output"; }
trim() { head -n "$maxln"; }
hl() { command head -n "$maxln" "$path" | highlight --syntax="$extension" --out-format=ansi; test $? = 0 -o $? = 141; }
case "$mimetype" in
# Syntax highlight for text files:
text/* | */xml)
try hl && { dump | trim; exit 5; } || exit 2;;
esac
exit 1
Run Code Online (Sandbox Code Playgroud)
这个想法,它只选择文本文件的第一行,然后highligh
只调用
那部分。
归档时间: |
|
查看次数: |
2554 次 |
最近记录: |