-
Notifications
You must be signed in to change notification settings - Fork 118
Open
Description
Named go-links are great, but sometimes you have a throwaway URL you just want a short pointer to, akin to bit.ly. I have a small helper function that I'm using to create these sort of links manually, but it'd be nice for golink to support this in the UI and auto-generate unique shortlinks.
What I have today:
go-link() {
local short=${1:?short-name} url=$2
if [[ -n "$url" ]]; then
# create a new go-link
if go-link "$short" &>/dev/null; then
echo "go/${short} already exists: http://go/${short}+" >&2
return 1
fi
curl -sS -L --fail --post302 -H Sec-Golink:1 -d "short=${short}" -d "long=${url}" go >/dev/null
else
# query for existing go-link
curl -sS -L --fail "go/${short}+"
fi && echo "http://go/${short}+"
}
shortn() {
local url=${1:?url} hash
until [[ -n "$hash" ]] && ! go-link "$hash" &>/dev/null; do
hash=shortn-$(md5sum <<<"$RANDOM$url" | head -c 8)
done
go-link "$hash" "$url"
}
Metadata
Metadata
Assignees
Labels
No labels