You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

#!/usr/bin/env pil
# Shorten a URL using
# The MIT License (MIT)
# Copyright (c) 2018 Alexander Williams, Unscramble <>
# v0.1
# Usage: <url> <code>
# exit and print an error message to STDERR
[de gitio-error (Msg Code)
(default Code 1)
(msg "" " " Msg)
(bye Code) ]
# perform 'curl' call and return the value (list) from the 'Location:' header
[de gitio-curl @
(if (clip (in (append (list 'curl "-s" "-i") (rest)) (while (from "Location:") (line))))
(gitio-error "No response, ensure URL is a valid or URL") ]
# convert a full URL to a URL
# free variables: Url, Code
[de gitio-shorten ()
(unless Url (gitio-error "You must specify a URL to shorten"))
(gitio-curl "" "-F" (pack "url=" Url) (when Code (list "-F" (pack "code=" Code) ]
# convert a URL to its original full URL
# free variables: Url
[de gitio-lengthen ()
(unless Url (gitio-error "You must specify a URL to lengthen"))
(gitio-curl Url) ]
# process the command-line arguments
[de gitio-process ()
(use Url Code
(argv Url Code)
(if (pre? "" (lowc Url))
(gitio-shorten) ]