This commit is contained in:
m1ngsama 2026-03-29 00:21:49 +00:00 committed by GitHub
commit 83744c1545
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 244 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,12 @@
- [tmux](https://github.com/tmux/tmux)
- Customed Keymaps Files
- [ranger](https://github.com/ranger/ranger)
- Custom keymap files
## Quick start
```bash
./scripts/install-ranger.sh
```

36
ranger/README.md Normal file
View file

@ -0,0 +1,36 @@
# 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
```
## Install
```bash
./scripts/install-ranger.sh
```
Useful options:
- `./scripts/install-ranger.sh --dry-run`
- `./scripts/install-ranger.sh --copy`
- `./scripts/install-ranger.sh --target-dir ~/.config/ranger`
## 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`.
- Existing `rc.conf` and `scope.sh` files are backed up under `~/.local/state/dotfiles-backups/ranger/`.

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
;;

169
scripts/install-ranger.sh Executable file
View file

@ -0,0 +1,169 @@
#!/usr/bin/env bash
set -euo pipefail
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
repo_root="$(cd -- "${script_dir}/.." && pwd)"
source_dir="${repo_root}/ranger"
target_dir="${XDG_CONFIG_HOME:-${HOME}/.config}/ranger"
state_dir="${XDG_STATE_HOME:-${HOME}/.local/state}/dotfiles-backups/ranger"
backup_dir=""
mode="link"
dry_run="false"
files=(
"rc.conf"
"scope.sh"
)
usage() {
cat <<'EOF'
Usage: install-ranger.sh [options]
Install the tracked ranger configuration into ~/.config/ranger.
Options:
--copy Copy files instead of creating symlinks
--link Create symlinks (default)
--dry-run Print the planned actions without changing anything
--target-dir <path> Override the install target directory
-h, --help Show this help message
EOF
}
log() {
printf '%s\n' "$*"
}
run() {
if [[ "${dry_run}" == "true" ]]; then
printf '[dry-run] %s\n' "$*"
return 0
fi
"$@"
}
ensure_backup_dir() {
if [[ -n "${backup_dir}" ]]; then
return 0
fi
backup_dir="${state_dir}/$(date +%Y%m%d-%H%M%S)-$$"
run mkdir -p -- "${backup_dir}"
}
backup_target() {
local target="${1}"
if [[ ! -e "${target}" && ! -L "${target}" ]]; then
return 0
fi
if [[ -d "${target}" && ! -L "${target}" ]]; then
printf 'Refusing to replace directory target: %s\n' "${target}" >&2
exit 1
fi
ensure_backup_dir
log "Backing up ${target} -> ${backup_dir}/$(basename -- "${target}")"
run mv -- "${target}" "${backup_dir}/$(basename -- "${target}")"
}
install_one() {
local name="${1}"
local src="${source_dir}/${name}"
local dst="${target_dir}/${name}"
if [[ ! -f "${src}" ]]; then
printf 'Missing source file: %s\n' "${src}" >&2
exit 1
fi
if [[ "${mode}" == "link" && -L "${dst}" ]]; then
local current
current="$(readlink -- "${dst}" || true)"
if [[ "${current}" == "${src}" ]]; then
log "Already linked: ${dst}"
return 0
fi
fi
if [[ "${mode}" == "copy" && -f "${dst}" && ! -L "${dst}" ]] && cmp -s -- "${src}" "${dst}"; then
log "Already up to date: ${dst}"
return 0
fi
backup_target "${dst}"
case "${mode}" in
link)
log "Linking ${dst} -> ${src}"
run ln -s -- "${src}" "${dst}"
;;
copy)
local install_mode="644"
if [[ -x "${src}" ]]; then
install_mode="755"
fi
log "Copying ${src} -> ${dst}"
run install -m "${install_mode}" -- "${src}" "${dst}"
;;
*)
printf 'Unsupported mode: %s\n' "${mode}" >&2
exit 1
;;
esac
}
while [[ $# -gt 0 ]]; do
case "${1}" in
--copy)
mode="copy"
shift
;;
--link)
mode="link"
shift
;;
--dry-run)
dry_run="true"
shift
;;
--target-dir)
if [[ $# -lt 2 ]]; then
printf 'Missing value for %s\n' "${1}" >&2
exit 1
fi
target_dir="${2}"
shift 2
;;
-h | --help)
usage
exit 0
;;
*)
printf 'Unknown argument: %s\n' "${1}" >&2
usage >&2
exit 1
;;
esac
done
if [[ ! -d "${source_dir}" ]]; then
printf 'Missing ranger source directory: %s\n' "${source_dir}" >&2
exit 1
fi
run mkdir -p -- "${target_dir}"
for name in "${files[@]}"; do
install_one "${name}"
done
if [[ -n "${backup_dir}" ]]; then
log "Backups stored in ${backup_dir}"
fi
log "ranger config installed into ${target_dir}"