1
0
Fork 0

Merge pull request #41 from andreyorst/skim-grep

Skim grep
This commit is contained in:
Andrey Orst 2019-03-06 14:40:44 +03:00 committed by GitHub
commit 98e4f0f83b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 2 deletions

View file

@ -0,0 +1,52 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ sk-grep.kak │
# ╞═════════════╩════════════════════════╡
# │ Module running interactive grep with │
# │ ski for fzf.kak │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
declare-option -docstring "what command to use to provide list of grep search matches.
Grep output must follow the format of 'filename:line-number:text'
Default value:
grep -RHn" \
str fzf_sk_grep_command 'grep -RHn'
evaluate-commands %sh{
if [ -n "$(command -v sk)" ]; then
printf "%s\n" "map global fzf -docstring %{Interactive grep with skim} 'g' '<esc>: sk-interactive-grep<ret>'"
fi
}
define-command -hidden sk-interactive-grep %{ evaluate-commands %sh{
if [ -z "$(command -v sk)" ]; then
printf "%s\n" "echo -markup %{{Information}skim required to run this command}"
exit
fi
title="skim interactive grep"
message="Interactively grep pattern from current directory
<ret>: open search result in new buffer.
<c-w>: open search result in new window"
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
<c-s>: open search result in horizontal split
<c-v>: open search result in vertical split"
printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'"
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
impl=$kak_opt_fzf_implementation
printf "%s\n" "set-option global fzf_implementation \"sk -i -c '$kak_opt_fzf_sk_grep_command {}'\"
fzf %{fzf-sk-grep-handler} %{echo >/dev/null 2>&1} %{--expect ctrl-w $additional_flags}
set-option global fzf_implementation $impl"
}}
define-command fzf-sk-grep-handler -params 1 %{ evaluate-commands %sh{
printf "%s\n" "$1" | awk '{
file = $0; sub(/:.*/, "", file); gsub("&", "&&", file);
line = $0; sub(/[^:]+:/, "", line); sub(/:.*/, "", line)
print "edit -existing %&" file "&; execute-keys %&" line "gxvc&";
}'
}}

View file

@ -176,7 +176,7 @@ fzf -params 2..4 %{ evaluate-commands %sh{
chmod 755 $fzfcmd
if [ -n "$kak_client_env_TMUX" ]; then
[ -n "${tmux_height%%*%}" ] && measure="-p" || measure="-p"
[ -n "${tmux_height%%*%}" ] && measure="-l" || measure="-p"
cmd="command tmux split-window $measure ${tmux_height%%%*} 'sh -c $fzfcmd'"
elif [ -n "$kak_opt_termcmd" ]; then
cmd="$kak_opt_termcmd 'sh -c $fzfcmd'"
@ -209,7 +209,7 @@ fzf -params 2..4 %{ evaluate-commands %sh{
fi ;;
esac
kakoune_command() {
printf "%s\n" "evaluate-commands -client $kak_client $wincmd $command %{$1}"
printf "%s\n" "evaluate-commands -client $kak_client $wincmd %{$command %{$1}}"
[ -n "$extra_action" ] && printf "%s\n" "evaluate-commands -client $kak_client $extra_action"
}
while read item; do