fzf
https://github.com/junegunn/fzf/blob/master/ADVANCED.md
fzf 筛选 + 搜索
vim or code 打开文件
#!/usr/bin/env bash
# 1. Search for text in files using Ripgrep
# 2. Interactively narrow down the list using fzf
# 3. Open the file in Vim
export FZF_DEFAULT_COMMAND='fdfind --type f'
function __bat_line_range() {
local line_range=10
local start_line=`expr $1 - $line_range`
[ $start_line -le 1 ] && start_line=1
echo $start_line:`expr $1 + $line_range`
}
export -f __bat_line_range
if [ $# -ge 1 ]; then
# 使用 rg 搜索过滤一下
IFS=: read -ra selected < <(
rg --color=always --line-number --no-heading --smart-case "$@" |
fzf --ansi \
--delimiter : \
--preview 'bat {1} --highlight-line {2} --line-range `__bat_line_range {2}`' \
)
else
# 没有参数, 直接fzf 过滤
IFS=: read -ra selected < <(fzf --preview "bat --style=numbers --color=always --line-range :20 {}")
fi
function __fzf_openfile() {
echo `realpath $1`
if code -v > /dev/null 2>&1; then
code --goto "$1":"$2"
else
vim "$1" +"$2"
fi
echo
}
[ -n "${selected[0]}" ] && __fzf_openfile "${selected[0]}" "${selected[1]}"
ranger
https://github.com/ranger/ranger
设置默认配置
zcz@zcz-pc:~/work$ ranger --copy-config=all
creating: /home/zcz/.config/ranger/rifle.conf
creating: /home/zcz/.config/ranger/commands.py
creating: /home/zcz/.config/ranger/commands_full.py
creating: /home/zcz/.config/ranger/rc.conf
creating: /home/zcz/.config/ranger/scope.sh
绑定fzf
https://github.com/ranger/ranger/wiki/Custom-Commands
/home/zcz/.config/ranger/commands.py
fzf_select 关键词
Q键退出
https://github.com/ranger/ranger/wiki/Integration-with-other-programs#changing-directories
下面的函数放到启动脚本中
#!/bin/bash
function r {
export EDITOR=vim
if code -v > /dev/null 2>&1; then
export EDITOR=code
fi
local IFS=$'\t\n'
local tempfile="$(mktemp -t tmp.XXXXXX)"
local ranger_cmd=(
command
ranger
--cmd="map Q chain shell echo %d > "$tempfile"; quitall"
)
${ranger_cmd[@]} "$@"
if [[ -f "$tempfile" ]] && [[ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]]; then
cd -- "$(cat "$tempfile")" || return
fi
command rm -f -- "$tempfile" 2>/dev/null
}
ranger 修改编辑器
code 是vscde 的命令行, 不建议直接在 启动脚本中使用, 可以在 启动脚本中包装一个 函数。 在函数中使用这个命令。
export EDITOR=vim
if code -v > /dev/null 2>&1; then
export EDITOR=code
fi
https://unix.stackexchange.com/questions/22796/can-i-export-functions-in-bash