#!/usr/bin/env bash

# basics
alias python=python3
alias pip=pip3

# BSD doesn't have --color
if $(ls --color >/dev/null 2>&1); then
  alias ls="ls --color"
else
  export CLICOLOR=1
fi

# vim
#alias vi=nvim
#alias vim=nvim
#alias vimdiff='nvim -d'

alias grep="egrep --color=always"
alias rgv="rg --vimgrep --color=auto"
alias rgt="rg --glob '!*.spec.ts' --glob '!*mx*' --glob '!*mock*'"

#verbose
alias ln="ln -v"
alias mkdir="mkdir -pv"

# careful
alias rm="rm -i"
alias mv="mv -i"
alias cp="cp -i"

#git
if type git > /dev/null; then
  function git() {
    if [[ "$PWD" =~ "code.byted.or" ]]; then
      command git -c 'user.name=Max 🕺 Coplan' -c 'user.email=max.coplan@bytedance.com' "$@"
    else
      command git "$@"
    fi
  }

  alias g.="git add -p ."
  alias ga="git add"
  alias gc="git commit"
  alias gcw="git cw"
  alias gfr="git fr"
  alias gfru="git fru"
  alias glo="git -c color.ui=always log --graph --decorate=full --oneline"
  alias glog="git log --graph --decorate=full"
  alias gp="git push"
  alias gr="git rebase"
  alias gres="git restore"
  alias gs="git s"
  alias gsf="git sf"
  alias gst="git status"
  alias gstu="git status -uno"
  alias gsw="git switch"
  gsfz() {
    git switch $(git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/ | fzf --height=70% --preview-window=right:60%:wrap --preview='git log --color=always --oneline --decorate {}')
  }
fi

#sapling

if type sl >/dev/null 2>&1; then
  function sl() {
    if [[ "$PWD" =~ "code.byted.or" ]]; then
      command sl --config 'ui.username=Max 🕺 Coplan <max.coplan@bytedance.com>' $@
    else
      command sl $@
    fi
  }

  alias sst="sl status && sl ssl"

  alias slc="sl commit --verbose"
  alias slci="slc --interactive"
  alias sla="sl amend"
  alias slai="sl amend --interactive"

  alias slr="sl rebase"
fi

#vscode
if ! type code >/dev/null 2>&1 && type code-insiders >/dev/null 2>&1; then
  alias code="code-insiders"
fi
if ! type trae >/dev/null 2>&1 && type trae-cn >/dev/null 2>&1;then
  alias trae="trae-cn"
fi
alias traex-frontier="traex --profile frontier"

# k8s
if type kubectl >/dev/null 2>&1; then
  alias k="kubectl"
  alias kns="kubens ce-smartlists-gql"
  alias kn="kubens"
  alias kpods="k get pods -o wide --sort-by=.metadata.creationTimestamp"
  alias kwpod="k get pod -w -o wide --sort-by=.metadata.creationTimestamp"
  alias kevents="k get events -w --sort-by=.metadata.creationTimestamp"
  alias khpa="k get hpa"
  alias kdp="k describe pod"
  alias kdhpa="k describe hpa"
  if type sledge > /dev/null; then
    #alias sl="sledge"
    #alias slc="sledge connect"
    alias slprod_w="sledge connect wus-prod-a31 && kns"
    alias slprod_s="sledge connect scus-prod-a29 && kns"
    alias slprod_e="sledge connect eus2-prod-a18 && kns"
  fi
fi
