blob: 6d4d084d1b68d2282fbcba3207d8bc7ac4afe831 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#!/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 = "*"
// scriptisto-end
use structopt::StructOpt;
use cmd_lib::*;
use scripttools::*;
#[derive(Debug, StructOpt)]
#[structopt(name = "autoscript", about = "A script to create scripts")]
struct Opt {
/// Name of the created script
name: String,
}
fn main() {
let opt = Opt::from_args();
if let Err(e) = run(opt) {
eprintln!("{}", e);
}
}
fn run(opt: Opt) -> Result<()> {
let script_folder = home()?.join("scripts");
let script_file = script_folder.join(&opt.name);
let str_path = script_file.to_str().ok_or("Failed to convert path to str")?;
if file_exists(&script_file)? == false {
let content = run_fun!("scriptisto new rust")?;
write_to_file(&script_file, &content)?;
run_cmd!("chmod +x \"{}\"", str_path)?;
}
Ok(run_cmd!("gvim \"{}\" &", str_path)?)
}
// vim: filetype=rust
|