#!/bin/sh | |
# SPDX-License-Identifier: MIT | |
## Copyright (C) 2011 Przemyslaw Pawelczyk <przemoc@gmail.com> | |
## | |
## 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 |
This comment has been minimized.
This comment has been minimized.
I think something is wrong with the regular expression. I can't seem to get any github.com URL to work… |
This comment has been minimized.
This comment has been minimized.
@pandamonia: $ wget -q --content-disposition https://gist.github.com/gists/1275673/download $ tar zxf gist1275673-*.tar.gz $ cd gist1275673-835ba0b0d2ab3d2ec48504481acdf36c442e168c/ $ chmod +x gitio $ ./gitio https://github.com/wycats/handlebars.js handlebars http://git.io/handlebars I have $ ./gitio http://pandamonia.us/ * github.com URLs only $ ./gitio https://github.com/pandamonia/OHAttributedLabel http://git.io/jx45wg $ ./gitio github.com/johnezang/JSONKit/issues/47\#issuecomment-2485870 http://git.io/JtY5FA Everything works for me. You meant that you always get |
This comment has been minimized.
This comment has been minimized.
@przemoc I'm running Lion 10.7.2 and bash. When I run the three tests you did in the last code block, I get the |
This comment has been minimized.
This comment has been minimized.
@pandamonia: Cut out line 13 to 20 (inclusive) and then it will work, am I quite sure of :) |
This comment has been minimized.
This comment has been minimized.
@knarf-se / Re: https://gist.github.com/przemoc/1275673/#comment-63754: Like the following?
|
This comment has been minimized.
This comment has been minimized.
I know I'm super late to this party, but... Shouldn't you just update your Regex to match the one written by @defunkt in https://gist.github.com/defunkt/1209316#file-gitio-L12? So this: It appears that there have been a number of updates to the original gist since you created this one. |
This comment has been minimized.
This comment has been minimized.
@rex, being super late is fine, but you're also super wrong (sorry, I couldn't resist...). @defunkt's gist has only 3 revisions and the last one is only a name change. All his revisions are from September 2011. My gist was created later (October 2011) and originally included regexp anchors ( And if you're talking about forks, I haven't checked them. I just looked at the forks of my script right now (only 2 introduced some changes) and I don't see any important stuff there. @rduenasf replaced I always appreciate suggestions, comments and questions, but I don't like rushed and showy ones, because they usually lack even the most basic research regarding commented matters. |
This comment has been minimized.
This comment has been minimized.
http://git.io/gitio points here |
This comment has been minimized.
This comment has been minimized.
I pushed very small update - https is used now (it should be used for quite some time already). |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
Based on @defunkt's ruby snippet.