lib/hook/hookapp.rb
# Generate a menu of available hooks for selecting one or more hooks to operate on.
# Revamped to use `fzf`, which is embedded as `lib/helpers/fuzzyfilefinder` to avoid any conflicts.
# Allows multiple selections with tab key, and type-ahead fuzzy filtering of results.
Generate a menu of available hooks for selecting one or more hooks to operate on.
Revamped to use `fzf`, which is embedded as `lib/helpers/fuzzyfilefinder` to avoid any conflicts.
Allows multiple selections with tab key, and type-ahead fuzzy filtering of results.
Generate a menu of available hooks for selecting one or more hooks to operate on . Revamped to use ` fzf ` which is embedded as ` lib / helpers / fuzzyfilefinder ` to avoid any conflicts . Allows multiple selections with tab key and type - ahead fuzzy filtering of results .
def select_hook(marks)
    options = marks.map {|mark|
      if mark[:name]
        id = mark[:name]
      elsif mark[:path]
        id = mark[:path]
      elsif mark[:url]
        id = mark[:url]
      else
        return false
      end
      if mark[:path]
        loc = File.dirname(mark[:path])
      elsif mark[:url]
        url = URI.parse(mark[:url])
        id = mark[:url]
        loc = url.scheme + " - " + url.hostname
      else
        loc = ""
      end
      "#{id}\t#{mark[:path]}\t#{mark[:url]}\t#{loc}"
    }.delete_if { |mark| !mark }
    raise "Error processing available hooks" if options.empty?
    args = ['--layout=reverse-list',
            '--header="esc: cancel, tab: multi-select, ctrl-a: select all, return: open"',
            '--bind ctrl-a:select-all',
            '--prompt="  Select hooks > "',
            '--multi',
            '--tabstop=4',
            '--delimiter="\t"',
            '--with-nth=1,4',
            '--height=60%',
            '--min-height=10'
          ]
    fzf = File.join(File.dirname(__FILE__), '../helpers/fuzzyfilefinder')
    sel = `echo #{Shellwords.escape(options.join("\n"))} | '#{fzf}' #{args.join(' ')}`.chomp
    res = sel.split(/\n/).map do |s|
      ps = s.split(/\t/)
      { name: ps[0], path: ps[1], url: ps[2] }
    end
    res || []
  end
def select_hook ( marks ) options = marks . map { | mark | if mark [ :name ] id = mark [ :name ] elsif mark [ :path ] id = mark [ :path ] elsif mark [ :url ] id = mark [ :url ] else return false end if mark [ :path ] loc = File . dirname ( mark [ :path ] ) elsif mark [ :url ] url = URI . parse ( mark [ :url ] ) id = mark [ :url ] loc = url . scheme + " - " + url . hostname else loc = "" end "#{id}\t#{mark[:path]}\t#{mark[:url]}\t#{loc}" } . delete_if { | mark | ! mark } raise "Error processing available hooks" if options . empty? args = [ '--layout=reverse-list' , '--header="esc: cancel, tab: multi-select, ctrl-a: select all, return: open"' , '--bind ctrl-a:select-all' , '--prompt="  Select hooks > "' , '--multi' , '--tabstop=4' , '--delimiter="\t"' , '--with-nth=1,4' , '--height=60%' , '--min-height=10' ] fzf = File . join ( File . dirname ( __FILE__ ) , '../helpers/fuzzyfilefinder' ) sel = ` echo  #{ Shellwords . escape ( options . join ( "\n" ) ) }  | ' #{ fzf } '  #{ args . join ( ' ' ) } ` . chomp res = sel . split ( / \n / ) . map do | s | ps = s . split ( / \t / ) { name : ps [ 0 ] , path : ps [ 1 ] , url : ps [ 2 ] } end res || [ ] end
Generate a menu of available hooks for selecting one or more hooks to operate on.
Generate a menu of available hooks for selecting one or more hooks to operate on .
# intpad = marks.length.to_s.length + 1 # marks.each_with_index do |mark, i| #   STDERR.printf "%#{intpad}d) %s\n", i + 1, mark[:name] # end # STDERR.print 'Open which bookmark: ' # sel = STDIN.gets.strip.to_i # raise 'Invalid selection' unless sel.positive? && sel <= marks.length # marks[sel - 1]
marks
<not_specific>