Created
April 12, 2022 23:14
-
-
Save tuan/3678d6f503fb593a293cee0943f94e62 to your computer and use it in GitHub Desktop.
Use FZF and Ripgrep to find notes and open it in CotEditor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# 1. Search for text in files using Ripgrep | |
# 2. Interactively restart Ripgrep with reload action | |
# 3. Open the file in Vim | |
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case " | |
INITIAL_QUERY="${*:-}" | |
IFS=: read -ra selected < <( | |
FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \ | |
fzf --ansi \ | |
--color "hl:-1:underline,hl+:-1:underline:reverse" \ | |
--disabled --query "$INITIAL_QUERY" \ | |
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \ | |
--bind "ctrl-s:unbind(change,alt-enter)+change-prompt(2. fzf> )+enable-search+clear-query" \ | |
--prompt '1. ripgrep> ' \ | |
--delimiter : \ | |
--preview 'bat --color=always {1} --highlight-line {2}' \ | |
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3' | |
) | |
[ -n "${selected[0]}" ] && cot -l "${selected[1]}" -c "${selected[2]}" "${selected[0]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment