Browse Source

First commit

master
Alex Williams 3 years ago
commit
b78ce55c33
Signed by: aw GPG Key ID: 19EE4AAA361A7E2C
3 changed files with 109 additions and 0 deletions
  1. +20
    -0
      LICENSE
  2. +43
    -0
      README.md
  3. +46
    -0
      git.io.l

+ 20
- 0
LICENSE View File

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2018 Alexander Williams, Unscramble <license@unscramble.jp>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 43
- 0
README.md View File

@ -0,0 +1,43 @@
# Git.io in PicoLisp
Command-line client for GitHub's URL shortener [git.io](https://git.io).
# Requirements
* `curl` with https support
* `PicoLisp`
# Usage
### shorten a github.com URL
```
pil git.io.l "https://github.com/aw/picolisp-git.io"
https://git.io/vhUj0
```
### shorten a github.com URL with custom code
```
pil git.io.l "https://github.com/aw/picolisp-json" piljson
https://git.io/piljson
```
### lengthen a shortened git.io URL
```
chmod +x git.io.l
./git.io.l "https://git.io/piljson"
https://github.com/aw/picolisp-json
```
# Alternatives
* [git.io (Ruby)](https://github.com/jgorset/git.io)
# License
[MIT License](LICENSE)
Copyright (c) 2018 Alexander Williams, Unscramble <license@unscramble.jp>

+ 46
- 0
git.io.l View File

@ -0,0 +1,46 @@
#!/usr/bin/env pil
#
# Shorten a URL using git.io
#
# The MIT License (MIT)
# Copyright (c) 2018 Alexander Williams, Unscramble <license@unscramble.jp>
#
# v0.1
#
# Usage: git.io.l <url> <code>
# exit and print an error message to STDERR
[de gitio-error (Msg Code)
(default Code 1)
(msg "git.io.l:" " " 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 GitHub.com or git.io URL") ]
# convert a full URL to a git.io URL
# free variables: Url, Code
[de gitio-shorten ()
(unless Url (gitio-error "You must specify a URL to shorten"))
(gitio-curl "https://git.io" "-F" (pack "url=" Url) (when Code (list "-F" (pack "code=" Code) ]
# convert a git.io 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)
(prinl
(if (pre? "https://git.io" (lowc Url))
(gitio-lengthen)
(gitio-shorten) ]
(gitio-process)
(bye)

Loading…
Cancel
Save