tvl-depot/fun/uggc/main.go
Kane York 2237a51d10 feat(fun/uggc): create a rot13 url handler
Example usage:
$ /nix/store/9kgpv4n62vhxs971jkvwvvl3msm4wpm8-uggc/bin/uggc 'uggcf://gjvggre.pbz/alnabgrpu/fgnghf/1272363652679524352'

Change-Id: I8fd5f77416116ce1a6ab7f96d3f2c726ef663677
Reviewed-on: https://cl.tvl.fyi/c/depot/+/386
Reviewed-by: tazjin <mail@tazj.in>
Reviewed-by: eta <eta@theta.eu.org>
2020-06-15 18:19:22 +00:00

38 lines
635 B
Go

package main
import (
"fmt"
"os"
"strings"
"github.com/pkg/browser"
)
func rot13(r rune) rune {
if 'a' <= r && r <= 'm' {
return r + ('n' - 'a')
} else if 'n' <= r && r <= 'z' {
return r - ('n' - 'a')
}
if 'A' <= r && r <= 'M' {
return r + ('N' - 'A')
} else if 'N' <= r && r <= 'Z' {
return r - ('N' - 'A')
}
return r
}
func main() {
if len(os.Args) == 0 {
fmt.Println("usage: uggc [rot13-encoded URL]")
return
}
urlText := strings.Join(os.Args[1:], " ")
corrected := strings.Map(rot13, urlText)
err := browser.OpenURL(corrected)
if err != nil {
fmt.Println("could not launch browser:", err)
}
}