function aws-profile {
  if [ $# -eq 0 ]; then
    echo Current AWS Profile: $AWS_DEFAULT_PROFILE
  else
    export AWS_DEFAULT_PROFILE=$1
    export AWS_PROFILE=$1
  fi
}

function g {
  if [[ $# > 0 ]]; then
    git $@
  else
    git status
  fi
}

function insert-sudo {
  zle beginning-of-line
  zle -U "sudo "
}

function true-colors {
  awk 'BEGIN{
    s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;
    for (colnum = 0; colnum<77; colnum++) {
        r = 255-(colnum*255/76);
        g = (colnum*510/76);
        b = (colnum*255/76);
        if (g>255) g = 510-g;
        printf "\033[48;2;%d;%d;%dm", r,g,b;
        printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
        printf "%s\033[0m", substr(s,colnum+1,1);
    }
    printf "\n";
  }'
}

function port-forward {
  if [ $# -lt 2 ]; then
    echo Usage: port-forward HOST LOCAL_PORT \[REMOTE_PORT\]
  else
    ssh $1 -R ${3:-$2}":localhost:"$2 -g
  fi
}

function gitignore-io {
  curl https://www.gitignore.io/api/$@
}

function git-date-added {
  if [ $# -eq 0 ]; then
    echo Usage: git-date-added FILENAME
  else
    git log --format=%aD $1 | tail -1
  fi
}

function run {
  if [ $# -lt 2 ]; then
    echo Usage: run NUMBER COMMAND
  else
    number=$1; shift

    for i in `seq $number`; do
      $@
    done
  fi
}

function npm-exec {
  (PATH=$(npm bin):$PATH; eval $@;)
}

function yarn-exec {
  (PATH=$(yarn bin):$PATH; eval $@;)
}

function yarn-install-like-bundle {
  if [ -f yarn.lock ]; then
    yarn install --pure-lockfile
  else
    yarn install
  fi
}