<commit_before>#!/usr/bin/env zsh
# This file defines a couple of git aliases and bash completions for a number
# of git scripts
__zsh_forivall_git_plugin_location=$0:A
__zsh_forivall_git_plugin_location=${__zsh_forivall_git_plugin_location%/*}
PATH="$PATH:${__zsh_forivall_git_plugin_location}/bin"

alias gl='git l'
alias gla='git la'
alias gps='git push'
alias gp='git pull'

# GIT_CONTRIB_ROOT="/usr/share/doc/git/contrib"
GIT_CONTRIB_ROOT="/usr/share/git"
if $IS_OSX ; then
  GIT_REALPATH="$(readlink -f "$(whence -p git)")"
  GIT_CONTRIB_ROOT="${GIT_REALPATH%/bin/git}/share/git-core/contrib"
fi

# alias git-blameview="perl /usr/share/doc/git/contrib/blameview/blameview.perl"
# alias git-new-workdir="sh /usr/share/doc/git/contrib/workdir/git-new-workdir"
#
alias git-new-workdir="$GIT_CONTRIB_ROOT/workdir/git-new-workdir"
# alias gitview="python /usr/share/doc/git/contrib/gitview/gitview"
alias gitview="/usr/share/git/gitview/gitview"

alias g=git
alias gg="git grep"
# alias ge="git each"
ge() {
    local first; first="$1"
    if whence "$first" >/dev/null 2>/dev/null ; then
        shift
    else
        first=git
    fi
    for d in */.git(#q:s/\\/.git//)(/); do echo "$yellow❯ $teal$d$reset" >&2; (cd "$d"; "$first" "$@"); done;
}
alias gr="git r"
alias grg="git r git"
alias gst="git st"
alias gitify=gitify_node_module
alias glg="git l3"
alias glga="git l3 --all"
alias glgs="git l3 --stat"
alias glgas="git l3 --all --stat"
alias gti="git"

# t is in a terrible place in querty, and I often hit space first
# TODO: switch keyboard layouts.
function gi() {
    local firstarg
    firstarg=$1
    if [[ "${firstarg}" == t* ]] ; then
        shift
        git "${firstarg:1}" "$@"
        return $?
    else
        env gi "$@"
        return $?
    fi
}

function ___git_indent_helper() {
    "$@" 2>/dev/null | (whitespace="↳ "; while read l; do echo "$whitespace$l"; whitespace="  "; done)
}

GIT_SSH_AGENT_CHECK=(ssh-add -l)
GIT_SSH_AGENT_ADD=(ssh-add)

# ssh-add works fine if envoy is started in ssh-agent mode
# GIT_SSH_AGENT_CHECK=(envoy -l)
# GIT_SSH_AGENT_ADD=(envoy -a)

___git_ran_once=n
function git() { # also put these in git-aliases for autocomplete
  local a;
  if [[ $___git_ran_once = n && "$1" =~ "clone|fetch|fetch-pack|pull|push|send-pack" ]] ; then
    ___git_ran_once=y

    if ! $IS_OSX && ! $GIT_SSH_AGENT_CHECK >/dev/null; then
      $GIT_SSH_AGENT_ADD
    fi
  fi
  case "$1" in
    age) shift; ~/code/git-repos/git-age/git-age $@;;
    diff) shift; if [[ "$1" == '--name-status' || "$1" == '--name-only' ]] ; then /usr/bin/env git --no-pager diff $@ ; else /usr/bin/env git diff $@ ; fi;;
    grep-gedit-open) shift; git-grep-gedit-open $@;;
    blameall) shift; ~/code/git-blameall.py $@;;
    stashed) shift; git stash save && /usr/bin/env git "$@" && git stash pop;;
    checkout|cherry-pick|commit|fetch|merge|pull|push) /usr/bin/env git "$@" && ___git_indent_helper git st --no-files; echo  ;;
    # diffuse) shift; ~/scripts/git-diffuse "$@";;
    *) /usr/bin/env git "$@";;
  esac
}

_git-stashed() {
    _git "$@"
}

