diff --git a/Cargo.lock b/Cargo.lock index 4aed033..7c98f8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,23 +82,6 @@ dependencies = [ "vec_map", ] -[[package]] -name = "console" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c0994e656bba7b922d8dd1245db90672ffb701e684e45be58f20719d69abc5a" -dependencies = [ - "encode_unicode", - "lazy_static", - "libc", - "regex", - "terminal_size", - "termios", - "unicode-width", - "winapi", - "winapi-util", -] - [[package]] name = "constant_time_eq" version = "0.1.5" @@ -116,17 +99,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "dialoguer" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4aa86af7b19b40ef9cbef761ed411a49f0afa06b7b6dcd3dfe2f96a3c546138" -dependencies = [ - "console", - "lazy_static", - "tempfile", -] - [[package]] name = "dirs" version = "2.0.2" @@ -139,28 +111,20 @@ dependencies = [ [[package]] name = "dirs-sys" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" +checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" dependencies = [ - "cfg-if", "libc", "redox_users", "winapi", ] -[[package]] -name = "encode_unicode" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" - [[package]] name = "eureka" version = "1.6.3" dependencies = [ "clap", - "dialoguer", "dirs", "termcolor", "which", @@ -198,71 +162,24 @@ version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" -[[package]] -name = "ppv-lite86" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" - [[package]] name = "proc-macro2" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1502d12e458c49a4c9cbff560d0fe0060c252bc29799ed94ca2ed4bb665a0101" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom", - "libc", - "rand_chacha", - "rand_core", - "rand_hc", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core", -] - [[package]] name = "redox_syscall" version = "0.1.56" @@ -280,30 +197,6 @@ dependencies = [ "rust-argon2", ] -[[package]] -name = "regex" -version = "1.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" -dependencies = [ - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" - -[[package]] -name = "remove_dir_all" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" -dependencies = [ - "winapi", -] - [[package]] name = "rust-argon2" version = "0.7.0" @@ -324,29 +217,15 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" -version = "1.0.29" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb37da98a55b1d08529362d9cbb863be17556873df2585904ab9d2bc951291d0" +checksum = "93a56fabc59dce20fe48b6c832cc249c713e7ed88fa28b0ee0a3bfcaae5fe4e2" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] -[[package]] -name = "tempfile" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" -dependencies = [ - "cfg-if", - "libc", - "rand", - "redox_syscall", - "remove_dir_all", - "winapi", -] - [[package]] name = "termcolor" version = "1.1.0" @@ -356,25 +235,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "terminal_size" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8038f95fc7a6f351163f4b964af631bd26c9e828f7db085f2a84aca56f70d13b" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "termios" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0fcee7b24a25675de40d5bb4de6e41b0df07bc9856295e7e2b3a3600c400c2" -dependencies = [ - "libc", -] - [[package]] name = "textwrap" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index 597ca80..e5e300c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,5 @@ exclude = [ [dependencies] clap = "2.33.1" dirs = "2.0.2" -dialoguer = "0.6.2" termcolor = "1.1.0" which = "4.0.0" diff --git a/README.md b/README.md index b26b0bd..ff640f9 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ is the default structure when you create an empty repository with a readme on GitHub, so it's easy to start using it. And since it's your own repository you can make it private to keep your ideas secret. +`eureka` looks at your environment variables to decide what program to use. +* `$EDITOR` for what to edit your ideas with (falls back to `vim`) +* `$PAGER` for what to view your ideas with (falls back to `less`) + ## Installation **[Homebrew](https://brew.sh/)** @@ -30,14 +34,13 @@ $ cargo install eureka ``` ## Usage -The first time you run `eureka` it will ask a few questions regarding your -setup. This configuration will be stored in `~/.eureka/`. +The first time you run `eureka` it will ask for the path to your ideas repo. +This configuration will be stored in `~/.eureka/`. After the setup simply run `eureka` to capture an idea. It will then be committed and pushed to `origin/master`. -View your stored ideas in `$PAGER` env variable (falls back to `less`) with the -`-v` or `--view` flag. +View your stored ideas with the `-v` or `--view` flag. ```sh $ eureka --view @@ -46,9 +49,8 @@ $ eureka --view ### Flags ```sh ---clear-editor Clear the stored path to your idea editor ---clear-repo Clear the stored path to your idea repo --v, --view View ideas with your $PAGER env variable. If unset use less +--clear-repo Clear the stored path to your idea repo +-v, --view View ideas with your $PAGER env variable. If unset use less ``` ### Recommended alias diff --git a/src/bin/eureka.rs b/src/bin/eureka.rs index 6ed0e4e..b52180b 100644 --- a/src/bin/eureka.rs +++ b/src/bin/eureka.rs @@ -3,7 +3,6 @@ extern crate eureka; #[macro_use] extern crate clap; -extern crate dialoguer; extern crate termcolor; use std::io; @@ -28,11 +27,6 @@ fn main() { .long(ClearRepo.value()) .help("Clear the stored path to your idea repo"), ) - .arg( - Arg::with_name(ClearEditor.value()) - .long(ClearEditor.value()) - .help("Clear the stored path to your idea editor"), - ) .arg( Arg::with_name(View.value()) .long(View.value()) @@ -51,20 +45,8 @@ fn main() { printer: Printer { writer: output }, }; - // Exit if any "clear" flag was provided - let mut should_exit = false; - if cli_flags.is_present(ClearRepo.value()) { eureka.clear_repo(); - should_exit = true; - } - - if cli_flags.is_present(ClearEditor.value()) { - eureka.clear_editor(); - should_exit = true; - } - - if should_exit { exit_w_code(0); } diff --git a/src/file_handler.rs b/src/file_handler.rs index 9a101c9..09344a4 100644 --- a/src/file_handler.rs +++ b/src/file_handler.rs @@ -102,7 +102,6 @@ impl ConfigManagement for FileHandler { fn config_path_for(config_type: ConfigFile) -> String { let file_name = match config_type { ConfigFile::Repo => ConfigFile::Repo.value(), - ConfigFile::Editor => ConfigFile::Editor.value(), }; match home_dir() { diff --git a/src/lib.rs b/src/lib.rs index b5a0e0a..c86ab6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,5 @@ -extern crate dialoguer; extern crate termcolor; -use dialoguer::Select; use termcolor::WriteColor; use std::io::{BufRead, Write}; @@ -11,7 +9,7 @@ use std::{env, io}; use file_handler::{ConfigManagement, FileHandler, FileManagement}; use printer::{Print, Printer}; use reader::{Read, Reader}; -use types::ConfigFile::{Editor, Repo}; +use types::ConfigFile::Repo; use utils::get_if_available; pub mod file_handler; @@ -48,11 +46,6 @@ where self.setup_repo_path().unwrap(); } - // If editor path is missing - ask for it - if self.fh.config_read(Editor).is_err() { - self.setup_editor_path().unwrap(); - } - self.printer .print("First time setup complete. Happy ideation!"); } else { @@ -68,14 +61,6 @@ where } } - pub fn clear_editor(&self) { - if self.fh.config_read(Editor).is_ok() { - self.fh - .file_rm(Editor) - .expect("Could not remove editor config file"); - } - } - pub fn open_idea_file(&self) { match self.fh.config_read(Repo) { Ok(repo_path) => self.open_pager(repo_path).unwrap(), @@ -96,62 +81,40 @@ where self.fh.config_write(Repo, input_repo_path) } - fn setup_editor_path(&mut self) -> io::Result<()> { - self.printer.print_editor_selection_header(); - - let select_index = Select::new() - .default(0) - .items(&["vim", "nano", "Other (provide name, e.g. 'emacs')"]) - .interact() - .unwrap(); - - let chosen_editor = match select_index { - 0 => "vim".to_string(), - 1 => "nano".to_string(), - 2 => { - self.printer.print_input_header(""); - self.printer.flush().unwrap(); - self.reader.read() - } - _ => panic!("You should not be able to get here"), - }; - - let editor_path = get_if_available(chosen_editor.as_str()).unwrap_or_else(|| { - panic!("Could not find executable for {} - aborting", chosen_editor) - }); - - self.fh.config_write(Editor, editor_path) - } - fn is_first_time_run(&self) -> bool { - self.fh.config_read(Repo).is_err() && self.fh.config_read(Editor).is_err() + self.fh.config_read(Repo).is_err() } fn is_config_missing(&self) -> bool { - self.fh.config_read(Repo).is_err() || self.fh.config_read(Editor).is_err() + self.fh.config_read(Repo).is_err() } fn input_idea(&mut self) { self.printer.print_input_header(">> Idea summary"); let idea_summary = self.reader.read(); - let editor_path = self.fh.config_read(Editor).unwrap(); let repo_path = self.fh.config_read(Repo).unwrap(); let readme_path = format!("{}/README.md", repo_path); - match self.open_editor(&editor_path, &readme_path) { + match self.open_editor(&readme_path) { Ok(_) => git::commit_and_push(&repo_path, idea_summary).unwrap(), - Err(e) => panic!("Could not open editor at path {}: {}", editor_path, e), + Err(e) => panic!(e), }; } - fn open_editor(&self, bin_path: &str, file_path: &str) -> io::Result<()> { - match Command::new(bin_path).arg(file_path).status() { + fn open_editor(&self, file_path: &str) -> io::Result<()> { + let editor = match env::var("EDITOR") { + Ok(e) => e, + Err(_) => { + get_if_available("vim").expect("Cannot locate executable - vim - on your system") + } + }; + match Command::new(&editor).arg(file_path).status() { Ok(_) => Ok(()), Err(e) => { eprintln!( "Error: Unable to open file [{}] with editor binary at [{}]: {}", - file_path, bin_path, e + file_path, editor, e ); Err(e) } diff --git a/src/types.rs b/src/types.rs index 728585a..94bae97 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,20 +1,17 @@ pub enum CliFlag { ClearRepo, - ClearEditor, View, ShortView, } pub enum ConfigFile { Repo, - Editor, } impl CliFlag { pub fn value(&self) -> &str { match *self { CliFlag::ClearRepo => "clear-repo", - CliFlag::ClearEditor => "clear-editor", CliFlag::View => "view", CliFlag::ShortView => "v", } @@ -26,7 +23,6 @@ impl ConfigFile { match *self { // These represents files so underscore is preferred ConfigFile::Repo => "repo_path", - ConfigFile::Editor => "editor_path", } } }