<commit_before># vim: set syntax=bash

function fzf-complete -d 'fzf completion and print selection back to commandline'
  # As of 2.6, fish's "complete" function does not understand
  # subcommands. Instead, we use the same hack as __fish_complete_subcommand and
  # extract the subcommand manually.

  set -l cmd (commandline -co) (commandline -ct)

  # ?
  switch $cmd[1]
    case env sudo
      for i in (seq 2 (count $cmd))
        switch $cmd[$i]
          case '-*'
          case '*=*'
          case '*'
            set cmd $cmd[$i..-1]
            break
        end
      end
  end
  set cmd (string join -- ' ' $cmd)

  # get the choice
  set -l complist (complete -C$cmd)
  set -l result

  string join -- \n $complist | \
    sort | \
    uniq | \
    eval (__fzfcmd) -m --select-1 --exit-0 --header '(commandline)' | \
    cut -f1 | \
    while read -l r; set result $result $r; end

  # escape everything
  set prefix (string sub -s 1 -l 1 -- (commandline -t))
  for i in (seq (count $result))
    set -l r $result[$i]
    switch $prefix
      case "'"
        commandline -t -- (string escape -- $r)
      case '"'
        if string match '*"*' -- $r >/dev/null
          commandline -t --  (string escape -- $r)<commit_msg>keep fzf tab complete from hanging forever<commit_after># vim: set syntax=bash

function fzf-complete -d 'fzf completion and print selection back to commandline'
  # As of 2.6, fish's "complete" function does not understand
  # subcommands. Instead, we use the same hack as __fish_complete_subcommand and
  # extract the subcommand manually.

  set -l cmd (commandline -co) (commandline -ct)

  # ?
  switch $cmd[1]
    case env sudo
      for i in (seq 2 (count $cmd))
        switch $cmd[$i]
          case '-*'
          case '*=*'
          case '*'
            set cmd $cmd[$i..-1]
            break
        end
      end
  end
  set cmd (string join -- ' ' $cmd)

  # get the choice
  set -l complist (complete -C$cmd)
  set -l result

  string join -- \n $complist | \
    sort | \
    uniq | \
    eval timeout 5 (__fzfcmd) -m --select-1 --exit-0 --header '(commandline)' | \
    cut -f1 | \
    while read -l r; set result $result $r; end

  # escape everything
  set prefix (string sub -s 1 -l 1 -- (commandline -t))
  for i in (seq (count $result))
    set -l r $result[$i]
    switch $prefix
      case "'"
        commandline -t -- (string escape -- $r)
      case '"'
        if string match '*"*' -- $r >/dev/null
          commandline -t --  (string escape -- $r)
{'fraction_non_alphanumeric': 0.13021040095275904, 'fraction_numerical': 0.00833664152441445, 'mean_word_length': 1.9200463499420626, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2347698', 'n_tokens_mistral': 860, 'n_tokens_neox': 827, 'n_words': 307}