mirror of
https://oauth2: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@github.com/m1ngsama/dotfiles.git
synced 2026-05-10 19:10:58 +08:00
Merge 2db0f29196 into 0a344a6ab6
This commit is contained in:
commit
83744c1545
5 changed files with 244 additions and 17 deletions
13
README.md
13
README.md
|
|
@ -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)
|
- [fish](https://github.com/fish-shell/fish-shell)
|
||||||
|
|
||||||
|
|
@ -12,5 +12,12 @@
|
||||||
|
|
||||||
- [tmux](https://github.com/tmux/tmux)
|
- [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
36
ranger/README.md
Normal 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
14
ranger/rc.conf
Normal 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
|
||||||
|
|
@ -162,20 +162,21 @@ handle_image() {
|
||||||
;;
|
;;
|
||||||
|
|
||||||
## Video
|
## Video
|
||||||
# video/*)
|
video/*)
|
||||||
# # Thumbnail
|
ffmpegthumbnailer -i "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" -s 0 && exit 6
|
||||||
# ffmpegthumbnailer -i "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" -s 0 && exit 6
|
exit 1
|
||||||
# exit 1;;
|
;;
|
||||||
|
|
||||||
## PDF
|
## PDF
|
||||||
# application/pdf)
|
application/pdf)
|
||||||
# pdftoppm -f 1 -l 1 \
|
pdftoppm -f 1 -l 1 \
|
||||||
# -scale-to-x "${DEFAULT_SIZE%x*}" \
|
-scale-to-x "${DEFAULT_SIZE%x*}" \
|
||||||
# -scale-to-y -1 \
|
-scale-to-y -1 \
|
||||||
# -singlefile \
|
-singlefile \
|
||||||
# -jpeg -tiffcompression jpeg \
|
-jpeg -tiffcompression jpeg \
|
||||||
# -- "${FILE_PATH}" "${IMAGE_CACHE_PATH%.*}" \
|
-- "${FILE_PATH}" "${IMAGE_CACHE_PATH%.*}" &&
|
||||||
# && exit 6 || exit 1;;
|
exit 6 || exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
## ePub, MOBI, FB2 (using Calibre)
|
## ePub, MOBI, FB2 (using Calibre)
|
||||||
# application/epub+zip|application/x-mobipocket-ebook|\
|
# application/epub+zip|application/x-mobipocket-ebook|\
|
||||||
|
|
@ -331,8 +332,8 @@ handle_mime() {
|
||||||
|
|
||||||
## Image
|
## Image
|
||||||
image/*)
|
image/*)
|
||||||
## Preview as text conversion
|
chafa --animate=off --size="${PV_WIDTH}x${PV_HEIGHT}" \
|
||||||
# img2txt --gamma=0.6 --width="${PV_WIDTH}" -- "${FILE_PATH}" && exit 4
|
--symbols=block -- "${FILE_PATH}" && exit 4
|
||||||
exiftool "${FILE_PATH}" && exit 5
|
exiftool "${FILE_PATH}" && exit 5
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
169
scripts/install-ranger.sh
Executable file
169
scripts/install-ranger.sh
Executable 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}"
|
||||||
Loading…
Reference in a new issue