about summary refs log tree commit diff
path: root/fun/uggc/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'fun/uggc/main.go')
-rw-r--r--fun/uggc/main.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/fun/uggc/main.go b/fun/uggc/main.go
new file mode 100644
index 000000000000..94f8cf092507
--- /dev/null
+++ b/fun/uggc/main.go
@@ -0,0 +1,38 @@
+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)
+	}
+}