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 Vimexport FZF_DEFAULT_COMMAND='fdfind --type f'function __bat_line_range() {local line_range=10local start_line=`expr $1 - $line_range`[ $start_line -le 1 ] && start_line=1echo $start_line:`expr $1 + $line_range`}export -f __bat_line_rangeif [ $# -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 {}")fifunction __fzf_openfile() {echo `realpath $1`if code -v > /dev/null 2>&1; thencode --goto "$1":"$2"elsevim "$1" +"$2"fiecho}[ -n "${selected[0]}" ] && __fzf_openfile "${selected[0]}" "${selected[1]}"
ranger
https://github.com/ranger/ranger
设置默认配置
zcz@zcz-pc:~/work$ ranger --copy-config=allcreating: /home/zcz/.config/ranger/rifle.confcreating: /home/zcz/.config/ranger/commands.pycreating: /home/zcz/.config/ranger/commands_full.pycreating: /home/zcz/.config/ranger/rc.confcreating: /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/bashfunction r {export EDITOR=vimif code -v > /dev/null 2>&1; thenexport EDITOR=codefilocal IFS=$'\t\n'local tempfile="$(mktemp -t tmp.XXXXXX)"local ranger_cmd=(commandranger--cmd="map Q chain shell echo %d > "$tempfile"; quitall")${ranger_cmd[@]} "$@"if [[ -f "$tempfile" ]] && [[ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]]; thencd -- "$(cat "$tempfile")" || returnficommand rm -f -- "$tempfile" 2>/dev/null}
ranger 修改编辑器
code 是vscde 的命令行, 不建议直接在 启动脚本中使用, 可以在 启动脚本中包装一个 函数。 在函数中使用这个命令。
export EDITOR=vimif code -v > /dev/null 2>&1; thenexport EDITOR=codefi
https://unix.stackexchange.com/questions/22796/can-i-export-functions-in-bash
