summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Isidoro <denisidoro@users.noreply.github.com>2020-10-08 17:45:01 -0300
committerGitHub <noreply@github.com>2020-10-08 17:45:01 -0300
commitde06161baf599f53171e119ba4c582285b08f93b (patch)
treefa391db8fe146424bb69164e7c69552693131797
parentba2efec723d455673d493c7299aceb308eac6af3 (diff)
Fix support for fish shell (#421)v2.12.1
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/cmds/core.rs18
-rw-r--r--src/common/shell.rs5
-rw-r--r--src/fetcher/mod.rs2
-rw-r--r--src/parser.rs14
-rw-r--r--src/structures/cheat.rs19
-rw-r--r--src/structures/config.rs6
-rw-r--r--src/tldr.rs22
-rwxr-xr-xtests/run2
10 files changed, 61 insertions, 31 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 48d1092..e64897a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -196,7 +196,7 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
[[package]]
name = "navi"
-version = "2.12.0"
+version = "2.12.1"
dependencies = [
"anyhow",
"directories-next",
diff --git a/Cargo.toml b/Cargo.toml
index 7ccc7c7..c55b010 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "navi"
-version = "2.12.0"
+version = "2.12.1"
authors = ["Denis Isidoro <denis_isidoro@live.com>"]
edition = "2018"
description = "An interactive cheatsheet tool for the command-line"
diff --git a/src/cmds/core.rs b/src/cmds/core.rs
index d846ee8..4c6ffee 100644
--- a/src/cmds/core.rs
+++ b/src/cmds/core.rs
@@ -1,6 +1,6 @@
use crate::cheatsh;
use crate::common::clipboard;
-use crate::common::shell::BashSpawnError;
+use crate::common::shell::{BashSpawnError, IS_FISH};
use crate::display;
use crate::env_vars;
use crate::fetcher::Fetcher;
@@ -27,7 +27,7 @@ fn gen_core_finder_opts(config: &Config) -> Result<FinderOpts, Error> {
} else {
Some(format!("{} preview {{}}", filesystem::exe_string()?))
},
- autoselect: !config.get_no_autoselect(),
+ autoselect: config.autoselect(),
overrides: config.fzf_overrides.clone(),
suggestion_type: SuggestionType::SnippetSelection,
query: if config.get_best_match() { None } else { config.get_query() },
@@ -95,18 +95,20 @@ fn prompt_finder(variable_name: &str, config: &Config, suggestion: Option<&Sugge
};
let mut opts = FinderOpts {
- autoselect: !config.get_no_autoselect(),
+ autoselect: config.autoselect(),
overrides: config.fzf_overrides_var.clone(),
preview: Some(format!(
- r#"navi preview-var "$(cat <<NAVIEOF
+ r#"{prefix}navi preview-var "$(cat <<NAVIEOF
{{}}
NAVIEOF
)" "$(cat <<NAVIEOF
{{q}}
NAVIEOF
-)" "{}"{}"#,
- variable_name,
- extra_preview.clone().unwrap_or_default()
+)" "{name}"; {extra}{suffix}"#,
+ prefix = if *IS_FISH { "bash -c '" } else { "" },
+ suffix = if *IS_FISH { "'" } else { "" },
+ name = variable_name,
+ extra = extra_preview.clone().unwrap_or_default()
)),
..opts.clone().unwrap_or_default()
};
@@ -136,7 +138,7 @@ NAVIEOF
fn unique_result_count(results: &[&str]) -> usize {
let mut vars = results.to_owned();
- vars.sort();
+ vars.sort_unstable();
vars.dedup();
vars.len()
}
diff --git a/src/common/shell.rs b/src/common/shell.rs
index 6071ae4..84d34f1 100644
--- a/src/common/shell.rs
+++ b/src/common/shell.rs
@@ -1,6 +1,11 @@
+use std::env;
use std::fmt::Debug;
use thiserror::Error;
+lazy_static! {
+ pub static ref IS_FISH: bool = env::var("SHELL").unwrap_or_else(|_| "".to_string()).contains(&"fish");
+}
+
#[derive(Debug)]
pub enum Shell {
Bash,
diff --git a/src/fetcher/mod.rs b/src/fetcher/mod.rs
index b07b26e..36b77f2 100644
--- a/src/fetcher/mod.rs
+++ b/src/fetcher/mod.rs
@@ -5,5 +5,5 @@ use crate::structures::cheat::VariableMap;
use anyhow::Error;
pub trait Fetcher {
- fn fetch(self: &Self, stdin: &mut std::process::ChildStdin, writer: &mut dyn Writer) -> Result<Option<VariableMap>, Error>;
+ fn fetch(&self, stdin: &mut std::process::ChildStdin, writer: &mut dyn Writer) -> Result<Option<VariableMap>, Error>;
}
diff --git a/src/parser.rs b/src/parser.rs
index bb4e6e1..c0be31f 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -114,6 +114,14 @@ fn write_cmd(tags: &str, comment: &str, snippet: &str, writer: &mut dyn Writer,
}
}
+fn without_prefix(line: &str) -> String {
+ if line.len() > 2 {
+ String::from(line[2..].trim())
+ } else {
+ String::from("")
+ }
+}
+
pub fn read_lines(
lines: impl Iterator<Item = Result<String, Error>>,
id: &str,
@@ -145,11 +153,11 @@ pub fn read_lines(
should_break = true
}
snippet = String::from("");
- tags = if line.len() > 2 { String::from(&line[2..]) } else { String::from("") };
+ tags = without_prefix(&line);
}
// dependency
else if line.starts_with('@') {
- let tags_dependency = if line.len() > 2 { String::from(&line[2..]) } else { String::from("") };
+ let tags_dependency = without_prefix(&line);
variables.insert_dependency(&tags, &tags_dependency);
}
// metacomment
@@ -161,7 +169,7 @@ pub fn read_lines(
should_break = true
}
snippet = String::from("");
- comment = if line.len() > 2 { String::from(&line[2..]) } else { String::from("") };
+ comment = without_prefix(&line);
}
// variable
else if line.starts_with('$') {
diff --git a/src/structures/cheat.rs b/src/structures/cheat.rs
index bbddd01..0d4885b 100644
--- a/src/structures/cheat.rs
+++ b/src/structures/cheat.rs
@@ -43,18 +43,25 @@ impl VariableMap {
pub fn get_suggestion(&self, tags: &str, variable: &str) -> Option<&Suggestion> {
let k = fnv(&tags);
- let res = self.variables.get(&k)?.get(variable);
- if res.is_some() {
- return res;
+
+ if let Some(vm) = self.variables.get(&k) {
+ let res = vm.get(variable);
+ if res.is_some() {
+ return res;
+ }
}
+
if let Some(dependency_keys) = self.dependencies.get(&k) {
for dependency_key in dependency_keys {
- let res = self.variables.get(&dependency_key)?.get(variable);
- if res.is_some() {
- return res;
+ if let Some(vm) = self.variables.get(&dependency_key) {
+ let res = vm.get(variable);
+ if res.is_some() {
+ return res;
+ }
}
}
}
+
None
}
}
diff --git a/src/structures/config.rs b/src/structures/config.rs
index a332152..a6a1ece 100644
--- a/src/structures/config.rs
+++ b/src/structures/config.rs
@@ -290,12 +290,12 @@ impl Config {
}
}
- pub fn get_no_autoselect(&self) -> bool {
+ pub fn autoselect(&self) -> bool {
if self.no_autoselect {
deprecated("--no-autoselect");
- true
- } else {
false
+ } else {
+ true
}
}
}
diff --git a/src/tldr.rs b/src/tldr.rs
index 3cd191f..f5801b5 100644
--- a/src/tldr.rs
+++ b/src/tldr.rs
@@ -13,6 +13,9 @@ lazy_static! {
pub static ref NON_VAR_CHARS_REGEX: Regex = Regex::new(r"[^\da-zA-Z_]").expect("Invalid regex");
}
+static VERSION_DISCLAIMER: &str = "The tldr client written in C (the default one in Homebrew) doesn't support markdown files, so navi can't use it.
+The client written in Rust is recommended. The one available in npm works, too.";
+
fn convert_tldr_vars(line: &str) -> String {
let caps = VAR_TLDR_REGEX.find_iter(&line);
let mut new_line: String = line.to_string();
@@ -87,7 +90,12 @@ pub fn fetch(query: &str) -> Result<String, Error> {
eprintln!(
"navi was unable to call tldr.
Make sure tldr is correctly installed.
-Refer to https://github.com/tldr-pages/tldr for more info."
+Refer to https://github.com/tldr-pages/tldr for more info.
+
+Note:
+{}
+",
+ VERSION_DISCLAIMER
);
process::exit(34)
}
@@ -107,15 +115,15 @@ Output:
Error:
{}
-Note:
-The tldr client written in C (the default one in Homebrew) doesn't support markdown files, so navi can't use it.
-Please make sure you're using a version that supports the --markdown flag.
-The client written in Rust is recommended. The one available in npm works, too.
-If you are already using a supported version you can ignore this message.
+Note:
+Please make sure you're using a version that supports the --markdown flag.
+If you are already using a supported version you can ignore this message.
+{}
",
args.join(" "),
String::from_utf8(out.stdout).unwrap_or_else(|_e| "Unable to get output message".to_string()),
- String::from_utf8(out.stderr).unwrap_or_else(|_e| "Unable to get error message".to_string())
+ String::from_utf8(out.stderr).unwrap_or_else(|_e| "Unable to get error message".to_string()),
+ VERSION_DISCLAIMER
);
process::exit(35)
}
diff --git a/tests/run b/tests/run
index 5f8a745..be29f86 100755
--- a/tests/run
+++ b/tests/run
@@ -109,7 +109,7 @@ _integration() {
echoerr "Running snippet..."
tmux send-key -t ci "pwd"
- sleep 1
+ sleep 1
tmux send-key -t ci "Enter"
sleep 2