/
kak-tree-grepper.kak
51 lines (39 loc) · 2.36 KB
/
kak-tree-grepper.kak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
declare-option str tree_grepper_path "tree-grepper"
declare-option str tree_grepper_fzf_path "fzf"
define-command -override -docstring "jump somewhere in an Elm file's definition outline" -params 0..1 outline-jump-elm %{
tmux-terminal-horizontal sh -c %{
set -euo pipefail
# what tools do we have available?
TREE_GREPPER=${1:-tree-grepper}
FZF=${2:-fzf}
# what do we care about?
FILE=$3
FZF_QUERY=$4
# where do we return results?
CLIENT=$5
SESSION=$6
# do the magic!
QUERY="(function_declaration_left (lower_case_identifier)@function) (type_declaration (type) (upper_case_identifier)@type) (type_alias_declaration (type) (alias) (upper_case_identifier)@alias) (union_variant (upper_case_identifier)@constructor) (field_type (lower_case_identifier)@field)"
# TODO: maybe also (import_clause (import) (upper_case_qid)@import)?
EDIT_LOCATION="$("$TREE_GREPPER" --language elm "$QUERY" "$FILE" | fzf --with-nth 4,5 --nth 2,1 --delimiter=: --query "$FZF_QUERY" --select-1 | cut -d : -f 1-3 | tr : ' ')"
printf "evaluate-commands -client %s edit %s\n" "$CLIENT" "$EDIT_LOCATION" | indiekak -p "$SESSION"
} -- %opt{tree_grepper_path} %opt{tree_grepper_fzf_path} %val{bufname} %arg{1} %val{client} %val{session}
}
define-command -override -docstring "jump somewhere in a Ruby file's definition outline" -params 0..1 outline-jump-ruby %{
tmux-terminal-horizontal sh -c %{
set -euo pipefail
# what tools do we have available?
TREE_GREPPER=${1:-tree-grepper}
FZF=${2:-fzf}
# what do we care about?
FILE=$3
FZF_QUERY=$4
# where do we return results?
CLIENT=$5
SESSION=$6
# do the magic!
QUERY="(module name: (_) @module) (class name: (_) @class) (method name: (_) @method) (singleton_method name: (_) @method) (assignment left: (_) @assignment) (operator_assignment left: (_) @assignment)"
EDIT_LOCATION="$("$TREE_GREPPER" --language ruby "$QUERY" "$FILE" | fzf --with-nth 4,5 --nth 2,1 --delimiter=: --query "$FZF_QUERY" --select-1 | cut -d : -f 1-3 | tr : ' ')"
printf "evaluate-commands -client %s edit %s\n" "$CLIENT" "$EDIT_LOCATION" | indiekak -p "$SESSION"
} -- %opt{tree_grepper_path} %opt{tree_grepper_fzf_path} %val{bufname} %arg{1} %val{client} %val{session}
}