Module: Sumologic::Interactive::FzfViewer::FzfConfig

Defined in:
lib/sumologic/interactive/fzf_viewer/fzf_config.rb

Class Method Summary collapse

Class Method Details

.build_fzf_args(input_path, preview_path, header_text) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/sumologic/interactive/fzf_viewer/fzf_config.rb', line 11

def build_fzf_args(input_path, preview_path, header_text)
  [
    'fzf',
    *search_options,
    *display_options(preview_path, header_text),
    *keybinding_options(input_path, preview_path)
  ]
end

.build_preview_command(preview_path) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/sumologic/interactive/fzf_viewer/fzf_config.rb', line 62

def build_preview_command(preview_path)
  escaped_path = Shellwords.escape(preview_path)

  calc = "LINE=$(({n} + 1)); TOTAL=$(wc -l < #{escaped_path}); "
  display = 'echo "Message $LINE of $TOTAL"; echo ""; '
  extract = "sed -n \"$LINE\"p #{escaped_path}"

  "#{calc}#{display}#{extract} | jq -C . || #{extract}"
end

.build_view_command(preview_path) ⇒ Object



56
57
58
59
60
# File 'lib/sumologic/interactive/fzf_viewer/fzf_config.rb', line 56

def build_view_command(preview_path)
  # FZF {n} is 0-indexed, sed is 1-indexed
  'LINE=$(({n} + 1)); ' \
    "sed -n \"$LINE\"p #{Shellwords.escape(preview_path)} | jq -C . | less -R"
end

.display_options(preview_path, header_text) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/sumologic/interactive/fzf_viewer/fzf_config.rb', line 30

def display_options(preview_path, header_text)
  [
    "--header=#{header_text}",
    "--preview=#{build_preview_command(preview_path)}",
    '--preview-window=right:60%:wrap:follow',
    '--height=100%'
  ]
end

.keybinding_options(input_path, preview_path) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sumologic/interactive/fzf_viewer/fzf_config.rb', line 39

def keybinding_options(input_path, preview_path)
  [
    '--bind=enter:toggle',
    "--bind=tab:execute(#{build_view_command(preview_path)})",
    '--bind=ctrl-a:select-all',
    '--bind=ctrl-d:deselect-all',
    '--bind=ctrl-s:execute-silent(echo {+} > sumo-selected.txt)+abort',
    '--bind=ctrl-y:execute-silent(echo {+} | pbcopy || ' \
    'echo {+} | xclip -selection clipboard 2>/dev/null)+abort',
    '--bind=ctrl-e:execute-silent(echo {+} > sumo-export.jsonl)+abort',
    '--bind=ctrl-/:toggle-preview',
    "--bind=ctrl-r:reload(cat #{input_path})",
    '--bind=ctrl-t:toggle-search',
    '--bind=ctrl-q:abort'
  ]
end

.search_optionsObject



20
21
22
23
24
25
26
27
28
# File 'lib/sumologic/interactive/fzf_viewer/fzf_config.rb', line 20

def search_options
  [
    '--ansi',
    '--multi',
    '--exact',       # Exact substring matching
    '-i',            # Case-insensitive
    '--no-hscroll'   # Prevent horizontal scrolling
  ]
end