## aliases
<commit_msg>add git fancy<commit_after>#!/usr/bin/env zsh
# This file defines a couple of git aliases and bash completions for a number
# of git scripts
__zsh_forivall_git_plugin_location=$0:A
__zsh_forivall_git_plugin_location=${__zsh_forivall_git_plugin_location%/*}
PATH="$PATH:${__zsh_forivall_git_plugin_location}/bin"

alias gl='git l'
alias gla='git la'
alias gps='git push'
alias gp='git pull'

# GIT_CONTRIB_ROOT="/usr/share/doc/git/contrib"
GIT_CONTRIB_ROOT="/usr/share/git"
if $IS_OSX ; then
  GIT_REALPATH="$(readlink -f "$(whence -p git)")"
  GIT_CONTRIB_ROOT="${GIT_REALPATH%/bin/git}/share/git-core/contrib"
fi

# alias git-blameview="perl /usr/share/doc/git/contrib/blameview/blameview.perl"
# alias git-new-workdir="sh /usr/share/doc/git/contrib/workdir/git-new-workdir"
#
alias git-new-workdir="$GIT_CONTRIB_ROOT/workdir/git-new-workdir"
# alias gitview="python /usr/share/doc/git/contrib/gitview/gitview"
alias gitview="/usr/share/git/gitview/gitview"

alias g=git
alias gg="git grep"
# alias ge="git each"
ge() {
    local first; first="$1"
    if whence "$first" >/dev/null 2>/dev/null ; then
        shift
    else
        first=git
    fi
    for d in */.git(#q:s/\\/.git//)(/); do echo "$yellow❯ $teal$d$reset" >&2; (cd "$d"; "$first" "$@"); done;
}
alias gr="git r"
alias grg="git r git"
alias gst="git st"
alias gitify=gitify_node_module
alias glg="git l3"
alias glga="git l3 --all"
alias glgs="git l3 --stat"
alias glgas="git l3 --all --stat"
alias gti="git"

# t is in a terrible place in querty, and I often hit space first
# TODO: switch keyboard layouts.
function gi() {
    local firstarg
    firstarg=$1
    if [[ "${firstarg}" == t* ]] ; then
        shift
        git "${firstarg:1}" "$@"
        return $?
    else
        env gi "$@"
        return $?
    fi
}

function ___git_indent_helper() {
    "$@" 2>/dev/null | (whitespace="↳ "; while read l; do echo "$whitespace$l"; whitespace="  "; done)
}

GIT_SSH_AGENT_CHECK=(ssh-add -l)
GIT_SSH_AGENT_ADD=(ssh-add)

# ssh-add works fine if envoy is started in ssh-agent mode
# GIT_SSH_AGENT_CHECK=(envoy -l)
# GIT_SSH_AGENT_ADD=(envoy -a)

___git_ran_once=n
function git() { # also put these in git-aliases for autocomplete
  local a;
  if [[ $___git_ran_once = n && "$1" =~ "clone|fetch|fetch-pack|pull|push|send-pack" ]] ; then
    ___git_ran_once=y

    if ! $IS_OSX && ! $GIT_SSH_AGENT_CHECK >/dev/null; then
      $GIT_SSH_AGENT_ADD
    fi
  fi
  case "$1" in
    fancy) shift;
      local pager="$(git config core.pager || echo -n "less")"
      git -c color.diff=always "$@" | diff-so-fancy | $pager;;
    age) shift; ~/code/git-repos/git-age/git-age $@;;
    diff) shift;
      if [[ "$1" == '--name-status' || "$1" == '--name-only' ]] ; then
        /usr/bin/env git --no-pager diff $@
      else
        /usr/bin/env git diff $@ ;
      fi;;
    grep-gedit-open) shift; git-grep-gedit-open $@;;
    blameall) shift; ~/code/git-blameall.py $@;;
    stashed) shift; git stash save && /usr/bin/env git "$@" && git stash pop;;
    checkout|cherry-pick|commit|fetch|merge|pull|push) /usr/bin/env git "$@" && ___git_indent_helper git st --no-files; echo  ;;
    # diffuse) shift; ~/scripts/git-diffuse "$@";;
    *) /usr/bin/env git "$@";;
  esac
}

_git-stashed() {
    _git "$@"
}

## aliases

{'fraction_non_alphanumeric': 0.17383793969849246, 'fraction_numerical': 0.004711055276381909, 'mean_word_length': 3.491537376586742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3278062', 'n_tokens_mistral': 2574, 'n_tokens_neox': 2502, 'n_words': 560}