dotfiles

custom linux config files managed with gnu stow

dotfiles

bin/.local/bin/gitio


#!/bin/sh
#
#          ██   ██      ██
#   █████ ░░   ░██     ░░
#  ██░░░██ ██ ██████    ██  ██████
# ░██  ░██░██░░░██░    ░██ ██░░░░██
# ░░██████░██  ░██     ░██░██   ░██
#  ░░░░░██░██  ░██     ░██░██   ░██
#   █████ ░██  ░░██  ██░██░░██████
#  ░░░░░  ░░    ░░  ░░ ░░  ░░░░░░
#
# create short / vanity github urls
#         ▟▙
# ▟▒░░░░░░░▜▙▜████████████████████████████████▛
# ▜▒░░░░░░░▟▛▟▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▛
#         ▜▛
# xero / syntax-samurai <http://git.io/gitio.sh>

usage () {
    cat <<EOF

         ▟▙
 ▟▒░░░░░░░▜▙▜████████████████████████████████▛
 ▜▒░░░░░░░▟▛▟▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▛
         ▜▛

 create short / vanity github urls
 usage: $(basename {{&blob}}) http://github.com/something [-v mini]
 
 options:
  -v   shortlink
  -h   display this screen
EOF
  exit 0
}

err() {
  echo 
  usage 
}

optstest() {
  found=0
  for arg in "$@"
  do
    if echo $arg | cut -d/ -f3 | grep -q "github.com\|githubusercontent.com"
    then
      GHURL=$arg
      found=1
    elif [ $arg = "-h" ]
    then
      usage
    elif [ $arg = "-v" ]
    then
      :
    else
      VANITY=$arg
    fi
  done
  if [ $found = 0 ]
  then
    err " must be a valid github.com url!"
  fi
}

case $# in
  1)
    optstest  ;;
  3)
    optstest    ;;
  *)
    err " invalid number of arguments!" ;;
esac

if [ -z "$VANITY" ]
then
  url=`curl -is https://git.io -F "url=$GHURL" | grep -i "location" | cut -d' ' -f2`
else
  url=`curl -is https://git.io -F "url=$GHURL" -F "code=$VANITY" | grep -i "location" | cut -d' ' -f2`
fi

if [ -z $url ]
then
  err " must be a valid github.com url!"
else
  echo $url
fi

Download

raw zip tar