feat(ranger): codify richer previews and tooling

This commit is contained in:
m1ngsama 2026-03-17 18:15:55 +08:00
parent 0a344a6ab6
commit 7d4fd93387
4 changed files with 56 additions and 17 deletions

View file

@ -2,9 +2,9 @@
“工欲善其事,必先利其器。”
> Dotfile of the tools what I use.
> Dotfiles for the tools I use.
## Including
## Includes
- [fish](https://github.com/fish-shell/fish-shell)
@ -12,5 +12,6 @@
- [tmux](https://github.com/tmux/tmux)
- Customed Keymaps Files
- [ranger](https://github.com/ranger/ranger)
- Custom keymap files

23
ranger/README.md Normal file
View file

@ -0,0 +1,23 @@
# ranger
This directory tracks the ranger setup I actually use instead of storing a
full copy of the packaged defaults.
## Files
- `rc.conf`: minimal overrides on top of ranger's built-in defaults
- `scope.sh`: richer previews for images, video, PDF, archives, and text
## Recommended packages on Arch Linux
```bash
sudo pacman -S --needed \
ranger ueberzugpp chafa ffmpegthumbnailer mediainfo highlight atool \
perl-image-exiftool w3m mpv trash-cli unrar poppler imagemagick bat jq file
```
## Notes
- `preview_images_method ueberzug` works well in X11 terminals such as Alacritty.
- `chafa` provides a readable fallback when graphical image previews are unavailable.
- `trash-cli` powers the `dt` and `dT` key bindings in `rc.conf`.

14
ranger/rc.conf Normal file
View file

@ -0,0 +1,14 @@
# Minimal ranger overrides on top of the built-in defaults.
set use_preview_script true
set preview_script ~/.config/ranger/scope.sh
set vcs_aware true
set preview_images true
set preview_images_method ueberzug
set collapse_preview false
set wrap_plaintext_previews true
set draw_borders both
# Prefer trash over permanent deletion for routine cleanup.
map dt shell -w trash-put -- %s
map dT shell -w trash-restore

View file

@ -162,20 +162,21 @@ handle_image() {
;;
## Video
# video/*)
# # Thumbnail
# ffmpegthumbnailer -i "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" -s 0 && exit 6
# exit 1;;
video/*)
ffmpegthumbnailer -i "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" -s 0 && exit 6
exit 1
;;
## PDF
# application/pdf)
# pdftoppm -f 1 -l 1 \
# -scale-to-x "${DEFAULT_SIZE%x*}" \
# -scale-to-y -1 \
# -singlefile \
# -jpeg -tiffcompression jpeg \
# -- "${FILE_PATH}" "${IMAGE_CACHE_PATH%.*}" \
# && exit 6 || exit 1;;
application/pdf)
pdftoppm -f 1 -l 1 \
-scale-to-x "${DEFAULT_SIZE%x*}" \
-scale-to-y -1 \
-singlefile \
-jpeg -tiffcompression jpeg \
-- "${FILE_PATH}" "${IMAGE_CACHE_PATH%.*}" &&
exit 6 || exit 1
;;
## ePub, MOBI, FB2 (using Calibre)
# application/epub+zip|application/x-mobipocket-ebook|\
@ -331,8 +332,8 @@ handle_mime() {
## Image
image/*)
## Preview as text conversion
# img2txt --gamma=0.6 --width="${PV_WIDTH}" -- "${FILE_PATH}" && exit 4
chafa --animate=off --size="${PV_WIDTH}x${PV_HEIGHT}" \
--symbols=block -- "${FILE_PATH}" && exit 4
exiftool "${FILE_PATH}" && exit 5
exit 1
;;