Compare commits
No commits in common. "5b20a34c7d6d6660390bfb60759d56540c0ead3b" and "c99ef1a7b069bdc8126c9e31b2cb833f61de6cec" have entirely different histories.
5b20a34c7d
...
c99ef1a7b0
4 changed files with 22 additions and 87 deletions
|
@ -1,14 +1,10 @@
|
||||||
[package]
|
[package]
|
||||||
name = "open"
|
name = "open"
|
||||||
version = "0.6.0"
|
version = "0.3.0"
|
||||||
authors = ["Valerie Wolfe <sleeplessval@gmail.com>"]
|
authors = ["Valerie Wolfe <sleeplessval@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
configparser = "3.0.0"
|
configparser = "2.0.1"
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
strip = "debuginfo"
|
|
||||||
|
|
||||||
|
|
27
README.md
27
README.md
|
@ -1,27 +0,0 @@
|
||||||
# open
|
|
||||||
|
|
||||||
A Rust reimplementation of `xdg-open` command. It's written to be quickly and easily customizable, features separate local and global configs, and a zero-operand command allowing the user to specify how files should be opened differently, and for opening a project, etc.
|
|
||||||
|
|
||||||
For example, for
|
|
||||||
|
|
||||||
```ini
|
|
||||||
[open]
|
|
||||||
# zero-operand command
|
|
||||||
command = atom .
|
|
||||||
# use $EDITOR to edit files without specified commands?
|
|
||||||
use_editor = true
|
|
||||||
|
|
||||||
[.md]
|
|
||||||
command = typora
|
|
||||||
|
|
||||||
[.rs]
|
|
||||||
command = atom
|
|
||||||
|
|
||||||
[filename:.gitignore]
|
|
||||||
command = vim
|
|
||||||
shell = true
|
|
||||||
```
|
|
||||||
|
|
||||||
I can use `open` to open the directory in Atom, or I could use `open src/main.rs` to open `main.rs` in Atom, and I can specify these on a per-project basis.
|
|
||||||
|
|
||||||
For directories with a local config, any missing values will be filled in by the global config (`~/.config/open.conf`), which means local configs can be shorter.
|
|
|
@ -9,8 +9,8 @@ use configparser::ini::Ini;
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub local: Option<Ini>,
|
pub local: Option<Ini>,
|
||||||
pub global: Option<Ini>,
|
pub global: Option<Ini>,
|
||||||
pub local_path: Option<String>,
|
local_path: Option<String>,
|
||||||
pub global_path: Option<String>
|
global_path: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
@ -86,15 +86,13 @@ impl Config {
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
pub fn getbool(&self, section: &str, key: &str) -> Option<bool> {
|
pub fn getbool(&self, section: &str, key: &str) -> Result<Option<bool>, String> {
|
||||||
let mut output = None;
|
let mut output = Ok(None);
|
||||||
if self.local.is_some() {
|
if self.local.is_some() {
|
||||||
let i_out = self.local.as_ref().unwrap().getbool(section, key);
|
output = self.local.as_ref().unwrap().getbool(section, key);
|
||||||
output = i_out.unwrap_or(None);
|
|
||||||
}
|
}
|
||||||
if output.is_none() && self.global.is_some() {
|
if output.clone().ok().is_none() && self.global.is_some() {
|
||||||
let i_out = self.global.as_ref().unwrap().getbool(section, key);
|
output = self.global.as_ref().unwrap().getbool(section, key);
|
||||||
output = i_out.unwrap_or(None);
|
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
42
src/main.rs
42
src/main.rs
|
@ -1,5 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
env::{args, current_dir, var},
|
env::{args, current_dir},
|
||||||
path::Path,
|
path::Path,
|
||||||
process::{Command, exit, Stdio}
|
process::{Command, exit, Stdio}
|
||||||
};
|
};
|
||||||
|
@ -22,9 +22,9 @@ fn main() {
|
||||||
match arg.as_str() {
|
match arg.as_str() {
|
||||||
"-h" |
|
"-h" |
|
||||||
"--help" => {
|
"--help" => {
|
||||||
println!("open v0.6.0
|
println!("open
|
||||||
Valerie Wolfe <sleeplessval@gmail.com>
|
Valerie Wolfe <sleeplessval@gmail.com>
|
||||||
A Rust reimplementation of \"xdg-open\" configurable with an ini file.
|
A Linux implementation of the \"open\" command on Mac OS written in Rust and easily configurable.
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
open [FLAGS] [OPERAND]
|
open [FLAGS] [OPERAND]
|
||||||
|
@ -32,8 +32,6 @@ USAGE:
|
||||||
FLAGS:
|
FLAGS:
|
||||||
-h, --help Prints this help text
|
-h, --help Prints this help text
|
||||||
-a, --add Add a handler for a operand type
|
-a, --add Add a handler for a operand type
|
||||||
-p, --path Prints the config path used
|
|
||||||
-v, --version Prints the version number
|
|
||||||
");
|
");
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
|
@ -54,17 +52,7 @@ FLAGS:
|
||||||
}
|
}
|
||||||
config.write().ok();
|
config.write().ok();
|
||||||
return;
|
return;
|
||||||
},
|
|
||||||
"-p" |
|
|
||||||
"--path" => {
|
|
||||||
let local = config.local_path;
|
|
||||||
if local.is_some() {
|
|
||||||
println!("{}", local.unwrap());
|
|
||||||
} else {
|
|
||||||
println!("{}", config.global_path.unwrap());
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
},
|
|
||||||
_ => {
|
_ => {
|
||||||
if file_operand {
|
if file_operand {
|
||||||
error = Some("open: too many file operands.".to_string());
|
error = Some("open: too many file operands.".to_string());
|
||||||
|
@ -105,33 +93,13 @@ 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() {
|
||||||
let use_editor = config.getbool("open", "use_editor");
|
|
||||||
if use_editor.unwrap_or(false) {
|
|
||||||
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 {
|
match ext {
|
||||||
|
"open" => println!("open: no zero-operand command specified."),
|
||||||
"dir" => println!("open: no command specified for directories."),
|
"dir" => println!("open: no command specified for directories."),
|
||||||
_ => println!("open: no command specified for \"{}\" files.", ext)
|
_ => 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(" ");
|
||||||
let mut command = Command::new(parts.next().unwrap());
|
let mut command = Command::new(parts.next().unwrap());
|
||||||
|
@ -143,7 +111,7 @@ FLAGS:
|
||||||
command.args(param)
|
command.args(param)
|
||||||
.current_dir(dir);
|
.current_dir(dir);
|
||||||
|
|
||||||
let is_sh = config.getbool(ext, "shell").unwrap_or(false);
|
let is_sh = config.getbool(ext, "shell").ok().unwrap_or(Some(false)).unwrap_or(false);
|
||||||
if is_sh {
|
if is_sh {
|
||||||
command.stdout(Stdio::inherit())
|
command.stdout(Stdio::inherit())
|
||||||
.stderr(Stdio::inherit())
|
.stderr(Stdio::inherit())
|
||||||
|
|
Loading…
Reference in a new issue