Merge pull request #2 from sleeplessval/use_editor
Merging "use_editor" and "flags"
This commit is contained in:
commit
c533630ff8
3 changed files with 29 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "open"
|
name = "open"
|
||||||
version = "0.3.1"
|
version = "0.4.0"
|
||||||
authors = ["Valerie Wolfe <sleeplessval@gmail.com>"]
|
authors = ["Valerie Wolfe <sleeplessval@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ For example, for
|
||||||
[open]
|
[open]
|
||||||
# zero-operand command
|
# zero-operand command
|
||||||
command = atom .
|
command = atom .
|
||||||
|
# use $EDITOR to edit files without specified commands?
|
||||||
|
use_editor = true
|
||||||
|
|
||||||
[.md]
|
[.md]
|
||||||
command = typora
|
command = typora
|
||||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -1,5 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
env::{args, current_dir},
|
env::{args, current_dir, var},
|
||||||
path::Path,
|
path::Path,
|
||||||
process::{Command, exit, Stdio}
|
process::{Command, exit, Stdio}
|
||||||
};
|
};
|
||||||
|
@ -104,11 +104,32 @@ FLAGS:
|
||||||
}
|
}
|
||||||
let i_exe = config.get(ext, "command");
|
let i_exe = config.get(ext, "command");
|
||||||
if i_exe.is_none() {
|
if i_exe.is_none() {
|
||||||
match ext {
|
let use_editor = config.getbool("open", "use_editor");
|
||||||
"dir" => println!("open: no command specified for directories."),
|
if use_editor.is_ok() && use_editor.ok().unwrap().unwrap() {
|
||||||
_ => println!("open: no command specified for \"{}\" files.", ext)
|
let i_editor = var("EDITOR");
|
||||||
|
if i_editor.is_err() {
|
||||||
|
println!("open: encountered an error trying to access $EDITOR");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
let editor = i_editor.ok().unwrap();
|
||||||
|
if editor.is_empty() {
|
||||||
|
println!("open: $EDITOR is not defined.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
let mut command = Command::new(editor);
|
||||||
|
command.args(vec![i_target]);
|
||||||
|
command.stdout(Stdio::inherit())
|
||||||
|
.stderr(Stdio::inherit())
|
||||||
|
.stdin(Stdio::inherit());
|
||||||
|
command.output().ok();
|
||||||
|
exit(0);
|
||||||
|
} else {
|
||||||
|
match ext {
|
||||||
|
"dir" => println!("open: no command specified for directories."),
|
||||||
|
_ => println!("open: no command specified for \"{}\" files.", ext)
|
||||||
|
}
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
let exe = i_exe.unwrap();
|
let exe = i_exe.unwrap();
|
||||||
let mut parts = exe.split(" ");
|
let mut parts = exe.split(" ");
|
||||||
|
|
Loading…
Reference in a new issue