diff options
author | Jesse Luehrs <doy@tozt.net> | 2018-11-04 19:50:48 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2018-11-04 19:50:48 -0500 |
commit | 8c0eddee79183434320409039bf6921289fad1e6 (patch) | |
tree | 27de4891b6775c36dc3ea43fe6a705d23a6ebfb8 | |
parent | 85053502b15b6587f956c81d416afd2fa38bfeab (diff) | |
download | open-link-8c0eddee79183434320409039bf6921289fad1e6.tar.gz open-link-8c0eddee79183434320409039bf6921289fad1e6.zip |
initial implementation
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Cargo.lock | 78 | ||||
-rw-r--r-- | Cargo.toml | 8 | ||||
-rw-r--r-- | src/main.rs | 21 |
4 files changed, 109 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53eaa21 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +**/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..ea3b0df --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,78 @@ +[[package]] +name = "cfg-if" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.43" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "linkify" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "memchr" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "open" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "open-link" +version = "0.1.0" +dependencies = [ + "linkify 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "open 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "version_check" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" +"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" +"checksum linkify 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9ce9439c6f4a1092dc1861272bef01034891da39f13aa1cdcf40ca3e4081de5f" +"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16" +"checksum open 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eedfa0ca7b54d84d948bfd058b8f82e767d11f362dd78c36866fd1f69c175867" +"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c661230 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "open-link" +version = "0.1.0" +authors = ["Jesse Luehrs <doy@tozt.net>"] + +[dependencies] +linkify = "0.3" +open = "1.2" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..6d5cc60 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,21 @@ +extern crate linkify; +extern crate open; + +use std::io::prelude::*; + +fn read_stdin() -> String { + let mut input = String::new(); + let stdin = std::io::stdin(); + let mut stdin_handle = stdin.lock(); + stdin_handle.read_to_string(&mut input).unwrap(); + return input; +} + +fn main() { + let input = read_stdin(); + let finder = linkify::LinkFinder::new(); + let links: Vec<_> = finder.links(&input).map(|l| l.as_str()).collect(); + if links.len() > 0 { + open::that(links[links.len() - 1]).unwrap(); + } +} |