diff options
| author | Jokler <jokler@protonmail.com> | 2020-06-22 02:15:52 +0200 |
|---|---|---|
| committer | Jokler <jokler@protonmail.com> | 2020-06-22 02:21:55 +0200 |
| commit | 37ccc5b7f8eaac129cfa5a229ff2c4e16d6fc929 (patch) | |
| tree | ff1446fe9b369112bdd41aaa02bc99343a9ecdf8 /scripts/open-url | |
| parent | 1a357dd0a71d8e6d73cc8af4c93d3005576aff36 (diff) | |
| download | dotfiles-37ccc5b7f8eaac129cfa5a229ff2c4e16d6fc929.tar.gz dotfiles-37ccc5b7f8eaac129cfa5a229ff2c4e16d6fc929.zip | |
Add new scripts and update old ones
Diffstat (limited to 'scripts/open-url')
| -rwxr-xr-x | scripts/open-url | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/open-url b/scripts/open-url new file mode 100755 index 0000000..9b67374 --- /dev/null +++ b/scripts/open-url @@ -0,0 +1,47 @@ +#!/usr/bin/env scriptisto + +// scriptisto-begin +// script_src: src/main.rs +// build_cmd: cargo build --release && strip ./target/release/script +// target_bin: ./target/release/script +// files: +// - path: Cargo.toml +// content: | +// package = { name = "script", version = "0.1.0", edition = "2018"} +// [dependencies] +// scripttools = { path = "/home/jokler/rust/scripttools" } +// structopt="*" +// cmd_lib = "*" +// regex = "*" +// scriptisto-end + +use structopt::StructOpt; +use cmd_lib::*; +use scripttools::*; + +#[derive(Debug, StructOpt)] +#[structopt(name = "open-url", about = "Opens urls in their respective programs")] +struct Opt { + /// The url to open + url: String, +} + +fn main() { + let opt = Opt::from_args(); + if let Err(e) = run(opt) { + eprintln!("{}", e); + } +} + +fn run(opt: Opt) -> Result<()> { + let url = opt.url; + + let yt_re = regex::Regex::new(r"^https?://(www\.)?(youtube\.com/watch|youtu\.be/)").unwrap(); + if yt_re.is_match(&url) { + Ok(run_cmd!("umpv \"{}\"", url)?) + } else { + Ok(run_cmd!("firefox \"{}\"", url)?) + } +} + +// vim: filetype=rust |
