diff options
author | Kane York <kanepyork@gmail.com> | 2020-06-15T17·20-0700 |
---|---|---|
committer | riking <rikingcoding@gmail.com> | 2020-06-15T18·19+0000 |
commit | 2237a51d10c7ffd30ca3ef08762212f271fee01e (patch) | |
tree | adefa578d60dc934743eaa2f394155e6ad191658 | |
parent | 9885b70b7aa8e90da930a2cab2af9318d4bede88 (diff) |
feat(fun/uggc): create a rot13 url handler r/968
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>
-rw-r--r-- | fun/uggc/default.nix | 14 | ||||
-rw-r--r-- | fun/uggc/main.go | 38 | ||||
-rw-r--r-- | fun/uggc/uggc.desktop | 7 | ||||
-rw-r--r-- | fun/uggc/uggc.reg | 23 | ||||
-rw-r--r-- | third_party/gopkgs/github.com/pkg/browser/default.nix | 12 |
5 files changed, 94 insertions, 0 deletions
diff --git a/fun/uggc/default.nix b/fun/uggc/default.nix new file mode 100644 index 000000000000..398e7b6ffe6c --- /dev/null +++ b/fun/uggc/default.nix @@ -0,0 +1,14 @@ +{ depot, ... }@args: + +let + gopkgs = depot.third_party.gopkgs; +in +depot.nix.buildGo.program { + name = "uggc"; + srcs = [ + ./main.go + ]; + deps = [ + gopkgs."github.com".pkg.browser.gopkg + ]; +} 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) + } +} diff --git a/fun/uggc/uggc.desktop b/fun/uggc/uggc.desktop new file mode 100644 index 000000000000..5203277f4ab4 --- /dev/null +++ b/fun/uggc/uggc.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Type=Application +Name=Rot13 URL Handler +Exec=uggc %u +StartupNotify=false +MimeType=x-scheme-handler/uggc; +MimeType=x-scheme-handler/uggcf; diff --git a/fun/uggc/uggc.reg b/fun/uggc/uggc.reg new file mode 100644 index 000000000000..bfb8e1952f7e --- /dev/null +++ b/fun/uggc/uggc.reg @@ -0,0 +1,23 @@ +Windows Registry Editor Version 5.00 + +[HKEY_CLASSES_ROOT\uggc] +"URL Protocol"="" +@="URL:Rot13 HTTP URL Protocol" + +[HKEY_CLASSES_ROOT\uggcf] +"URL Protocol"="" +@="URL:Rot13 HTTPS URL Protocol" + +[HKEY_CLASSES_ROOT\uggc\shell] + +[HKEY_CLASSES_ROOT\uggcf\shell] + +[HKEY_CLASSES_ROOT\uggc\shell\open] + +[HKEY_CLASSES_ROOT\uggcf\shell\open] + +[HKEY_CLASSES_ROOT\uggc\shell\open\command] +@="\"C:\\Program Files\\uggc\\uggc.exe\" \"%1\"" + +[HKEY_CLASSES_ROOT\uggcf\shell\open\command] +@="\"C:\\Program Files\\uggc\\uggc.exe\" \"%1\"" diff --git a/third_party/gopkgs/github.com/pkg/browser/default.nix b/third_party/gopkgs/github.com/pkg/browser/default.nix new file mode 100644 index 000000000000..ae685e50b356 --- /dev/null +++ b/third_party/gopkgs/github.com/pkg/browser/default.nix @@ -0,0 +1,12 @@ +{ depot, ... }: + +depot.buildGo.external { + path = "github.com/pkg/browser"; + + src = depot.third_party.fetchFromGitHub { + owner = "pkg"; + repo = "browser"; + rev = "0a3d74bf9ce488f035cf5bc36f753a711bc74334"; + sha256 = "0lv6kwvm31n79mh14a63zslaf4l9bspi2q0i8i9im4njfl42iv1c"; + }; +} |