Skip to content

Instantly share code, notes, and snippets.

@skopp
Forked from przemoc/gitio
Last active December 16, 2015 21:10
Show Gist options
  • Save skopp/5498154 to your computer and use it in GitHub Desktop.
Save skopp/5498154 to your computer and use it in GitHub Desktop.
Bourne Again Shell and Git.io...bashio!

bashIO


Hey, the name sticks. Admit it.

SHell(it) + G(it) + IO

Other nominations:

  • bagoshit (git io bash shell)
  • shitbash... nah
  • terminal gitio ...nah
  • bashio ... maybe. but two letters from git are missing
  • gitshellio ...nah
  • gitshio ... hmm
  • gishio ... 50-50

#!/bin/sh
# Usage: gitio URL [CODE]
#
# Turns a github.com URL
# into a git.io URL
#
# Copies the git.io URL to your clipboard if xclip is available.
URL="$1"
CODE="$2"
if ! expr "${URL}" : "\(\(https\?://\)\?\(gist\.\)\?github.com/\)" >/dev/null; then
echo "* github.com URLs only" >&2
exit 1
fi
if ! expr "${URL}" : "http" >/dev/null; then
URL="https://${URL}"
fi
OUT="$(\
curl -si http://git.io -F "url=${URL}" ${CODE:+-F "code=${CODE}"} | \
sed '/^Status: /{s///;/^201/d;q};/^Location: /!d;s///'
)"
if expr "${OUT}" : "[0-9]\+" >/dev/null; then
echo "${OUT}" >&2
exit 1
fi
echo "${OUT}"
which xclip >/dev/null && echo "${OUT}" | xclip -selection clipboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment