インクリメンタルサーチするために。
事前準備
情報源
プラグイン導入
fzf
ファイルのインクリメンタルサーチができるCLIツール。
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf ~/.fzf/install
~/.fzf/install --all
新しいタブを開いてfzfコマンドを叩くと実行できる。
ranger設定
fzf_select
cat >> ~/.config/ranger/commands.py << EOF class fzf_select(Command): """ :fzf_select Find a file using fzf. With a prefix argument to select only directories. See: https://github.com/junegunn/fzf """ def execute(self): import subprocess import os from ranger.ext.get_executables import get_executables if 'fzf' not in get_executables(): self.fm.notify('Could not find fzf in the PATH.', bad=True) return fd = None if 'fdfind' in get_executables(): fd = 'fdfind' elif 'fd' in get_executables(): fd = 'fd' if fd is not None: hidden = ('--hidden' if self.fm.settings.show_hidden else '') exclude = "--no-ignore-vcs --exclude '.git' --exclude '*.py[co]' --exclude '__pycache__'" only_directories = ('--type directory' if self.quantifier else '') fzf_default_command = '{} --follow {} {} {} --color=always'.format( fd, hidden, exclude, only_directories ) else: hidden = ('-false' if self.fm.settings.show_hidden else r"-path '*/\.*' -prune") exclude = r"\( -name '\.git' -o -name '*.py[co]' -o -fstype 'dev' -o -fstype 'proc' \) -prune" only_directories = ('-type d' if self.quantifier else '') fzf_default_command = 'find -L . -mindepth 1 {} -o {} -o {} -print | cut -b3-'.format( hidden, exclude, only_directories ) env = os.environ.copy() env['FZF_DEFAULT_COMMAND'] = fzf_default_command env['FZF_DEFAULT_OPTS'] = '--height=40% --layout=reverse --ansi --preview="{}"'.format(''' ( batcat --color=always {} || bat --color=always {} || cat {} || tree -ahpCL 3 -I '.git' -I '*.py[co]' -I '__pycache__' {} ) 2>/dev/null | head -n 100 ''') fzf = self.fm.execute_command('fzf --no-multi', env=env, universal_newlines=True, stdout=subprocess.PIPE) stdout, _ = fzf.communicate() if fzf.returncode == 0: selected = os.path.abspath(stdout.strip()) if os.path.isdir(selected): self.fm.cd(selected) else: self.fm.select_file(selected) EOF
compress
~/.fzf.bash
# Setup fzf # --------- if [[ ! "$PATH" == */home/pi/.fzf/bin* ]]; then PATH="${PATH:+${PATH}:}/home/pi/.fzf/bin" fi export FZF_DEFAULT_OPTS="--ansi -e --prompt='QUERY> ' --layout=reverse --border=rounded --height 100%" export FZF_CTRL_T_OPTS="--preview 'bat --color=always --style=header,grid --line-range :100 {}'" export FZF_ALT_C_OPTS="--preview 'exa {} -h -T -F --no-user --no-time --no-filesize --no-permissions --long | head -200'" export FZF_DEFAULT_COMMAND="fd -H -E .git --color=always" export FZF_CTRL_T_COMMAND="fd --type f -H -E .git" export FZF_ALT_C_COMMAND="fd --type d -H -E .git" export EDITOR=vim bind '"\C-f":"tfz\C-m"' eval "$(fzf --bash)"
BAT
catの代替でlessを拡張したコマンド。構文強調できる。
BAT_VER=0.25.0 wget -q -O bat.deb https://github.com/sharkdp/bat/releases/download/v${BAT_VER}/bat_${BAT_VER}_arm64.deb sudo dpkg -i bat.deb rm -rf bat.deb
eza
lsの代替コマンド。
以下失敗。
EZA_VER=0.23.0 wget -q -O eza.tar.gz https://github.com/eza-community/eza/releases/download/v${EZA_VER}/eza_arm-unknown-linux-gnueabihf.tar.gz tar -zxvf eza.tar.gz sudo cp ./eza /usr/local/bin/ rm -rf eza eza.tar.gz
$ eza bash: /usr/local/bin/eza: 実行できません: 必要なファイルがありません
仕方ないのでRust言語のSDKをインストールしてからパッケージ管理ツールcargoで入れる。
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ rustc --version rustc 1.88.0 (6b00bc388 2025-06-23)
Rust言語のパッケージ管理ツールcargoでezaをインストールする。
cd /tmp/work
cargo install eza
...
Finished `release` profile [optimized] target(s) in 8m 21s
Installing /home/pi/.cargo/bin/eza
Installed package `eza v0.23.0` (executable `eza`)
配置する。
sudo cp /home/pi/.cargo/bin/eza /usr/local/bin
$ eza --version eza - A modern, maintained replacement for ls v0.23.0 [+git] https://github.com/eza-community/eza
fd-find
sudo apt install -y fd-find mkdir -p ~/.local/bin ln -s $(which fdfind) ~/.local/bin/fd
~/.bashrc
export EDITOR=vim bind '"\C-f":"tfz\C-m"'
ripgrep
$ sudo apt install -y ripgrep