Last active
February 2, 2022 11:59
-
-
Save przemoc/1275673 to your computer and use it in GitHub Desktop.
Turn a github.com URL into a git.io URL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# SPDX-License-Identifier: MIT | |
## Copyright (C) 2011 Przemyslaw Pawelczyk <[email protected]> | |
## | |
## This script is licensed under the terms of the MIT license. | |
## https://opensource.org/licenses/MIT | |
# | |
# 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 https://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 |
Author
przemoc
commented
Feb 6, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment