mirror of https://github.com/bobwen-dev/hunter
add startup options
This commit is contained in:
parent
3085d0ec0e
commit
d1e9c1645b
|
@ -54,6 +54,16 @@ dependencies = [
|
|||
"rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "0.1.2"
|
||||
|
@ -124,6 +134,20 @@ dependencies = [
|
|||
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.33.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cloudabi"
|
||||
version = "0.0.3"
|
||||
|
@ -417,6 +441,7 @@ dependencies = [
|
|||
"alphanumeric-sort 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"async_value 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dirs-2 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1121,6 +1146,11 @@ name = "stable_deref_trait"
|
|||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.15.34"
|
||||
|
@ -1167,6 +1197,14 @@ dependencies = [
|
|||
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "0.3.6"
|
||||
|
@ -1252,6 +1290,11 @@ name = "utf8-ranges"
|
|||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.1.5"
|
||||
|
@ -1321,6 +1364,7 @@ dependencies = [
|
|||
"checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392"
|
||||
"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71"
|
||||
"checksum async_value 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e9c7275a202ffc12d7307fc4899390c3c64af7198c49015b3242c11892f93414"
|
||||
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
|
||||
"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799"
|
||||
"checksum backtrace 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "45934a579eff9fd0ff637ac376a4bd134f47f8fc603f0b211d696b54d61e35f1"
|
||||
"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6"
|
||||
|
@ -1331,6 +1375,7 @@ dependencies = [
|
|||
"checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d"
|
||||
"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
|
||||
"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
|
||||
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
|
||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
"checksum color_quant 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd"
|
||||
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
|
||||
|
@ -1442,10 +1487,12 @@ dependencies = [
|
|||
"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
||||
"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be"
|
||||
"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
|
||||
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe"
|
||||
"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f"
|
||||
"checksum systemstat 0.1.5 (git+https://github.com/myfreeweb/systemstat)" = "<none>"
|
||||
"checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea"
|
||||
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
|
||||
"checksum tiff 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1e4834f28a0330cb9f3f2c87d2649dca723cb33802e2bdcf18da32759fbec7ce"
|
||||
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
|
||||
|
@ -1457,6 +1504,7 @@ dependencies = [
|
|||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
"checksum users 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7fed7d0912567d35f88010c23dbaf865e9da8b5227295e8dc0f2fdd109155ab7"
|
||||
"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737"
|
||||
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
|
||||
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
|
||||
"checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1"
|
||||
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
||||
|
|
|
@ -33,6 +33,7 @@ mime_guess = "2.0.0-alpha.6"
|
|||
async_value = "0.2"
|
||||
osstrtools = "0.1"
|
||||
pathbuftools = "0.1"
|
||||
clap = "2.33"
|
||||
|
||||
|
||||
|
||||
|
|
15
README.md
15
README.md
|
@ -107,6 +107,21 @@ media_autostart=off
|
|||
media_mute=off
|
||||
```
|
||||
|
||||
## Startup options
|
||||
You can set a few options when hunter starts. These override the configuration file. You can also tell hunter to start in a certain directory.
|
||||
|
||||
**USAGE: hunter [FLAGS] [path]**
|
||||
**FLAGS: **
|
||||
| -a, --animation-off | Turn off animations |
|
||||
| --help | Prints help information |
|
||||
| -i, --icons | Show icons for different file types |
|
||||
| -h, --show-hiddenn | Show hidden files |
|
||||
| -V, --version | Prints version information |
|
||||
|
||||
**ARGS:**
|
||||
|<path> | Start in <path> |
|
||||
|
||||
|
||||
## Drop into hunter cwd on quit
|
||||
To change the directory of your shell when quitting hunter with Q you need to source extra/hunter_cd.sh, which is a wrapper that runs hunter and checks for ~/.hunter_cwd after hunter exits and cd's into the contained directory if it exists.
|
||||
|
||||
|
|
|
@ -1,6 +1,72 @@
|
|||
use lazy_static;
|
||||
use clap;
|
||||
|
||||
use std::sync::RwLock;
|
||||
|
||||
use crate::paths;
|
||||
|
||||
use crate::fail::{HError, HResult, ErrorLog};
|
||||
|
||||
#[derive(Clone)]
|
||||
// These are options, so we know if they have been set or not
|
||||
struct ArgvConfig {
|
||||
animation: Option<bool>,
|
||||
show_hidden: Option<bool>,
|
||||
icons: Option<bool>
|
||||
}
|
||||
|
||||
impl ArgvConfig {
|
||||
fn new() -> Self {
|
||||
ArgvConfig {
|
||||
animation: None,
|
||||
show_hidden: None,
|
||||
icons: None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref ARGV_CONFIG: RwLock<ArgvConfig> = RwLock::new(ArgvConfig::new());
|
||||
}
|
||||
|
||||
|
||||
pub fn set_argv_config(args: clap::ArgMatches) -> HResult<()> {
|
||||
let animation = args.is_present("animation-off");
|
||||
let show_hidden = args.is_present("show-hidden");
|
||||
let icons = args.is_present("icons");
|
||||
|
||||
let mut config = ArgvConfig::new();
|
||||
|
||||
if animation == true {
|
||||
config.animation = Some(false);
|
||||
}
|
||||
|
||||
if show_hidden == true {
|
||||
config.show_hidden = Some(true);
|
||||
}
|
||||
|
||||
if icons == true {
|
||||
config.icons = Some(true)
|
||||
}
|
||||
|
||||
*ARGV_CONFIG.write()? = config;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_argv_config() -> HResult<ArgvConfig> {
|
||||
Ok(ARGV_CONFIG.try_read()?.clone())
|
||||
}
|
||||
|
||||
fn infuse_argv_config(mut config: Config) -> Config {
|
||||
let argv_config = get_argv_config().unwrap_or(ArgvConfig::new());
|
||||
|
||||
argv_config.animation.map(|val| config.animation = val);
|
||||
argv_config.show_hidden.map(|val| config.show_hidden = val);
|
||||
argv_config.icons.map(|val| config.icons = val);
|
||||
|
||||
config
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub animation: bool,
|
||||
|
@ -15,6 +81,12 @@ pub struct Config {
|
|||
|
||||
impl Config {
|
||||
pub fn new() -> Config {
|
||||
let config = Config::default();
|
||||
|
||||
infuse_argv_config(config)
|
||||
}
|
||||
|
||||
pub fn default() -> Config {
|
||||
Config {
|
||||
animation: true,
|
||||
show_hidden: false,
|
||||
|
@ -30,7 +102,7 @@ impl Config {
|
|||
let config_path = paths::config_path()?;
|
||||
|
||||
if !config_path.exists() {
|
||||
return Ok(Config::new());
|
||||
return Ok(infuse_argv_config(Config::new()));
|
||||
}
|
||||
|
||||
let config_string = std::fs::read_to_string(config_path)?;
|
||||
|
@ -59,6 +131,9 @@ impl Config {
|
|||
}
|
||||
config
|
||||
});
|
||||
|
||||
let config = infuse_argv_config(config);
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
|
|
49
src/main.rs
49
src/main.rs
|
@ -22,12 +22,14 @@ extern crate signal_notify;
|
|||
extern crate tree_magic;
|
||||
extern crate systemstat;
|
||||
extern crate mime_guess;
|
||||
extern crate clap;
|
||||
|
||||
extern crate osstrtools;
|
||||
extern crate pathbuftools;
|
||||
extern crate async_value;
|
||||
|
||||
use failure::Fail;
|
||||
use clap::{App, Arg};
|
||||
|
||||
use std::panic;
|
||||
|
||||
|
@ -90,6 +92,8 @@ fn main() -> HResult<()> {
|
|||
// do this early so it might be ready when needed
|
||||
crate::files::load_tags().ok();
|
||||
|
||||
parse_args().ok();
|
||||
|
||||
let mut core = WidgetCore::new().expect("Can't create WidgetCore!");
|
||||
|
||||
// Resets terminal when hunter crashes :(
|
||||
|
@ -119,3 +123,48 @@ fn run(mut core: WidgetCore) -> HResult<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn parse_args() -> HResult<()> {
|
||||
let args = App::new("Lag-free terminal file browser")
|
||||
.version(clap::crate_version!())
|
||||
.author(clap::crate_authors!("\n"))
|
||||
.about("Hunt your files at light-speed, armed with full $SHELL integration")
|
||||
.arg(
|
||||
Arg::with_name("animation-off")
|
||||
.short("a")
|
||||
.long("animation-off")
|
||||
.help("Turn off animations")
|
||||
.takes_value(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("show-hidden")
|
||||
.short("h")
|
||||
.long("show-hidden")
|
||||
.help("Show hidden files")
|
||||
.takes_value(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("icons")
|
||||
.short("i")
|
||||
.long("icons")
|
||||
.help("Show icons for different file types")
|
||||
.takes_value(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("path")
|
||||
.index(1)
|
||||
.help("Start in <path>")
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
|
||||
let path = args.value_of("path");
|
||||
|
||||
if let Some(path) = path {
|
||||
std::env::set_current_dir(&path).ok();
|
||||
}
|
||||
|
||||
crate::config::set_argv_config(args).ok();
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue