<commit_before># Inspired by
# - https://github.com/junegunn/fzf/wiki/Examples#git
# - https://junegunn.kr/2016/07/fzf-git/

# fco - checkout git branch/tag
fzf_get_ref() {
  local tags branches target

  tags=$(
    git for-each-ref --sort=-committerdate refs/tags/ --format="%(refname:short)" |
    awk '{print "\x1b[31;1mtag\x1b[m\t" $1}'
  ) || return

  localBranches=$(
    git for-each-ref --sort=-committerdate refs/heads/ --format="%(refname:short)" |
    sed "s/.* //"    | sed "s#remotes/[^/]*/##" |
    awk '{print "\x1b[34;1mlocal\x1b[m\t" $1}'
  ) || return

  remoteBranches=$(
    git for-each-ref --sort=-committerdate refs/remotes/ --format="%(refname:short)" |
    sed "s/.* //"    | sed "s#remotes/[^/]*/##" |
    awk '{print "\x1b[34;1mremote\x1b[m\t" $1}'
  ) || return

  target=$(
    (echo "$localBranches"; echo "$remoteBranches"; echo "$tags") |
    fzf -m --ansi \
      --preview 'git log --pretty=oneline --abbrev-commit --color=always `echo {} | cut -f2` | head -'$LINES |
    awk '{print $2}' |
    xargs echo
  )

  echo $target
}

fco() {
  local target=$(fzf_get_ref)
  echo git checkout "${target}"<commit_msg>Fix for exit fco w/o running<commit_after># Inspired by
# - https://github.com/junegunn/fzf/wiki/Examples#git
# - https://junegunn.kr/2016/07/fzf-git/

# fco - checkout git branch/tag
fzf_get_ref() {
  local tags branches target

  tags=$(
    git for-each-ref --sort=-committerdate refs/tags/ --format="%(refname:short)" |
    awk '{print "\x1b[31;1mtag\x1b[m\t" $1}'
  ) || return

  localBranches=$(
    git for-each-ref --sort=-committerdate refs/heads/ --format="%(refname:short)" |
    sed "s/.* //"    | sed "s#remotes/[^/]*/##" |
    awk '{print "\x1b[34;1mlocal\x1b[m\t" $1}'
  ) || return

  remoteBranches=$(
    git for-each-ref --sort=-committerdate refs/remotes/ --format="%(refname:short)" |
    sed "s/.* //"    | sed "s#remotes/[^/]*/##" |
    awk '{print "\x1b[34;1mremote\x1b[m\t" $1}'
  ) || return

  target=$(
    (echo "$localBranches"; echo "$remoteBranches"; echo "$tags") |
    fzf -m --ansi \
      --preview 'git log --pretty=oneline --abbrev-commit --color=always `echo {} | cut -f2` | head -'$LINES |
    awk '{print $2}' |
    xargs echo
  )

  echo $target
}

fco() {
  local target=$(fzf_get_ref)

  if [[ -z "$target" ]]; then
    return 0;
  fi

  echo git checkout "${target}"
  git checkout "${target}"
{'fraction_non_alphanumeric': 0.21635220125786164, 'fraction_numerical': 0.022222222222222223, 'mean_word_length': 2.823717948717949, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '2441005', 'n_tokens_mistral': 998, 'n_tokens_neox': 945, 'n_words': 194}