From 2561d50a48bfb7da86f134cd4aa2b79ac1430dc7 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Fri, 13 Mar 2020 21:20:38 -0300 Subject: [PATCH 01/27] Initial cheat repo support --- Cargo.lock | 121 ++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/cmds/mod.rs | 1 + src/filesystem.rs | 21 +++----- src/main.rs | 1 + src/option.rs | 2 + 6 files changed, 134 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b431f064..431a1ce6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,6 +16,16 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "arrayvec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "atty" version = "0.2.14" @@ -26,11 +36,36 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "base64" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "blake2b_simd" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "clap" version = "2.33.0" @@ -45,6 +80,21 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "derive_more" version = "0.14.1" @@ -56,6 +106,36 @@ dependencies = [ "syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dirs" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dirs-sys" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_users 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "getrandom" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)", + "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "heck" version = "0.3.1" @@ -91,6 +171,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "navi" version = "2.0.11" dependencies = [ + "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "raw_tty 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -182,6 +263,16 @@ dependencies = [ "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "redox_users" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-argon2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "regex" version = "1.3.4" @@ -198,6 +289,17 @@ name = "regex-syntax" version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rust-argon2" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "blake2b_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc_version" version = "0.2.3" @@ -347,6 +449,11 @@ name = "vec_map" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "winapi" version = "0.3.8" @@ -369,10 +476,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum aho-corasick 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "743ad5a418686aad3b87fd14c43badd828cf26e214a00f92a384291cf22e1811" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" +"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +"checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +"checksum blake2b_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +"checksum constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +"checksum crossbeam-utils 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" "checksum derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d944ac6003ed268757ef1ee686753b57efc5fcf0ebe7b64c9fc81e7e32ff839" +"checksum dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" +"checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" +"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hermit-abi 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" @@ -388,8 +506,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum raw_tty 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "51f512d7504049ef0d3f5d48d8aa5129beaea4fccfaf5c500c9b60101394f8b1" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +"checksum redox_users 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "09b23093265f8d200fa7b4c2c76297f47e681c655f6f1285a8780d6a022f7431" "checksum regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "322cf97724bea3ee221b78fe25ac9c46114ebb51747ad5babd51a2fc6a8235a8" "checksum regex-syntax 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)" = "b28dfe3fe9badec5dbf0a79a9cccad2cfc2ab5484bdb3e44cbd1ae8b3ba2be06" +"checksum rust-argon2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustversion 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b3bba175698996010c4f6dce5e7f173b6eb781fce25d2cfc45e27091ce0b79f6" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" @@ -409,6 +529,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +"checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 5e3a649b..d4ea2e7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,5 @@ structopt = "0.3" termion = "1.5.5" raw_tty = "0.1.0" lazy_static = "1.4.0" +dirs = "2.0.0" terminal_size = "0.1.10" diff --git a/src/cmds/mod.rs b/src/cmds/mod.rs index 1c7a9203..47f6be45 100644 --- a/src/cmds/mod.rs +++ b/src/cmds/mod.rs @@ -7,3 +7,4 @@ pub mod preview; pub mod query; pub mod search; pub mod shell; +pub mod repo; \ No newline at end of file diff --git a/src/filesystem.rs b/src/filesystem.rs index ed3ecc6c..c2241d5f 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -1,9 +1,10 @@ use std::fs; -use std::fs::metadata; use std::fs::File; use std::io::{self, BufRead, BufReader, Lines}; use std::path::{Path, PathBuf}; +use dirs; + pub fn read_lines

(filename: P) -> io::Result>> where P: AsRef, @@ -40,20 +41,14 @@ fn exe_pathbuf() -> PathBuf { } pub fn cheat_pathbuf() -> Option { - let exe_parent_str = exe_parent_string(); - - let array = ["cheats", "../libexec/cheats", "../cheats", "../../cheats"]; - for elem in &array { - let p = format!("{}/{}", exe_parent_str, elem); - let meta = metadata(&p); - if let Ok(m) = meta { - if m.is_dir() { - return Some(PathBuf::from(p)); - } + match dirs::config_dir() { + Some(mut d) => { + d.push("navi"); + d.push("cheats"); + Some(d) } + None => None, } - - None } pub fn shell_pathbuf() -> PathBuf { diff --git a/src/main.rs b/src/main.rs index 4b498620..e9c05a1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,7 @@ fn main() -> Result<(), Box> { Command::Widget { shell } => cmds::shell::main(&shell[..]), Command::Fn { func, args } => cmds::func::main(func.clone(), args.to_vec()), Command::Home => cmds::home::main(), + Command::Repo => cmds::repo::main(), }, } } diff --git a/src/option.rs b/src/option.rs index 39254cba..d79c5d03 100644 --- a/src/option.rs +++ b/src/option.rs @@ -58,6 +58,8 @@ pub enum Command { Best { query: String, args: Vec }, /// Performs ad-hoc functions provided by navi Fn { func: String, args: Vec }, + /// Repo + Repo, /// Shows the path for shell widget files Widget { shell: String }, } From 4948e334aa32618521f3aa487f58765e18f93836 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Fri, 13 Mar 2020 21:21:29 -0300 Subject: [PATCH 02/27] Initial cheat repo support --- src/cmds/mod.rs | 2 +- src/cmds/repo.rs | 25 +++++++++++++++++++++++++ src/filesystem.rs | 2 -- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/cmds/repo.rs diff --git a/src/cmds/mod.rs b/src/cmds/mod.rs index 47f6be45..85e6e37c 100644 --- a/src/cmds/mod.rs +++ b/src/cmds/mod.rs @@ -5,6 +5,6 @@ pub mod func; pub mod home; pub mod preview; pub mod query; +pub mod repo; pub mod search; pub mod shell; -pub mod repo; \ No newline at end of file diff --git a/src/cmds/repo.rs b/src/cmds/repo.rs new file mode 100644 index 00000000..615132f2 --- /dev/null +++ b/src/cmds/repo.rs @@ -0,0 +1,25 @@ +use std::error::Error; +use std::process::{Command, Stdio}; + +use crate::filesystem; + +pub fn main() -> Result<(), Box> { + let cheat_path = filesystem::cheat_pathbuf(); + let cheat_path_str = filesystem::pathbuf_to_string(cheat_path.unwrap()); + + let cmd = format!("user=\"{user}\" && repo=\"{repo}\" && url=\"https://github.com/${{user}}/${{repo}}/archive/master.tar.gz\" && path=\"{cheat_path}/tmp\"; mkdir -p \"${{path}}\"; cd \"${{path}}\"; (wget -c \"$url\" -O - || curl -L \"$url\") | tar -xz && find \"${{repo}}-master\" -name \"*.cheat\"", cheat_path = cheat_path_str, user = "denisidoro", repo = "navi"); + + let child = Command::new("bash") + .arg("-c") + .arg(cmd.as_str()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .unwrap(); + + let out = String::from_utf8(child.wait_with_output().unwrap().stdout).unwrap(); + + println!("{}", out); + + Ok(()) +} diff --git a/src/filesystem.rs b/src/filesystem.rs index c2241d5f..bae3e4fd 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -3,8 +3,6 @@ use std::fs::File; use std::io::{self, BufRead, BufReader, Lines}; use std::path::{Path, PathBuf}; -use dirs; - pub fn read_lines

(filename: P) -> io::Result>> where P: AsRef, From 04c08654fb77cc447aaf247906b1eaaa5632d448 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Fri, 13 Mar 2020 22:20:18 -0300 Subject: [PATCH 03/27] qip --- src/cmds/repo.rs | 20 +++++++++++++++++--- src/fzf.rs | 6 ++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/cmds/repo.rs b/src/cmds/repo.rs index 615132f2..de71c1f9 100644 --- a/src/cmds/repo.rs +++ b/src/cmds/repo.rs @@ -1,13 +1,15 @@ use std::error::Error; use std::process::{Command, Stdio}; +use std::io::Write; +use crate::fzf; use crate::filesystem; pub fn main() -> Result<(), Box> { let cheat_path = filesystem::cheat_pathbuf(); let cheat_path_str = filesystem::pathbuf_to_string(cheat_path.unwrap()); - let cmd = format!("user=\"{user}\" && repo=\"{repo}\" && url=\"https://github.com/${{user}}/${{repo}}/archive/master.tar.gz\" && path=\"{cheat_path}/tmp\"; mkdir -p \"${{path}}\"; cd \"${{path}}\"; (wget -c \"$url\" -O - || curl -L \"$url\") | tar -xz && find \"${{repo}}-master\" -name \"*.cheat\"", cheat_path = cheat_path_str, user = "denisidoro", repo = "navi"); + let cmd = format!("user=\"{user}\" && repo=\"{repo}\" && url=\"https://github.com/${{user}}/${{repo}}/archive/master.tar.gz\" && path=\"{cheat_path}/tmp\"; mkdir -p \"${{path}}\"; cd \"${{path}}\"; (wget -c \"$url\" -O - || curl -L \"$url\") | tar -xz && cd \"${{repo}}-master\"; find . -name \"*.cheat\"", cheat_path = cheat_path_str, user = "denisidoro", repo = "navi"); let child = Command::new("bash") .arg("-c") @@ -17,9 +19,21 @@ pub fn main() -> Result<(), Box> { .spawn() .unwrap(); - let out = String::from_utf8(child.wait_with_output().unwrap().stdout).unwrap(); + let all_files = String::from_utf8(child.wait_with_output().unwrap().stdout).unwrap(); - println!("{}", out); + let opts = fzf::Opts { + multi: true, + preview: false, + header: Some("Select the cheatsheets you want to import with then hit ".to_string()), + ..Default::default() + }; + + let (files, _) = fzf::call(opts, |stdin| { + stdin.write_all(all_files.as_bytes()).unwrap(); + None + }); + + println!("{}", files); Ok(()) } diff --git a/src/fzf.rs b/src/fzf.rs index c4016c7e..46d3a3c6 100644 --- a/src/fzf.rs +++ b/src/fzf.rs @@ -14,6 +14,7 @@ pub struct Opts<'a> { pub autoselect: bool, pub overrides: Option<&'a String>, // TODO: remove &'a pub header_lines: u8, + pub header: Option, pub multi: bool, pub copyable: bool, pub suggestions: bool, @@ -28,6 +29,7 @@ impl Default for Opts<'_> { autoselect: true, overrides: None, header_lines: 0, + header: None, prompt: None, multi: false, copyable: false, @@ -81,6 +83,10 @@ where if let Some(f) = opts.filter { c.args(&["--filter", &f]); } + + if let Some(h) = opts.header { + c.args(&["--header", &h]); + } if let Some(p) = opts.prompt { c.args(&["--prompt", &p]); From de7d33d83a9099c611efc3b962201d65cd49abc6 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Sat, 14 Mar 2020 00:41:42 -0300 Subject: [PATCH 04/27] wip --- src/cmds/repo.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/cmds/repo.rs b/src/cmds/repo.rs index de71c1f9..aa7f4b6f 100644 --- a/src/cmds/repo.rs +++ b/src/cmds/repo.rs @@ -1,15 +1,24 @@ use std::error::Error; use std::process::{Command, Stdio}; use std::io::Write; +use std::fs; use crate::fzf; use crate::filesystem; pub fn main() -> Result<(), Box> { + let user = "denisidoro"; + let repo = "navi"; let cheat_path = filesystem::cheat_pathbuf(); let cheat_path_str = filesystem::pathbuf_to_string(cheat_path.unwrap()); + let repo_folder_str = format!("{}-master", repo); + let tmp_path_str = format!("{}/tmp", cheat_path_str); - let cmd = format!("user=\"{user}\" && repo=\"{repo}\" && url=\"https://github.com/${{user}}/${{repo}}/archive/master.tar.gz\" && path=\"{cheat_path}/tmp\"; mkdir -p \"${{path}}\"; cd \"${{path}}\"; (wget -c \"$url\" -O - || curl -L \"$url\") | tar -xz && cd \"${{repo}}-master\"; find . -name \"*.cheat\"", cheat_path = cheat_path_str, user = "denisidoro", repo = "navi"); + let cmd = format!("url=\"https://github.com/{user}/{repo}/archive/master.tar.gz\" && mkdir -p \"{tmp_path}\"; cd \"{tmp_path}\"; (wget -c \"$url\" -O - || curl -L \"$url\") | tar -xz && cd \"{repo_folder}\"; find . -name \"*.cheat\"", + tmp_path = tmp_path_str, + repo_folder = repo_folder_str, + user = user, + repo = repo); let child = Command::new("bash") .arg("-c") @@ -35,5 +44,14 @@ pub fn main() -> Result<(), Box> { println!("{}", files); + for f in files.split('\n') { + let from = format!("{}/{}/{}", tmp_path_str, repo_folder_str, f).replace("./", ""); + let to_folder = format!("{}/{}/{}", cheat_path_str, user, repo).replace("./", ""); + let to = format!("{}/{}", to_folder, f).replace("./", ""); + println!("{} -> {}", from, to); + fs::create_dir_all(to_folder).unwrap_or(()); + fs::copy(from, to)?; + } + Ok(()) } From cfbede4824ff3ee5ffe8215b038d00b8a1e53a3e Mon Sep 17 00:00:00 2001 From: asd Date: Sat, 14 Mar 2020 18:29:55 -0300 Subject: [PATCH 05/27] wip --- src/fzf.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fzf.rs b/src/fzf.rs index 43a567d6..e5900200 100644 --- a/src/fzf.rs +++ b/src/fzf.rs @@ -35,6 +35,9 @@ impl Default for Opts<'_> { header: None, prompt: None, suggestion_type: SingleSelection, + copyable: false, + multi: false, + suggestions: false } } } @@ -94,7 +97,7 @@ where } if let Some(h) = opts.header { - c.args(&["--header", &h]); + fzf_command.args(&["--header", &h]); } if let Some(p) = opts.prompt { From d210738cdee7a82b740a50a7b07416066f598852 Mon Sep 17 00:00:00 2001 From: asd Date: Sat, 14 Mar 2020 18:54:17 -0300 Subject: [PATCH 06/27] wip --- src/cmds/repo.rs | 9 ++++++--- src/fzf.rs | 6 ------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/cmds/repo.rs b/src/cmds/repo.rs index aa7f4b6f..4203515d 100644 --- a/src/cmds/repo.rs +++ b/src/cmds/repo.rs @@ -2,9 +2,11 @@ use std::error::Error; use std::process::{Command, Stdio}; use std::io::Write; use std::fs; +use std::vec::Vec; use crate::fzf; use crate::filesystem; +use crate::cheat::SuggestionType; pub fn main() -> Result<(), Box> { let user = "denisidoro"; @@ -31,7 +33,7 @@ pub fn main() -> Result<(), Box> { let all_files = String::from_utf8(child.wait_with_output().unwrap().stdout).unwrap(); let opts = fzf::Opts { - multi: true, + suggestion_type: SuggestionType::MultipleSelections, preview: false, header: Some("Select the cheatsheets you want to import with then hit ".to_string()), ..Default::default() @@ -47,8 +49,9 @@ pub fn main() -> Result<(), Box> { for f in files.split('\n') { let from = format!("{}/{}/{}", tmp_path_str, repo_folder_str, f).replace("./", ""); let to_folder = format!("{}/{}/{}", cheat_path_str, user, repo).replace("./", ""); - let to = format!("{}/{}", to_folder, f).replace("./", ""); - println!("{} -> {}", from, to); + let parts: Vec<&str> = f.split('/').collect(); + let filename = parts.last().unwrap(); + let to = format!("{}/{}", to_folder, filename); fs::create_dir_all(to_folder).unwrap_or(()); fs::copy(from, to)?; } diff --git a/src/fzf.rs b/src/fzf.rs index e5900200..06ce2c7b 100644 --- a/src/fzf.rs +++ b/src/fzf.rs @@ -17,9 +17,6 @@ pub struct Opts<'a> { pub overrides: Option<&'a String>, // TODO: remove &'a pub header_lines: u8, pub header: Option, - pub multi: bool, - pub copyable: bool, - pub suggestions: bool, pub suggestion_type: SuggestionType, } @@ -35,9 +32,6 @@ impl Default for Opts<'_> { header: None, prompt: None, suggestion_type: SingleSelection, - copyable: false, - multi: false, - suggestions: false } } } From 9eee7e5cab35220ea016eb5adfe13bfbea8c567e Mon Sep 17 00:00:00 2001 From: asd Date: Sat, 14 Mar 2020 21:42:09 -0300 Subject: [PATCH 07/27] wip --- README.md | 6 +++--- src/cmds/home.rs | 8 -------- src/cmds/mod.rs | 1 - src/cmds/repo.rs | 34 ++++++++++++++++++++-------------- src/cmds/shell.rs | 16 +++++----------- src/filesystem.rs | 33 ++++++++++++++++----------------- src/main.rs | 20 ++++++++++++-------- src/option.rs | 13 ++++++++++--- 8 files changed, 66 insertions(+), 65 deletions(-) delete mode 100644 src/cmds/home.rs diff --git a/README.md b/README.md index 6939ac01..09ea02e5 100644 --- a/README.md +++ b/README.md @@ -91,13 +91,13 @@ You can use **navi** as a widget to your shell. This way, your history is correc In order to use it, add this line to your `.bashrc`-like file: ```sh # bash -source "$(navi widget bash)" +source <(navi widget bash) # zsh -source "$(navi widget zsh)" +source <(navi widget zsh) # fish -source (navi widget fish) +navi widget fish | source ``` By default, `Ctrl+G` is assigned to launching **navi**. If you want to change the keybinding, replace the argument of `bind` or `bindkey` in [the widget file](https://github.com/denisidoro/navi/search?q=filename%3Anavi.plugin.*&unscoped_q=filename%3Anavi.plugin.*). diff --git a/src/cmds/home.rs b/src/cmds/home.rs deleted file mode 100644 index a38d825b..00000000 --- a/src/cmds/home.rs +++ /dev/null @@ -1,8 +0,0 @@ -use std::error::Error; - -use crate::filesystem; - -pub fn main() -> Result<(), Box> { - println!("{}", filesystem::exe_parent_string()); - Ok(()) -} diff --git a/src/cmds/mod.rs b/src/cmds/mod.rs index 85e6e37c..6b0925d2 100644 --- a/src/cmds/mod.rs +++ b/src/cmds/mod.rs @@ -2,7 +2,6 @@ pub mod aux; pub mod best; pub mod core; pub mod func; -pub mod home; pub mod preview; pub mod query; pub mod repo; diff --git a/src/cmds/repo.rs b/src/cmds/repo.rs index 4203515d..7f43b3e3 100644 --- a/src/cmds/repo.rs +++ b/src/cmds/repo.rs @@ -2,21 +2,28 @@ use std::error::Error; use std::process::{Command, Stdio}; use std::io::Write; use std::fs; -use std::vec::Vec; use crate::fzf; use crate::filesystem; use crate::cheat::SuggestionType; -pub fn main() -> Result<(), Box> { - let user = "denisidoro"; - let repo = "navi"; - let cheat_path = filesystem::cheat_pathbuf(); - let cheat_path_str = filesystem::pathbuf_to_string(cheat_path.unwrap()); +pub fn add(uri: String) -> Result<(), Box> { + let mut parts = uri.split('/'); + let user = parts.next().unwrap(); + let repo = parts.next().unwrap(); + let cheat_path_str = filesystem::pathbuf_to_string(filesystem::cheat_pathbuf().unwrap()); let repo_folder_str = format!("{}-master", repo); let tmp_path_str = format!("{}/tmp", cheat_path_str); - let cmd = format!("url=\"https://github.com/{user}/{repo}/archive/master.tar.gz\" && mkdir -p \"{tmp_path}\"; cd \"{tmp_path}\"; (wget -c \"$url\" -O - || curl -L \"$url\") | tar -xz && cd \"{repo_folder}\"; find . -name \"*.cheat\"", + // TODO: stop shell'ing out + let cmd = format!(r#" + url="https://github.com/{user}/{repo}/archive/master.tar.gz"; + mkdir -p "{tmp_path}"; + cd "{tmp_path}"; + (wget -c "$url" -O - || curl -L "$url") | tar -xz || exit 42; + cd "{repo_folder}"; + find . -name "*.cheat" + "#, tmp_path = tmp_path_str, repo_folder = repo_folder_str, user = user, @@ -28,7 +35,7 @@ pub fn main() -> Result<(), Box> { .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() - .unwrap(); + .expect("Unable to download or extract repository"); let all_files = String::from_utf8(child.wait_with_output().unwrap().stdout).unwrap(); @@ -40,21 +47,20 @@ pub fn main() -> Result<(), Box> { }; let (files, _) = fzf::call(opts, |stdin| { - stdin.write_all(all_files.as_bytes()).unwrap(); + stdin.write_all(all_files.as_bytes()).expect("Unable to prompt cheats to import"); None }); - println!("{}", files); - for f in files.split('\n') { let from = format!("{}/{}/{}", tmp_path_str, repo_folder_str, f).replace("./", ""); - let to_folder = format!("{}/{}/{}", cheat_path_str, user, repo).replace("./", ""); - let parts: Vec<&str> = f.split('/').collect(); - let filename = parts.last().unwrap(); + let to_folder = format!("{}/{}__{}", cheat_path_str, user, repo).replace("./", ""); + let filename = f.replace("./", "").replace("/", "__"); let to = format!("{}/{}", to_folder, filename); fs::create_dir_all(to_folder).unwrap_or(()); fs::copy(from, to)?; } + fs::remove_dir_all(tmp_path_str).unwrap_or(()); + Ok(()) } diff --git a/src/cmds/shell.rs b/src/cmds/shell.rs index d562bde3..81f5831d 100644 --- a/src/cmds/shell.rs +++ b/src/cmds/shell.rs @@ -1,19 +1,13 @@ use std::error::Error; -use crate::filesystem; - pub fn main(shell: &str) -> Result<(), Box> { - let file = match shell { - "zsh" => "navi.plugin.zsh", - "fish" => "navi.plugin.fish", - _ => "navi.plugin.bash", + let content = match shell { + "zsh" => include_str!("../../shell/navi.plugin.zsh"), + "fish" => include_str!("../../shell/navi.plugin.fish"), + _ => include_str!("../../shell/navi.plugin.bash"), }; - println!( - "{}/{}", - filesystem::pathbuf_to_string(filesystem::shell_pathbuf()), - file - ); + println!("{}", content); Ok(()) } diff --git a/src/filesystem.rs b/src/filesystem.rs index bae3e4fd..94d35b09 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -12,7 +12,22 @@ where } pub fn pathbuf_to_string(pathbuf: PathBuf) -> String { - pathbuf.as_os_str().to_str().unwrap().to_string() + pathbuf + .as_os_str() + .to_str() + .unwrap() + .to_string() +} + +pub fn cheat_pathbuf() -> Option { + match dirs::config_dir() { + Some(mut d) => { + d.push("navi"); + d.push("cheats"); + Some(d) + } + None => None, + } } fn follow_symlink(pathbuf: PathBuf) -> PathBuf { @@ -38,22 +53,6 @@ fn exe_pathbuf() -> PathBuf { follow_symlink(pathbuf) } -pub fn cheat_pathbuf() -> Option { - match dirs::config_dir() { - Some(mut d) => { - d.push("navi"); - d.push("cheats"); - Some(d) - } - None => None, - } -} - -pub fn shell_pathbuf() -> PathBuf { - let cheat_path_str = pathbuf_to_string(cheat_pathbuf().unwrap()); - PathBuf::from(format!("{}/../shell", cheat_path_str)) -} - pub fn exe_string() -> String { pathbuf_to_string(exe_pathbuf()) } diff --git a/src/main.rs b/src/main.rs index e9c05a1a..1674c6c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,8 @@ mod option; mod terminal; use crate::cmds::core::Variant; -use option::{Command, InternalCommand}; +use option::{InternalCommand, RepoCommand}; +use option::Command::{Query, Best, Search, Widget, Fn, Repo}; fn main() -> Result<(), Box> { match option::internal_command() { @@ -22,15 +23,18 @@ fn main() -> Result<(), Box> { match config.cmd.as_mut() { None => cmds::core::main(Variant::Core, config, true), Some(c) => match c { - Command::Query { query } => cmds::query::main(query.clone(), config), - Command::Best { query, args } => { + Query { query } => cmds::query::main(query.clone(), config), + Best { query, args } => { cmds::best::main(query.clone(), args.to_vec(), config) } - Command::Search { query } => cmds::search::main(query.clone(), config), - Command::Widget { shell } => cmds::shell::main(&shell[..]), - Command::Fn { func, args } => cmds::func::main(func.clone(), args.to_vec()), - Command::Home => cmds::home::main(), - Command::Repo => cmds::repo::main(), + Search { query } => cmds::search::main(query.clone(), config), + Widget { shell } => cmds::shell::main(&shell[..]), + Fn { func, args } => cmds::func::main(func.clone(), args.to_vec()), + Repo { cmd } => { + match cmd { + RepoCommand::Add { uri } => cmds::repo::add(uri.clone()), + } + } }, } } diff --git a/src/option.rs b/src/option.rs index d79c5d03..8527f811 100644 --- a/src/option.rs +++ b/src/option.rs @@ -50,8 +50,6 @@ pub struct Config { pub enum Command { /// Filters results Query { query: String }, - /// Shows navi's home directory - Home, /// Uses online repositories for cheatsheets Search { query: String }, /// Autoselects the snippet that best matches the query @@ -59,11 +57,20 @@ pub enum Command { /// Performs ad-hoc functions provided by navi Fn { func: String, args: Vec }, /// Repo - Repo, + Repo { + #[structopt(subcommand)] + cmd: RepoCommand, + }, /// Shows the path for shell widget files Widget { shell: String }, } +#[derive(Debug, StructOpt)] +pub enum RepoCommand { + /// Adds a repo (user/repo will download cheats from github.com/user/repo) + Add { uri: String }, +} + pub enum InternalCommand { Preview { line: String }, } From 14644a3b71aa66a208f4665e3a3062efcccf6a13 Mon Sep 17 00:00:00 2001 From: asd Date: Sat, 14 Mar 2020 21:43:49 -0300 Subject: [PATCH 08/27] linting --- src/cmds/repo.rs | 36 +++++++++++++++++++++--------------- src/filesystem.rs | 6 +----- src/fzf.rs | 2 +- src/main.rs | 14 +++++--------- src/option.rs | 6 +++--- 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/cmds/repo.rs b/src/cmds/repo.rs index 7f43b3e3..c45b91e8 100644 --- a/src/cmds/repo.rs +++ b/src/cmds/repo.rs @@ -1,11 +1,11 @@ use std::error::Error; -use std::process::{Command, Stdio}; -use std::io::Write; use std::fs; +use std::io::Write; +use std::process::{Command, Stdio}; -use crate::fzf; -use crate::filesystem; use crate::cheat::SuggestionType; +use crate::filesystem; +use crate::fzf; pub fn add(uri: String) -> Result<(), Box> { let mut parts = uri.split('/'); @@ -16,18 +16,20 @@ pub fn add(uri: String) -> Result<(), Box> { let tmp_path_str = format!("{}/tmp", cheat_path_str); // TODO: stop shell'ing out - let cmd = format!(r#" + let cmd = format!( + r#" url="https://github.com/{user}/{repo}/archive/master.tar.gz"; mkdir -p "{tmp_path}"; cd "{tmp_path}"; (wget -c "$url" -O - || curl -L "$url") | tar -xz || exit 42; cd "{repo_folder}"; find . -name "*.cheat" - "#, - tmp_path = tmp_path_str, - repo_folder = repo_folder_str, - user = user, - repo = repo); + "#, + tmp_path = tmp_path_str, + repo_folder = repo_folder_str, + user = user, + repo = repo + ); let child = Command::new("bash") .arg("-c") @@ -39,15 +41,19 @@ pub fn add(uri: String) -> Result<(), Box> { let all_files = String::from_utf8(child.wait_with_output().unwrap().stdout).unwrap(); - let opts = fzf::Opts { - suggestion_type: SuggestionType::MultipleSelections, - preview: false, - header: Some("Select the cheatsheets you want to import with then hit ".to_string()), + let opts = fzf::Opts { + suggestion_type: SuggestionType::MultipleSelections, + preview: false, + header: Some( + "Select the cheatsheets you want to import with then hit ".to_string(), + ), ..Default::default() }; let (files, _) = fzf::call(opts, |stdin| { - stdin.write_all(all_files.as_bytes()).expect("Unable to prompt cheats to import"); + stdin + .write_all(all_files.as_bytes()) + .expect("Unable to prompt cheats to import"); None }); diff --git a/src/filesystem.rs b/src/filesystem.rs index 94d35b09..0758ea03 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -12,11 +12,7 @@ where } pub fn pathbuf_to_string(pathbuf: PathBuf) -> String { - pathbuf - .as_os_str() - .to_str() - .unwrap() - .to_string() + pathbuf.as_os_str().to_str().unwrap().to_string() } pub fn cheat_pathbuf() -> Option { diff --git a/src/fzf.rs b/src/fzf.rs index 06ce2c7b..13f7bd50 100644 --- a/src/fzf.rs +++ b/src/fzf.rs @@ -89,7 +89,7 @@ where if let Some(f) = opts.filter { fzf_command.args(&["--filter", &f]); } - + if let Some(h) = opts.header { fzf_command.args(&["--header", &h]); } diff --git a/src/main.rs b/src/main.rs index 1674c6c9..7da056e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,8 +12,8 @@ mod option; mod terminal; use crate::cmds::core::Variant; +use option::Command::{Best, Fn, Query, Repo, Search, Widget}; use option::{InternalCommand, RepoCommand}; -use option::Command::{Query, Best, Search, Widget, Fn, Repo}; fn main() -> Result<(), Box> { match option::internal_command() { @@ -24,17 +24,13 @@ fn main() -> Result<(), Box> { None => cmds::core::main(Variant::Core, config, true), Some(c) => match c { Query { query } => cmds::query::main(query.clone(), config), - Best { query, args } => { - cmds::best::main(query.clone(), args.to_vec(), config) - } + Best { query, args } => cmds::best::main(query.clone(), args.to_vec(), config), Search { query } => cmds::search::main(query.clone(), config), Widget { shell } => cmds::shell::main(&shell[..]), Fn { func, args } => cmds::func::main(func.clone(), args.to_vec()), - Repo { cmd } => { - match cmd { - RepoCommand::Add { uri } => cmds::repo::add(uri.clone()), - } - } + Repo { cmd } => match cmd { + RepoCommand::Add { uri } => cmds::repo::add(uri.clone()), + }, }, } } diff --git a/src/option.rs b/src/option.rs index 8527f811..918958b5 100644 --- a/src/option.rs +++ b/src/option.rs @@ -57,9 +57,9 @@ pub enum Command { /// Performs ad-hoc functions provided by navi Fn { func: String, args: Vec }, /// Repo - Repo { - #[structopt(subcommand)] - cmd: RepoCommand, + Repo { + #[structopt(subcommand)] + cmd: RepoCommand, }, /// Shows the path for shell widget files Widget { shell: String }, From 25cea3c206c4181f7d273f27ffa16c746f7d4548 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Sat, 14 Mar 2020 21:46:05 -0300 Subject: [PATCH 09/27] [WIP] Add welcome cheatsheet (#254) --- src/cheat.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/cheat.rs b/src/cheat.rs index 1c9628f5..4ce7fd9c 100644 --- a/src/cheat.rs +++ b/src/cheat.rs @@ -109,7 +109,7 @@ fn read_file( path: &str, variables: &mut HashMap, stdin: &mut std::process::ChildStdin, -) { +) -> bool { let mut tags = String::from(""); let mut comment = String::from(""); let mut snippet = String::from(""); @@ -160,9 +160,17 @@ fn read_file( snippet.push_str(&line); } } + + return true; } - write_cmd(&tags, &comment, &snippet, tag_width, comment_width, stdin); + false +} + +fn add_msg(tag: &str, comment: &str, snippet: &str, stdin: &mut std::process::ChildStdin) { + stdin + .write_all(display::format_line(tag, comment, snippet, 25, 60).as_bytes()) + .unwrap(); } pub fn read_all( @@ -170,6 +178,7 @@ pub fn read_all( stdin: &mut std::process::ChildStdin, ) -> HashMap { let mut variables: HashMap = HashMap::new(); + let mut found_something = false; let mut fallback: String = String::from(""); let folders_str = config.path.as_ref().unwrap_or_else(|| { @@ -185,13 +194,29 @@ pub fn read_all( for path in paths { let path_os_str = path.unwrap().path().into_os_string(); let path_str = path_os_str.to_str().unwrap(); - if path_str.ends_with(".cheat") { - read_file(path_str, &mut variables, stdin); + if path_str.ends_with(".cheat") && read_file(path_str, &mut variables, stdin) { + found_something = true; } } } } + if !found_something { + add_msg( + "Cheatsheets", + "Download default cheatsheets", + "navi repo add default", + stdin, + ); + add_msg( + "Cheatsheets", + "Browse for cheatsheets to install", + "navi repo browse", + stdin, + ); + add_msg("Shell", "Install shell widget", "navi shell install", stdin); + } + variables } From 1b4c368c732c9bd1cdaf153b8f8ba8910fa36a09 Mon Sep 17 00:00:00 2001 From: asd Date: Sat, 14 Mar 2020 22:47:19 -0300 Subject: [PATCH 10/27] wip --- src/cheat.rs | 60 ++++++++++++++++++++++++++++------------------- src/filesystem.rs | 10 -------- src/option.rs | 2 +- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/cheat.rs b/src/cheat.rs index 4ce7fd9c..5c42411d 100644 --- a/src/cheat.rs +++ b/src/cheat.rs @@ -169,32 +169,56 @@ fn read_file( fn add_msg(tag: &str, comment: &str, snippet: &str, stdin: &mut std::process::ChildStdin) { stdin - .write_all(display::format_line(tag, comment, snippet, 25, 60).as_bytes()) + .write_all(display::format_line(tag, comment, snippet, 10, 60).as_bytes()) .unwrap(); } +fn welcome_cheatsheet(stdin: &mut std::process::ChildStdin) { + add_msg( + "cheatsheets", + "Download default cheatsheets", + "navi repo add denisidoro/navi", + stdin, + ); + add_msg("more info", "Read --help message", "navi --help", stdin); +} + +fn get_paths_from_config_dir() -> String { + let mut paths_str = String::from(""); + + if let Some(f) = filesystem::cheat_pathbuf() { + if let Ok(paths) = fs::read_dir(filesystem::pathbuf_to_string(f)) { + for path in paths { + paths_str.push_str(path.unwrap().path().into_os_string().to_str().unwrap()); + paths_str.push_str(":"); + } + } + } + + paths_str + } + + fn get_paths(config: &Config) -> String { + config.path.clone().unwrap_or_else(|| { + get_paths_from_config_dir() + }) +} + pub fn read_all( config: &Config, stdin: &mut std::process::ChildStdin, ) -> HashMap { let mut variables: HashMap = HashMap::new(); let mut found_something = false; - - let mut fallback: String = String::from(""); - let folders_str = config.path.as_ref().unwrap_or_else(|| { - if let Some(f) = filesystem::cheat_pathbuf() { - fallback = filesystem::pathbuf_to_string(f); - } - &fallback - }); - let folders = folders_str.split(':'); + let paths = get_paths(config); + let folders = paths.split(':'); for folder in folders { if let Ok(paths) = fs::read_dir(folder) { for path in paths { let path_os_str = path.unwrap().path().into_os_string(); let path_str = path_os_str.to_str().unwrap(); - if path_str.ends_with(".cheat") && read_file(path_str, &mut variables, stdin) { + if path_str.ends_with(".cheat") && read_file(path_str, &mut variables, stdin) && !found_something { found_something = true; } } @@ -202,19 +226,7 @@ pub fn read_all( } if !found_something { - add_msg( - "Cheatsheets", - "Download default cheatsheets", - "navi repo add default", - stdin, - ); - add_msg( - "Cheatsheets", - "Browse for cheatsheets to install", - "navi repo browse", - stdin, - ); - add_msg("Shell", "Install shell widget", "navi shell install", stdin); + welcome_cheatsheet(stdin); } variables diff --git a/src/filesystem.rs b/src/filesystem.rs index 0758ea03..04da9cdd 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -52,13 +52,3 @@ fn exe_pathbuf() -> PathBuf { pub fn exe_string() -> String { pathbuf_to_string(exe_pathbuf()) } - -pub fn exe_parent_string() -> String { - exe_pathbuf() - .parent() - .unwrap() - .as_os_str() - .to_str() - .unwrap() - .to_string() -} diff --git a/src/option.rs b/src/option.rs index 918958b5..bcec801b 100644 --- a/src/option.rs +++ b/src/option.rs @@ -56,7 +56,7 @@ pub enum Command { Best { query: String, args: Vec }, /// Performs ad-hoc functions provided by navi Fn { func: String, args: Vec }, - /// Repo + /// Manages cheatsheet repositories Repo { #[structopt(subcommand)] cmd: RepoCommand, From 68509d84740f49e0b82c6de42c85ac463ad7c933 Mon Sep 17 00:00:00 2001 From: asd Date: Sat, 14 Mar 2020 22:47:44 -0300 Subject: [PATCH 11/27] linting --- src/cheat.rs | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/cheat.rs b/src/cheat.rs index 5c42411d..65f7183c 100644 --- a/src/cheat.rs +++ b/src/cheat.rs @@ -174,34 +174,35 @@ fn add_msg(tag: &str, comment: &str, snippet: &str, stdin: &mut std::process::Ch } fn welcome_cheatsheet(stdin: &mut std::process::ChildStdin) { - add_msg( - "cheatsheets", - "Download default cheatsheets", - "navi repo add denisidoro/navi", - stdin, - ); - add_msg("more info", "Read --help message", "navi --help", stdin); + add_msg( + "cheatsheets", + "Download default cheatsheets", + "navi repo add denisidoro/navi", + stdin, + ); + add_msg("more info", "Read --help message", "navi --help", stdin); } fn get_paths_from_config_dir() -> String { let mut paths_str = String::from(""); - if let Some(f) = filesystem::cheat_pathbuf() { - if let Ok(paths) = fs::read_dir(filesystem::pathbuf_to_string(f)) { - for path in paths { + if let Some(f) = filesystem::cheat_pathbuf() { + if let Ok(paths) = fs::read_dir(filesystem::pathbuf_to_string(f)) { + for path in paths { paths_str.push_str(path.unwrap().path().into_os_string().to_str().unwrap()); paths_str.push_str(":"); } } - } - - paths_str } - fn get_paths(config: &Config) -> String { - config.path.clone().unwrap_or_else(|| { - get_paths_from_config_dir() - }) + paths_str +} + +fn get_paths(config: &Config) -> String { + config + .path + .clone() + .unwrap_or_else(|| get_paths_from_config_dir()) } pub fn read_all( @@ -218,7 +219,10 @@ pub fn read_all( for path in paths { let path_os_str = path.unwrap().path().into_os_string(); let path_str = path_os_str.to_str().unwrap(); - if path_str.ends_with(".cheat") && read_file(path_str, &mut variables, stdin) && !found_something { + if path_str.ends_with(".cheat") + && read_file(path_str, &mut variables, stdin) + && !found_something + { found_something = true; } } From 378fc5e4180d2c28739cc9041a115ed2f63b7bd4 Mon Sep 17 00:00:00 2001 From: asd Date: Sun, 15 Mar 2020 09:42:57 -0300 Subject: [PATCH 12/27] wip --- src/cheat.rs | 52 +++++++---------------------------------------- src/cmds/core.rs | 11 +++++++++- src/filesystem.rs | 23 +++++++++++++++++++++ src/fzf.rs | 1 - src/handler.rs | 27 ++++++++++++++++++++++++ src/main.rs | 31 ++++++++-------------------- src/option.rs | 8 ++++++-- src/welcome.rs | 18 ++++++++++++++++ 8 files changed, 99 insertions(+), 72 deletions(-) create mode 100644 src/handler.rs create mode 100644 src/welcome.rs diff --git a/src/cheat.rs b/src/cheat.rs index 65f7183c..06887294 100644 --- a/src/cheat.rs +++ b/src/cheat.rs @@ -1,7 +1,7 @@ use crate::display; use crate::filesystem; use crate::option::Config; - +use crate::welcome; use regex::Regex; use std::collections::HashMap; use std::fs; @@ -31,7 +31,7 @@ pub enum SuggestionType { pub type Suggestion = (String, Option); -fn remove_quote(txt: &str) -> String { +fn remove_quotes(txt: &str) -> String { txt.replace('"', "").replace('\'', "") } @@ -49,10 +49,10 @@ fn parse_opts(text: &str) -> SuggestionOpts { "--multi" => multi = true, "--allow-extra" => allow_extra = true, "--header" | "--headers" | "--header-lines" => { - header_lines = remove_quote(parts.next().unwrap()).parse::().unwrap() + header_lines = remove_quotes(parts.next().unwrap()).parse::().unwrap() } - "--column" => column = Some(remove_quote(parts.next().unwrap()).parse::().unwrap()), - "--delimiter" => delimiter = Some(remove_quote(parts.next().unwrap()).to_string()), + "--column" => column = Some(remove_quotes(parts.next().unwrap()).parse::().unwrap()), + "--delimiter" => delimiter = Some(remove_quotes(parts.next().unwrap()).to_string()), _ => (), } } @@ -167,51 +167,13 @@ fn read_file( false } -fn add_msg(tag: &str, comment: &str, snippet: &str, stdin: &mut std::process::ChildStdin) { - stdin - .write_all(display::format_line(tag, comment, snippet, 10, 60).as_bytes()) - .unwrap(); -} - -fn welcome_cheatsheet(stdin: &mut std::process::ChildStdin) { - add_msg( - "cheatsheets", - "Download default cheatsheets", - "navi repo add denisidoro/navi", - stdin, - ); - add_msg("more info", "Read --help message", "navi --help", stdin); -} - -fn get_paths_from_config_dir() -> String { - let mut paths_str = String::from(""); - - if let Some(f) = filesystem::cheat_pathbuf() { - if let Ok(paths) = fs::read_dir(filesystem::pathbuf_to_string(f)) { - for path in paths { - paths_str.push_str(path.unwrap().path().into_os_string().to_str().unwrap()); - paths_str.push_str(":"); - } - } - } - - paths_str -} - -fn get_paths(config: &Config) -> String { - config - .path - .clone() - .unwrap_or_else(|| get_paths_from_config_dir()) -} - pub fn read_all( config: &Config, stdin: &mut std::process::ChildStdin, ) -> HashMap { let mut variables: HashMap = HashMap::new(); let mut found_something = false; - let paths = get_paths(config); + let paths = filesystem::cheat_paths(config); let folders = paths.split(':'); for folder in folders { @@ -230,7 +192,7 @@ pub fn read_all( } if !found_something { - welcome_cheatsheet(stdin); + welcome::cheatsheet(stdin); } variables diff --git a/src/cmds/core.rs b/src/cmds/core.rs index c74443a0..bc71f049 100644 --- a/src/cmds/core.rs +++ b/src/cmds/core.rs @@ -2,8 +2,9 @@ use crate::cheat; use crate::cmds; use crate::display; use crate::fzf; +use crate::option; use crate::option::Config; - +use crate::handler; use crate::cheat::SuggestionType; use regex::Regex; use std::collections::HashMap; @@ -192,12 +193,20 @@ pub fn main(variant: Variant, config: Config, contains_key: bool) -> Result<(), &config, )); + // copy to clipboard if key == "ctrl-y" { cmds::aux::abort("copying snippets to the clipboard", 201)? + // print to stdout } else if config.print { println!("{}", interpolated_snippet); + // save to file } else if let Some(s) = config.save { fs::write(s, interpolated_snippet)?; + // call navi (this prevents "failed to read /dev/tty" from fzf) + } else if interpolated_snippet.starts_with("navi") { + let new_config = option::config_from_iter(interpolated_snippet.split(" ").collect()); + handler::handle_config(new_config)?; + // shell out and execute snippet } else { Command::new("bash") .arg("-c") diff --git a/src/filesystem.rs b/src/filesystem.rs index 04da9cdd..ab9fc3b4 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -2,6 +2,7 @@ use std::fs; use std::fs::File; use std::io::{self, BufRead, BufReader, Lines}; use std::path::{Path, PathBuf}; +use crate::option::Config; pub fn read_lines

(filename: P) -> io::Result>> where @@ -52,3 +53,25 @@ fn exe_pathbuf() -> PathBuf { pub fn exe_string() -> String { pathbuf_to_string(exe_pathbuf()) } + +fn cheat_paths_from_config_dir() -> String { + let mut paths_str = String::from(""); + + if let Some(f) = cheat_pathbuf() { + if let Ok(paths) = fs::read_dir(pathbuf_to_string(f)) { + for path in paths { + paths_str.push_str(path.unwrap().path().into_os_string().to_str().unwrap()); + paths_str.push_str(":"); + } + } + } + + paths_str +} + +pub fn cheat_paths(config: &Config) -> String { + config + .path + .clone() + .unwrap_or_else(cheat_paths_from_config_dir) +} \ No newline at end of file diff --git a/src/fzf.rs b/src/fzf.rs index 13f7bd50..0e27d12c 100644 --- a/src/fzf.rs +++ b/src/fzf.rs @@ -115,7 +115,6 @@ where let child = fzf_command .stdin(Stdio::piped()) .stdout(Stdio::piped()) - .stderr(Stdio::inherit()) .spawn(); let mut child = match child { diff --git a/src/handler.rs b/src/handler.rs new file mode 100644 index 00000000..54556396 --- /dev/null +++ b/src/handler.rs @@ -0,0 +1,27 @@ +use std::error::Error; +use crate::cmds; +use crate::cmds::core::Variant; +use crate::option::Command::{Best, Fn, Query, Repo, Search, Widget}; +use crate::option::{Config, InternalCommand, RepoCommand}; + +pub fn handle_config(mut config: Config) -> Result<(), Box> { + match config.cmd.as_mut() { + None => cmds::core::main(Variant::Core, config, true), + Some(c) => match c { + Query { query } => cmds::query::main(query.clone(), config), + Best { query, args } => cmds::best::main(query.clone(), args.to_vec(), config), + Search { query } => cmds::search::main(query.clone(), config), + Widget { shell } => cmds::shell::main(&shell[..]), + Fn { func, args } => cmds::func::main(func.clone(), args.to_vec()), + Repo { cmd } => match cmd { + RepoCommand::Add { uri } => cmds::repo::add(uri.clone()), + }, + }, + } + } + +pub fn handle_internal_command(cmd: InternalCommand) -> Result<(), Box> { +match cmd { + InternalCommand::Preview { line } => cmds::preview::main(line), +} +} diff --git a/src/main.rs b/src/main.rs index 7da056e7..77a0c254 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,6 @@ #[macro_use] extern crate lazy_static; -use std::error::Error; - mod cheat; mod cmds; mod display; @@ -10,29 +8,16 @@ mod filesystem; mod fzf; mod option; mod terminal; +mod handler; +mod welcome; -use crate::cmds::core::Variant; -use option::Command::{Best, Fn, Query, Repo, Search, Widget}; -use option::{InternalCommand, RepoCommand}; +use std::error::Error; fn main() -> Result<(), Box> { - match option::internal_command() { - Some(InternalCommand::Preview { line }) => cmds::preview::main(line), - _ => { - let mut config = option::parse(); - match config.cmd.as_mut() { - None => cmds::core::main(Variant::Core, config, true), - Some(c) => match c { - Query { query } => cmds::query::main(query.clone(), config), - Best { query, args } => cmds::best::main(query.clone(), args.to_vec(), config), - Search { query } => cmds::search::main(query.clone(), config), - Widget { shell } => cmds::shell::main(&shell[..]), - Fn { func, args } => cmds::func::main(func.clone(), args.to_vec()), - Repo { cmd } => match cmd { - RepoCommand::Add { uri } => cmds::repo::add(uri.clone()), - }, - }, - } - } + let internal_cmd = option::internal_command_from_env(); + if let Some(cmd) = internal_cmd { + handler::handle_internal_command(cmd) + } else { + handler::handle_config(option::config_from_env()) } } diff --git a/src/option.rs b/src/option.rs index bcec801b..59de7d41 100644 --- a/src/option.rs +++ b/src/option.rs @@ -75,11 +75,15 @@ pub enum InternalCommand { Preview { line: String }, } -pub fn parse() -> Config { +pub fn config_from_env() -> Config { Config::from_args() } -pub fn internal_command() -> Option { +pub fn config_from_iter(args: Vec<&str>) -> Config { + Config::from_iter(args) +} + +pub fn internal_command_from_env() -> Option { let mut args = env::args(); args.next(); if args.next() == Some(String::from("preview")) { diff --git a/src/welcome.rs b/src/welcome.rs new file mode 100644 index 00000000..d0884f1d --- /dev/null +++ b/src/welcome.rs @@ -0,0 +1,18 @@ +use crate::display; +use std::io::Write; + +fn add_msg(tag: &str, comment: &str, snippet: &str, stdin: &mut std::process::ChildStdin) { + stdin + .write_all(display::format_line(tag, comment, snippet, 10, 60).as_bytes()) + .unwrap(); +} + +pub fn cheatsheet(stdin: &mut std::process::ChildStdin) { + add_msg( + "cheatsheets", + "Download default cheatsheets", + "navi repo add denisidoro/navi", + stdin, + ); + add_msg("more info", "Read --help message", "navi --help", stdin); +} \ No newline at end of file From 2b97222f8b033dd7f8b7328a389cf02f8970caf4 Mon Sep 17 00:00:00 2001 From: asd Date: Sun, 15 Mar 2020 09:43:14 -0300 Subject: [PATCH 13/27] linting --- src/cheat.rs | 4 +++- src/cmds/core.rs | 14 +++++++------- src/filesystem.rs | 4 ++-- src/handler.rs | 34 +++++++++++++++++----------------- src/main.rs | 2 +- src/welcome.rs | 2 +- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/cheat.rs b/src/cheat.rs index 06887294..f2be8ee1 100644 --- a/src/cheat.rs +++ b/src/cheat.rs @@ -51,7 +51,9 @@ fn parse_opts(text: &str) -> SuggestionOpts { "--header" | "--headers" | "--header-lines" => { header_lines = remove_quotes(parts.next().unwrap()).parse::().unwrap() } - "--column" => column = Some(remove_quotes(parts.next().unwrap()).parse::().unwrap()), + "--column" => { + column = Some(remove_quotes(parts.next().unwrap()).parse::().unwrap()) + } "--delimiter" => delimiter = Some(remove_quotes(parts.next().unwrap()).to_string()), _ => (), } diff --git a/src/cmds/core.rs b/src/cmds/core.rs index bc71f049..1f05f0f8 100644 --- a/src/cmds/core.rs +++ b/src/cmds/core.rs @@ -1,11 +1,11 @@ use crate::cheat; +use crate::cheat::SuggestionType; use crate::cmds; use crate::display; use crate::fzf; +use crate::handler; use crate::option; use crate::option::Config; -use crate::handler; -use crate::cheat::SuggestionType; use regex::Regex; use std::collections::HashMap; use std::error::Error; @@ -196,17 +196,17 @@ pub fn main(variant: Variant, config: Config, contains_key: bool) -> Result<(), // copy to clipboard if key == "ctrl-y" { cmds::aux::abort("copying snippets to the clipboard", 201)? - // print to stdout + // print to stdout } else if config.print { println!("{}", interpolated_snippet); - // save to file + // save to file } else if let Some(s) = config.save { fs::write(s, interpolated_snippet)?; - // call navi (this prevents "failed to read /dev/tty" from fzf) + // call navi (this prevents "failed to read /dev/tty" from fzf) } else if interpolated_snippet.starts_with("navi") { - let new_config = option::config_from_iter(interpolated_snippet.split(" ").collect()); + let new_config = option::config_from_iter(interpolated_snippet.split(' ').collect()); handler::handle_config(new_config)?; - // shell out and execute snippet + // shell out and execute snippet } else { Command::new("bash") .arg("-c") diff --git a/src/filesystem.rs b/src/filesystem.rs index ab9fc3b4..7c96c059 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -1,8 +1,8 @@ +use crate::option::Config; use std::fs; use std::fs::File; use std::io::{self, BufRead, BufReader, Lines}; use std::path::{Path, PathBuf}; -use crate::option::Config; pub fn read_lines

(filename: P) -> io::Result>> where @@ -74,4 +74,4 @@ pub fn cheat_paths(config: &Config) -> String { .path .clone() .unwrap_or_else(cheat_paths_from_config_dir) -} \ No newline at end of file +} diff --git a/src/handler.rs b/src/handler.rs index 54556396..b5755cb1 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -1,27 +1,27 @@ -use std::error::Error; use crate::cmds; use crate::cmds::core::Variant; use crate::option::Command::{Best, Fn, Query, Repo, Search, Widget}; use crate::option::{Config, InternalCommand, RepoCommand}; +use std::error::Error; pub fn handle_config(mut config: Config) -> Result<(), Box> { - match config.cmd.as_mut() { - None => cmds::core::main(Variant::Core, config, true), - Some(c) => match c { - Query { query } => cmds::query::main(query.clone(), config), - Best { query, args } => cmds::best::main(query.clone(), args.to_vec(), config), - Search { query } => cmds::search::main(query.clone(), config), - Widget { shell } => cmds::shell::main(&shell[..]), - Fn { func, args } => cmds::func::main(func.clone(), args.to_vec()), - Repo { cmd } => match cmd { - RepoCommand::Add { uri } => cmds::repo::add(uri.clone()), - }, - }, - } - } + match config.cmd.as_mut() { + None => cmds::core::main(Variant::Core, config, true), + Some(c) => match c { + Query { query } => cmds::query::main(query.clone(), config), + Best { query, args } => cmds::best::main(query.clone(), args.to_vec(), config), + Search { query } => cmds::search::main(query.clone(), config), + Widget { shell } => cmds::shell::main(&shell[..]), + Fn { func, args } => cmds::func::main(func.clone(), args.to_vec()), + Repo { cmd } => match cmd { + RepoCommand::Add { uri } => cmds::repo::add(uri.clone()), + }, + }, + } +} pub fn handle_internal_command(cmd: InternalCommand) -> Result<(), Box> { -match cmd { + match cmd { InternalCommand::Preview { line } => cmds::preview::main(line), -} + } } diff --git a/src/main.rs b/src/main.rs index 77a0c254..e4c645b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,9 @@ mod cmds; mod display; mod filesystem; mod fzf; +mod handler; mod option; mod terminal; -mod handler; mod welcome; use std::error::Error; diff --git a/src/welcome.rs b/src/welcome.rs index d0884f1d..69e77771 100644 --- a/src/welcome.rs +++ b/src/welcome.rs @@ -15,4 +15,4 @@ pub fn cheatsheet(stdin: &mut std::process::ChildStdin) { stdin, ); add_msg("more info", "Read --help message", "navi --help", stdin); -} \ No newline at end of file +} From ae8ae7b498da642e22a7a1bbacf30659ae8a41bf Mon Sep 17 00:00:00 2001 From: asd Date: Sun, 15 Mar 2020 09:50:19 -0300 Subject: [PATCH 14/27] wip --- src/cmds/best.rs | 1 - src/cmds/core.rs | 1 + src/cmds/preview.rs | 1 - src/cmds/query.rs | 1 - src/cmds/repo.rs | 1 - src/cmds/search.rs | 1 - src/display.rs | 1 - src/fzf.rs | 1 - src/option.rs | 43 +++++++++++++++++++++++++++++++++---------- 9 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/cmds/best.rs b/src/cmds/best.rs index ef449d43..50fd738c 100644 --- a/src/cmds/best.rs +++ b/src/cmds/best.rs @@ -1,5 +1,4 @@ use std::error::Error; - use crate::cmds; use crate::cmds::core::Variant; use crate::option::Config; diff --git a/src/cmds/core.rs b/src/cmds/core.rs index 1f05f0f8..04085979 100644 --- a/src/cmds/core.rs +++ b/src/cmds/core.rs @@ -186,6 +186,7 @@ pub fn main(variant: Variant, config: Config, contains_key: bool) -> Result<(), }); let (key, tags, snippet) = extract_from_selections(&raw_selection[..], contains_key); + let interpolated_snippet = with_new_lines(replace_variables_from_snippet( snippet, tags, diff --git a/src/cmds/preview.rs b/src/cmds/preview.rs index bbb04031..9607a2f8 100644 --- a/src/cmds/preview.rs +++ b/src/cmds/preview.rs @@ -1,6 +1,5 @@ use std::error::Error; use std::process; - use crate::display; fn extract_elements(argstr: &str) -> (&str, &str, &str) { diff --git a/src/cmds/query.rs b/src/cmds/query.rs index 627d67bf..7f7fa2d0 100644 --- a/src/cmds/query.rs +++ b/src/cmds/query.rs @@ -1,5 +1,4 @@ use std::error::Error; - use crate::cmds; use crate::cmds::core::Variant; use crate::option::Config; diff --git a/src/cmds/repo.rs b/src/cmds/repo.rs index c45b91e8..04f7a2bb 100644 --- a/src/cmds/repo.rs +++ b/src/cmds/repo.rs @@ -2,7 +2,6 @@ use std::error::Error; use std::fs; use std::io::Write; use std::process::{Command, Stdio}; - use crate::cheat::SuggestionType; use crate::filesystem; use crate::fzf; diff --git a/src/cmds/search.rs b/src/cmds/search.rs index 1f334ce1..51379421 100644 --- a/src/cmds/search.rs +++ b/src/cmds/search.rs @@ -1,5 +1,4 @@ use std::error::Error; - use super::aux; use crate::option::Config; diff --git a/src/display.rs b/src/display.rs index 40cb4e20..da7ddcfe 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,5 +1,4 @@ use crate::terminal; - use regex::Regex; use std::cmp::max; use termion::color; diff --git a/src/fzf.rs b/src/fzf.rs index 0e27d12c..0f679a87 100644 --- a/src/fzf.rs +++ b/src/fzf.rs @@ -1,7 +1,6 @@ use crate::cheat; use crate::display; use crate::filesystem; - use crate::cheat::SuggestionType; use crate::cheat::SuggestionType::SingleSelection; use std::collections::HashMap; diff --git a/src/option.rs b/src/option.rs index 59de7d41..f6e35cc1 100644 --- a/src/option.rs +++ b/src/option.rs @@ -18,7 +18,7 @@ pub struct Config { #[structopt(short, long, env = "NAVI_PATH")] pub path: Option, - /// [alpha] Instead of executing a snippet, saves it to a file + /// [Experimental] Instead of executing a snippet, saves it to a file #[structopt(short, long)] pub save: Option, @@ -34,11 +34,11 @@ pub struct Config { #[structopt(long)] pub no_preview: bool, - /// FZF overrides for cheat selection (must start with an empty space) + /// FZF overrides for cheat selection (must start with an empty space) #[structopt(long, env = "NAVI_FZF_OVERRIDES")] pub fzf_overrides: Option, - /// FZF overrides for variable selection (must start with an empty space) + /// FZF overrides for variable selection (must start with an empty space) #[structopt(long, env = "NAVI_FZF_OVERRIDES_VAR")] pub fzf_overrides_var: Option, @@ -49,26 +49,49 @@ pub struct Config { #[derive(Debug, StructOpt)] pub enum Command { /// Filters results - Query { query: String }, + Query { + /// String used as filter (example: "git") + query: String + }, /// Uses online repositories for cheatsheets - Search { query: String }, + Search { + /// String used as filter (example: "git") + query: String + }, /// Autoselects the snippet that best matches the query - Best { query: String, args: Vec }, + Best { + /// String used as filter (example: "git remove branch") + query: String, + /// List of arguments (example: "mybranch" "remote") + args: Vec + }, /// Performs ad-hoc functions provided by navi - Fn { func: String, args: Vec }, + Fn { + /// Function name (example: "url::open") + func: String, + /// List of arguments (example: "https://google.com") + args: Vec + }, /// Manages cheatsheet repositories Repo { #[structopt(subcommand)] cmd: RepoCommand, }, /// Shows the path for shell widget files - Widget { shell: String }, + Widget { + /// bash, zsh or fish + shell: String + }, } #[derive(Debug, StructOpt)] pub enum RepoCommand { - /// Adds a repo (user/repo will download cheats from github.com/user/repo) - Add { uri: String }, + /// Imports cheatsheets from a repo + Add { + /// A URI to a .tar.gz containing .cheat files + /// ("user/repo" will download cheats from github.com/user/repo) + uri: String + }, } pub enum InternalCommand { From 7face444ca3aa87b06226090d185746d64e94558 Mon Sep 17 00:00:00 2001 From: asd Date: Sun, 15 Mar 2020 09:50:26 -0300 Subject: [PATCH 15/27] linting --- src/cmds/best.rs | 2 +- src/cmds/preview.rs | 2 +- src/cmds/query.rs | 2 +- src/cmds/repo.rs | 6 +++--- src/cmds/search.rs | 2 +- src/fzf.rs | 4 ++-- src/option.rs | 26 +++++++++++++------------- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/cmds/best.rs b/src/cmds/best.rs index 50fd738c..aa8bf58e 100644 --- a/src/cmds/best.rs +++ b/src/cmds/best.rs @@ -1,7 +1,7 @@ -use std::error::Error; use crate::cmds; use crate::cmds::core::Variant; use crate::option::Config; +use std::error::Error; pub fn main(query: String, args: Vec, config: Config) -> Result<(), Box> { if !args.is_empty() { diff --git a/src/cmds/preview.rs b/src/cmds/preview.rs index 9607a2f8..0923f763 100644 --- a/src/cmds/preview.rs +++ b/src/cmds/preview.rs @@ -1,6 +1,6 @@ +use crate::display; use std::error::Error; use std::process; -use crate::display; fn extract_elements(argstr: &str) -> (&str, &str, &str) { let mut parts = argstr.split(display::DELIMITER).skip(3); diff --git a/src/cmds/query.rs b/src/cmds/query.rs index 7f7fa2d0..92a4d937 100644 --- a/src/cmds/query.rs +++ b/src/cmds/query.rs @@ -1,7 +1,7 @@ -use std::error::Error; use crate::cmds; use crate::cmds::core::Variant; use crate::option::Config; +use std::error::Error; pub fn main(query: String, config: Config) -> Result<(), Box> { cmds::core::main(Variant::Query(query), config, true) diff --git a/src/cmds/repo.rs b/src/cmds/repo.rs index 04f7a2bb..2c39c7a8 100644 --- a/src/cmds/repo.rs +++ b/src/cmds/repo.rs @@ -1,10 +1,10 @@ +use crate::cheat::SuggestionType; +use crate::filesystem; +use crate::fzf; use std::error::Error; use std::fs; use std::io::Write; use std::process::{Command, Stdio}; -use crate::cheat::SuggestionType; -use crate::filesystem; -use crate::fzf; pub fn add(uri: String) -> Result<(), Box> { let mut parts = uri.split('/'); diff --git a/src/cmds/search.rs b/src/cmds/search.rs index 51379421..685fae8c 100644 --- a/src/cmds/search.rs +++ b/src/cmds/search.rs @@ -1,6 +1,6 @@ -use std::error::Error; use super::aux; use crate::option::Config; +use std::error::Error; pub fn main(_query: String, _config: Config) -> Result<(), Box> { aux::abort("searching for cheats online", 201) diff --git a/src/fzf.rs b/src/fzf.rs index 0f679a87..1e5909a8 100644 --- a/src/fzf.rs +++ b/src/fzf.rs @@ -1,8 +1,8 @@ use crate::cheat; -use crate::display; -use crate::filesystem; use crate::cheat::SuggestionType; use crate::cheat::SuggestionType::SingleSelection; +use crate::display; +use crate::filesystem; use std::collections::HashMap; use std::process; use std::process::{Command, Stdio}; diff --git a/src/option.rs b/src/option.rs index f6e35cc1..1950c4cc 100644 --- a/src/option.rs +++ b/src/option.rs @@ -51,26 +51,26 @@ pub enum Command { /// Filters results Query { /// String used as filter (example: "git") - query: String + query: String, }, /// Uses online repositories for cheatsheets - Search { + Search { /// String used as filter (example: "git") - query: String + query: String, }, /// Autoselects the snippet that best matches the query - Best { + Best { /// String used as filter (example: "git remove branch") query: String, /// List of arguments (example: "mybranch" "remote") - args: Vec + args: Vec, }, /// Performs ad-hoc functions provided by navi - Fn { + Fn { /// Function name (example: "url::open") - func: String, + func: String, /// List of arguments (example: "https://google.com") - args: Vec + args: Vec, }, /// Manages cheatsheet repositories Repo { @@ -79,18 +79,18 @@ pub enum Command { }, /// Shows the path for shell widget files Widget { - /// bash, zsh or fish - shell: String + /// bash, zsh or fish + shell: String, }, } #[derive(Debug, StructOpt)] pub enum RepoCommand { - /// Imports cheatsheets from a repo - Add { + /// Imports cheatsheets from a repo + Add { /// A URI to a .tar.gz containing .cheat files /// ("user/repo" will download cheats from github.com/user/repo) - uri: String + uri: String, }, } From cb51c375d57ab498fc153fd592cd22208aa0971f Mon Sep 17 00:00:00 2001 From: asd Date: Sun, 15 Mar 2020 09:51:04 -0300 Subject: [PATCH 16/27] wip --- src/option.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/option.rs b/src/option.rs index 1950c4cc..4723bf23 100644 --- a/src/option.rs +++ b/src/option.rs @@ -2,17 +2,17 @@ use std::env; use structopt::StructOpt; #[derive(Debug, StructOpt)] -#[structopt(after_help = "EXAMPLES: +#[structopt(after_help = r#"EXAMPLES: navi # default behavior navi --print # doesn't execute the snippet navi --path '/some/dir:/other/dir' # uses custom cheats navi search docker # uses online data - navi query git # filters results by \"git\" + navi query git # filters results by "git" navi best 'sql create db' root mydb # uses a snippet as a CLI - source \"$(navi widget zsh)\" # loads the zsh widget + source "$(navi widget zsh)" # loads the zsh widget navi --fzf-overrides ' --with-nth 1,2' # shows only the comment and tag columns navi --fzf-overrides ' --nth 1,2' # search will consider only the first two columns - navi --fzf-overrides ' --no-exact' # looser search algorithm")] + navi --fzf-overrides ' --no-exact' # looser search algorithm"#)] pub struct Config { /// List of :-separated paths containing .cheat files #[structopt(short, long, env = "NAVI_PATH")] From 2c967e73ba6a0639234899cccd9846a692dc43ef Mon Sep 17 00:00:00 2001 From: asd Date: Sun, 15 Mar 2020 09:55:15 -0300 Subject: [PATCH 17/27] wip --- src/option.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/option.rs b/src/option.rs index 4723bf23..d46ed1d9 100644 --- a/src/option.rs +++ b/src/option.rs @@ -9,7 +9,8 @@ use structopt::StructOpt; navi search docker # uses online data navi query git # filters results by "git" navi best 'sql create db' root mydb # uses a snippet as a CLI - source "$(navi widget zsh)" # loads the zsh widget + navi repo add denisidoro/cheats # imports cheats from github.com/denisidoro/cheats + source <(navi widget zsh) # loads the zsh widget navi --fzf-overrides ' --with-nth 1,2' # shows only the comment and tag columns navi --fzf-overrides ' --nth 1,2' # search will consider only the first two columns navi --fzf-overrides ' --no-exact' # looser search algorithm"#)] From 062bc6d7c1d264ebcb16349987606920b7c85082 Mon Sep 17 00:00:00 2001 From: asd Date: Sun, 15 Mar 2020 10:14:42 -0300 Subject: [PATCH 18/27] wip --- src/welcome.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/welcome.rs b/src/welcome.rs index 69e77771..4019b923 100644 --- a/src/welcome.rs +++ b/src/welcome.rs @@ -11,7 +11,7 @@ pub fn cheatsheet(stdin: &mut std::process::ChildStdin) { add_msg( "cheatsheets", "Download default cheatsheets", - "navi repo add denisidoro/navi", + "navi repo add denisidoro/cheats", stdin, ); add_msg("more info", "Read --help message", "navi --help", stdin); From fffcce01ffb259cdb5f45682a21a55c18f13c52f Mon Sep 17 00:00:00 2001 From: asd Date: Sun, 15 Mar 2020 10:17:48 -0300 Subject: [PATCH 19/27] update scripts --- cheats/android.cheat | 27 ----- cheats/apt.cheat | 55 ---------- cheats/brew.cheat | 36 ------- cheats/cf.cheat | 130 ------------------------ cheats/compression.cheat | 24 ----- cheats/crontab.cheat | 7 -- cheats/docker.cheat | 71 ------------- cheats/firebase.cheat | 47 --------- cheats/fly.cheat | 154 ---------------------------- cheats/git.cheat | 108 -------------------- cheats/gpg.cheat | 37 ------- cheats/httpie.cheat | 28 ----- cheats/javascript.cheat | 70 ------------- cheats/k3d.cheat | 36 ------- cheats/keytool.cheat | 58 ----------- cheats/kubernetes.cheat | 52 ---------- cheats/misc.cheat | 27 ----- cheats/mysql.cheat | 10 -- cheats/network.cheat | 27 ----- cheats/openssl.cheat | 81 --------------- cheats/osx.cheat | 25 ----- cheats/rsfetch.cheat | 79 --------------- cheats/shell.cheat | 214 --------------------------------------- cheats/ssh.cheat | 4 - cheats/systemctl.cheat | 37 ------- cheats/yum.cheat | 52 ---------- scripts/action | 2 - 27 files changed, 1498 deletions(-) delete mode 100644 cheats/android.cheat delete mode 100644 cheats/apt.cheat delete mode 100644 cheats/brew.cheat delete mode 100644 cheats/cf.cheat delete mode 100644 cheats/compression.cheat delete mode 100644 cheats/crontab.cheat delete mode 100644 cheats/docker.cheat delete mode 100644 cheats/firebase.cheat delete mode 100644 cheats/fly.cheat delete mode 100644 cheats/git.cheat delete mode 100644 cheats/gpg.cheat delete mode 100644 cheats/httpie.cheat delete mode 100644 cheats/javascript.cheat delete mode 100644 cheats/k3d.cheat delete mode 100644 cheats/keytool.cheat delete mode 100644 cheats/kubernetes.cheat delete mode 100644 cheats/misc.cheat delete mode 100644 cheats/mysql.cheat delete mode 100644 cheats/network.cheat delete mode 100644 cheats/openssl.cheat delete mode 100644 cheats/osx.cheat delete mode 100644 cheats/rsfetch.cheat delete mode 100644 cheats/shell.cheat delete mode 100644 cheats/ssh.cheat delete mode 100644 cheats/systemctl.cheat delete mode 100644 cheats/yum.cheat diff --git a/cheats/android.cheat b/cheats/android.cheat deleted file mode 100644 index fbc02f12..00000000 --- a/cheats/android.cheat +++ /dev/null @@ -1,27 +0,0 @@ -% android, device - -# Get property -adb -s shell getprop - -# Install APK -adb -s install -r - -# Uninstall package -adb -s uninstall -r - -# Clear user data for package -adb -s shell pm clear - -# Dispatch a deep-link / open URI -adb -s shell am start - -$ device: adb devices --- --headers 1 --column 1 - - - -% android, emulator - -# Start emulator -"$ANDROID_HOME/tools/emulator" -avd -netdelay none -netspeed full - -$ emulator: "$ANDROID_HOME/tools/emulator" -list-avds diff --git a/cheats/apt.cheat b/cheats/apt.cheat deleted file mode 100644 index 13fa9663..00000000 --- a/cheats/apt.cheat +++ /dev/null @@ -1,55 +0,0 @@ -% apt - -# Update content listings from package repositories -apt update - -# List all available packages -apt list - -# List all installed packages -apt list --installed - -# Info about package (including description) -apt show -a - -# Show versions and archive areas of available package -apt list -a - -# Search in repository (packages and description) -apt search - -# Check updates for installed packages -apt list --upgradeable - -# Update all installed packages -apt upgrade - -# Upgrade all installed packages (add/remove dependencies) -apt full-upgrade - -# Update specific/individual package -apt install --only-upgrade - -# Downgrade package to a specific version -apt install = - -# Install a package from repository -apt install - -# Remove/delete package -apt remove - -# Remove/delete package (with config files) -apt purge - -# Install local dpkg package -apt install - -# List dependencies of package -apt depends - -# List reverse dependencies of package -apt rdepends - -# Remove un-needed packages and dependencies -apt autoremove diff --git a/cheats/brew.cheat b/cheats/brew.cheat deleted file mode 100644 index 610ce38d..00000000 --- a/cheats/brew.cheat +++ /dev/null @@ -1,36 +0,0 @@ -% brew, cask - -# update brew -brew update - -# upgrade brew -brew upgrade - -# get info for a package -brew info - -# get info for a cask -brew cask info - -# install a package -brew install - -# install a cask -brew cask install - -# uninstall a package -brew uninstall - -# uninstall a cask -brew cask uninstall - -# edit package -brew edit - -# edit cask -brew cask edit - -$ package: brew search -$ casks: brew search --casks -$ installed: brew list -$ caskinstalled: brew cask list diff --git a/cheats/cf.cheat b/cheats/cf.cheat deleted file mode 100644 index 9fcf9688..00000000 --- a/cheats/cf.cheat +++ /dev/null @@ -1,130 +0,0 @@ -% cf, pcf, pivotal cloud foundry, paas - - -### Information -# Get the extended list of help -cf help -a - -# Get current version of cf -cf version - -# Get information about current org -cf org - -# Get information about current space -cf space - -# Get information about current target -cf target - -# Get list of all apps -cf apps - -# Get list of all services -cf services - -# Get list of all routes -cf routes - -# Get list of all network policies -cf network-policies - - - -### Login -# Login to your CF/PCF instance -cf login -a - -# Login to your CF/PCF instance with username and password -cf login -a -u -p - -# Login and specify target directly -cf login -a -u -p -o -s - - - -### Target -# Set target org -cf target -o - -# Set target space -cf target -o -s - - -### Application manipulation -## Information -# Get the guid of an app -cf app --guid - -# Get the status of an app -cf app - -## Status -# Start an app -cf start - -# Stop an app -cf stop - -# Restart an app -cf restart - -# Rebuild the application package and restart -cf restage - -## Deletion -# Delete an app -cf delete - -# Delete an app no prompt -cf delete -f - -# Delete an app and routes -cf delete -r - - - -### Networking - A bit slow due to filtering -# Add network policy -cf add-network-policy \ ---destination-app \ ---protocol \ ---port - -# Remove network-policy -cf remove-network-policy \ ---destination-app \ ---protocol \ ---port - - -### Services -# Bind a service to an application -cf bind-service - -# Unbind a service from an application -cf unbind-service - -# Share a service between spaces -cf share-service -o -s - -# Unshare a service from a spaces -cf unshare-service -o -s - - - -# Autocomplete variables -$ org: cf orgs | awk 'NR>3 {print}' -$ space: cf target -o "$org" > /dev/null && cf spaces | awk 'NR>3 {print $1}' -$ service: cf services | awk 'NR>3 {print $1}' | sed '/TIP:/d' -$ route: cf routes | awk 'NR>3 {if ($4 ~ /^\//){ print $2 "." $3 $4} else {print $2 "." $3}}' -$ app: cf apps | awk 'NR>4 {print $1}' - -$ add_network_source: cf apps | awk 'NR>4 {print $1}' -$ add_network_destination: cf apps | awk 'NR>4 {print $1}' | sed "/$add_network_source/d" -$ add_network_protocol: printf "tcp \nudp" - -$ remove_network_source: cf network-policies | awk 'NR>3 {print $1}' | uniq -$ remove_network_destination: cf network-policies | grep "^$remove_network_source" | awk '{print $2}' | uniq -$ remove_network_protocol: cf network-policies | grep "^$remove_network_source" | grep "$remove_network_destination" | awk '{print $3}' | uniq -$ remove_network_port: cf network-policies | grep "^$remove_network_source" | grep "$remove_network_destination" | awk '{print $4}' | uniq diff --git a/cheats/compression.cheat b/cheats/compression.cheat deleted file mode 100644 index f71c750b..00000000 --- a/cheats/compression.cheat +++ /dev/null @@ -1,24 +0,0 @@ -% compression - -# Create a tar containing files -tar cf .tar - -# Extract the files from a tar -tar xf - -# Create a tar with Gzip compression -tar czf .tar.gz - -# Extract a tar using Gzip -tar xzf - -# Compress file and appends .gz to its name -gzip - -# Decompress compressed file -gzip -d - -$ path: ls -$ tar_file: ls *.tar -$ targz_file: ls *.tar.gz -$ gz_file: ls *.gz diff --git a/cheats/crontab.cheat b/cheats/crontab.cheat deleted file mode 100644 index 8f8fd0e9..00000000 --- a/cheats/crontab.cheat +++ /dev/null @@ -1,7 +0,0 @@ -% crontab, schedule - -# List cron jobs -crontab -l - -# Edit cron job -crontab -e diff --git a/cheats/docker.cheat b/cheats/docker.cheat deleted file mode 100644 index ff8b7a8e..00000000 --- a/cheats/docker.cheat +++ /dev/null @@ -1,71 +0,0 @@ -% docker - -# Remove an image -docker image rm - -# Delete an image from the local image store -docker rmi - -# List all images that are locally stored with the Docker engine -docker images - -# Build an image from the Dockerfile in the current directory and tag the image -docker build -t : . - -# Pull an image from a registry -docker pull : - -# Stop a running container through SIGTERM -docker stop - -# Stop a running container through SIGKILL -docker kill - -# List the networks -docker network ls - -# List the running containers -docker ps - -# Delete all running and stopped containers -docker rm -f $(docker ps -aq) - -# Create a new bash process inside the container and connect it to the terminal -docker exec -it bash - -# Print the last lines of a container’s logs -docker logs --tail 100 | less - -# Print the last lines of a container's logs and following its logs -docker logs --tail 100 -f - -# Create new network -docker network create - -$ image_id: docker images --- --headers 1 --column 3 -$ container_id: docker ps --- --headers 1 --column 1 - - - -% docker-compose - -# Builds, (re)creates, starts, and attaches to containers for all services -docker-compose up - -# Builds, (re)creates, starts, and dettaches to containers for all services -docker-compose up -d - -# Builds, (re)creates, starts, and attaches to containers for a service -docker-compose up -d - -# Builds, (re)creates, starts, and dettaches to containers for a service -docker-compose up -d - -# Print the last lines of a service’s logs -docker-compose logs --tail 100 | less - -# Print the last lines of a service's logs and following its logs -docker-compose logs -f --tail 100 - -# Stops containers and removes containers, networks created by up -docker-compose down diff --git a/cheats/firebase.cheat b/cheats/firebase.cheat deleted file mode 100644 index c3a98f26..00000000 --- a/cheats/firebase.cheat +++ /dev/null @@ -1,47 +0,0 @@ -% firebase, account - -# Login -firebase login - -# Logout -firebase logout - -% firebase, local - -# Init a new project -firebase init [feature] - -# List of projects you have access to -firebase projects:list - -# Set current project -firebase use [options] [alias_or_project_id] - -# Serve all allowed content -firebase serve - -# Serve specific feature -firebase serve --only - -# Serve specific content for feature -firebase serve --only : - -% firebase, remote - -# Deploy projects -firebase deploy - -# Deploy specific feature -firebase deploy --only - -# Deploy specific content for feature -firebase deploy --only : - -% firebase, ci - -# Generate a token for CI -firebase login:ci - -# Deploy from CI -firebase deploy --token - diff --git a/cheats/fly.cheat b/cheats/fly.cheat deleted file mode 100644 index ea97dcbd..00000000 --- a/cheats/fly.cheat +++ /dev/null @@ -1,154 +0,0 @@ -% fly, concourse, pipeline, ci-cd - -# Show Concourse help -fly --help - - - -# List all Concourse target aliases -fly targets - -# Delete saved configuration for a target -fly --target delete-target - -# Sync concourse version with target -fly --target sync - -# Login to a selected target -fly --target login - - - -# List all teams within a Concourse target -fly --target teams - -# Show the configuration for a given team -fly --target get-team --team-name - -# Delete a team from Concourse installation -fly --target destroy-team -n - - - -# list all pipelines -fly --target pipelines - -# Make pipeline public -fly --target expose-pipeline --pipeline - -# Make pipeline private -fly --target hide-pipeline --pipeline - -# Get pipeline / show pipeline -fly --target get-pipeline --pipeline - -# Pause a pipeline -fly --target pause-pipeline --pipeline - -# Unpause a pipeline -fly --target unpause-pipeline --pipeline - -# Rename a pipeline -fly --target rename-pipeline --old-name \ ---new-name - -# Create pipeline without variables -fly --target set-pipeline --pipeline \ ---config - -# Create pipeline with variables -fly --target set-pipeline --pipeline \ ---config --load-vars-from - -# Update pipeline without variables -fly --target set-pipeline --pipeline \ ---config - -# Update pipeline with variables -fly --target set-pipeline --pipeline \ ---config --load-vars-from - -# Validate pipeline without variables -fly validate-pipeline --config - -# Validate pipeline with variables -fly validate-pipeline --config \ ---load-vars-from - -# Delete a pipeline -fly --target destroy-pipeline --pipeline - - - -# List the jobs of a pipeline -fly --target jobs --pipeline - -# Pause a job on a pipeline -fly --target pause-job --job=/ - -# Unpause a job on a pipeline -fly --target unpause-job --job=/ - -# Trigger a job on a pipeline -fly --target trigger-job --job=/ - - - -# List the latest builds for a job -fly --target builds --job=/ \ ---count= - -# Hijack a pipeline job for debugging -fly --target hijack --job=/ \ ---build - -# Watch the log output from a running job -fly --target watch --job=/ \ ---build - -# Abort a running build -fly --target abort-build --job=/ \ ---build - - - -# List the users who have been active for the past 2 months -fly --target active-users - -# List the access of the current user -fly --target userinfo - - - -# List the resources for a pipeline -fly --target resources --pipeline - -# Check a resource -fly --target check-resource --resource=/ - -# List the versions of a resource -fly --target resource-versions --resource=/ - -# Pin a resource version -fly --target pin-resource --resource=/ \ ---version - -# Unpin a resource version -fly --target unpin-resource --resource=/ - - - - - -$ target: fly targets --- --column 1 -$ team: fly -t "$target" teams -$ job: fly -t "$target" jobs --pipeline "$pipeline" --- --column 1 -$ build: fly -t "$target" builds --job="$pipeline"/"$job" --- --column 3 -$ resource: fly -t "$target" resources --pipeline "$pipeline" --- --column 1 -$ version: fly -t "$target" resource-versions --resource="$pipeline"/"$resource" --- --column 2 -$ pipeline: fly -t "$target" pipelines --- --column 1 -$ pipeline_yaml: ls *.yml || ls -$ pipeline_vars: ls *.yml || ls - - - diff --git a/cheats/git.cheat b/cheats/git.cheat deleted file mode 100644 index 9b5a1b59..00000000 --- a/cheats/git.cheat +++ /dev/null @@ -1,108 +0,0 @@ -% git - -# Set global git user name -git config --global user.name - -# Set global git user email -git config --global user.email - -# Initializes a git repository -git init - -# Clone a git repository -git clone -b - -# View all available remote for a git repository -git remote --verbose - -# Adds a remote for a git repository -git remote add - -# Renames a remote for a git repository -git remote rename - -# Remove a remote for a git repository -git remote remove - -# Checkout to branch -git checkout - -# Displays the current status of a git repository -git status - -# Displays unstaged changes for file -cd ; \ - git diff - -# Stage single or multiple files -cd ; \ - git add ; - -# Stage all files in project -git add -A - -# Saves the changes to a file in a commit -git commit -m - -# Pushes committed changes to remote repository -git push -u - -# Pushes changes to a remote repository overwriting another branch -git push : - -# Overwrites remote branch with local branch changes -git push -f - -# Pulls changes to a remote repo to the local repo -git pull --ff-only - -# Merges changes on one branch into current branch -git merge - -# Abort the current conflict resolution process, and try to reconstruct the pre-merge state. -git merge --abort - -# Displays log of commits for a repo -git log - -# Displays formatted log of commits for a repo -git log --all --decorate --oneline --graph - -# Clear everything -git clean -dxf - -# Sign all commits in a branch based on master -git rebase master -S -f - -# See all open pull requests of a user on Github -navi fn url::open 'https://github.com/pulls?&q=author:+is:open+is:pr' - -# Checkout a branch from a fork -git fetch origin pull//head:pr/ \ - && git checkout pr/ - -# Add a new module -git submodule add - -# Update module -git submodule update --init - -# Update module without init -git submodule update - -# Pull all submodules -git submodule foreach git pull origin master - -# Update all submodules -git submodule update --init --recursive - -# Skip git hooks -git commit --no-verify - -# Create new branch from current HEAD -git checkout -b - -$ branch: git branch | awk '{print $NF}' -$ toplevel_directory: git rev-parse --show-toplevel -$ unstaged_files: git status --untracked-files=no -s --porcelain | awk '{print $NF}' --- --multi true -$ changed_files: git status --untracked-files=all -s --porcelain | awk '{print $NF}' --- --multi true diff --git a/cheats/gpg.cheat b/cheats/gpg.cheat deleted file mode 100644 index fb88333d..00000000 --- a/cheats/gpg.cheat +++ /dev/null @@ -1,37 +0,0 @@ -% gpg - -# gpg version -gpg --version - -# gpg generate key -gpg --gen-key - -# list keys -gpg --list-keys - -# distribute public key to key server -gpg --keyserver --send-keys - -# export public key -gpg --output --export - -# import public key -gpg --import - -# encrypt document -gpg --output --encrypt --recipient - -# decrypt document -gpg --output --decrypt - -# make a signature -gpg --output --sign - -# verify signature -gpg --output --decrypt - -# clearsign documents -gpg --clearsign - -# detach signature -gpg --output --detach-sig diff --git a/cheats/httpie.cheat b/cheats/httpie.cheat deleted file mode 100644 index cfa5e8f6..00000000 --- a/cheats/httpie.cheat +++ /dev/null @@ -1,28 +0,0 @@ -% httpie, http - -# send a get http request -http - -# send a http request -http - -# send an authenticated http request -http -a : - -# send a http request with a json body -http = - -# send a http request with a form body -http -f POST = - -# send a http request and see the request as well as the response -http -v - -# send a post http request wih a body from a file -http < - -# send a http request wih a custom header -http : - -$ file: ls -$ method: echo -e 'GET\nPOST\nPUT\nDELETE\nPATCH' diff --git a/cheats/javascript.cheat b/cheats/javascript.cheat deleted file mode 100644 index 9ae5929a..00000000 --- a/cheats/javascript.cheat +++ /dev/null @@ -1,70 +0,0 @@ -% npm, node, js - -# initial new package -npm init - -# initial immediately a new package -npm init -y - -# install all dependencies packages -npm install - -# install all dev dependencies packages -npm install --save-dev - -# install a specified package -npm install - -# install a specified dev package -npm install --save-dev - -# install globally a specified package -npm install -g - -# run a script -npm run