summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenis Isidoro <denisidoro@users.noreply.github.com>2023-04-09 10:08:42 -0300
committerGitHub <noreply@github.com>2023-04-09 10:08:42 -0300
commitf8192a468eaf1c803d7a186d95df438cb47596c2 (patch)
tree5e5305c43e050259fd4d2bdfcb2527a2328f6514 /src
parente3920552ca99bd3f436f548ffdbef7621f7b079d (diff)
Fix publish script (#825)
Diffstat (limited to 'src')
-rw-r--r--src/clients/cheatsh.rs7
-rw-r--r--src/clients/tldr.rs14
-rw-r--r--src/commands/core/actor.rs10
-rw-r--r--src/commands/func/widget.rs2
-rw-r--r--src/commands/preview/mod.rs2
-rw-r--r--src/commands/preview/var.rs6
-rw-r--r--src/commands/repo/add.rs6
-rw-r--r--src/commands/repo/browse.rs2
-rw-r--r--src/commands/repo/mod.rs4
-rw-r--r--src/commands/shell.rs2
-rw-r--r--src/common/clipboard.rs7
-rw-r--r--src/common/git.rs2
-rw-r--r--src/common/terminal.rs2
-rw-r--r--src/common/url.rs7
-rw-r--r--src/config/mod.rs2
-rw-r--r--src/config/yaml.rs4
-rw-r--r--src/env_var.rs2
-rw-r--r--src/filesystem.rs4
-rw-r--r--src/finder/mod.rs6
-rw-r--r--src/finder/post.rs11
-rw-r--r--src/parser.rs2
21 files changed, 46 insertions, 58 deletions
diff --git a/src/clients/cheatsh.rs b/src/clients/cheatsh.rs
index fb29e8d..99417a2 100644
--- a/src/clients/cheatsh.rs
+++ b/src/clients/cheatsh.rs
@@ -7,9 +7,8 @@ fn map_line(line: &str) -> String {
fn as_lines(query: &str, markdown: &str) -> Vec<String> {
format!(
- "% {}, cheat.sh
-{}",
- query, markdown
+ "% {query}, cheat.sh
+{markdown}"
)
.lines()
.map(map_line)
@@ -17,7 +16,7 @@ fn as_lines(query: &str, markdown: &str) -> Vec<String> {
}
pub fn call(query: &str) -> Result<Vec<String>> {
- let args = ["-qO-", &format!("cheat.sh/{}", query)];
+ let args = ["-qO-", &format!("cheat.sh/{query}")];
let child = Command::new("wget")
.args(args)
diff --git a/src/clients/tldr.rs b/src/clients/tldr.rs
index 16ff216..cd040e4 100644
--- a/src/clients/tldr.rs
+++ b/src/clients/tldr.rs
@@ -18,10 +18,10 @@ fn convert_tldr_vars(line: &str) -> String {
let mut new_var = NON_VAR_CHARS_REGEX.replace_all(var, "_").to_string();
if let Some(c) = new_var.chars().next() {
if c.to_string().parse::<u8>().is_ok() {
- new_var = format!("example_{}", new_var);
+ new_var = format!("example_{new_var}");
}
}
- let bracketed_var = format!("<{}>", new_var);
+ let bracketed_var = format!("<{new_var}>");
new_line = new_line.replace(braced_var, &bracketed_var);
}
new_line
@@ -42,9 +42,8 @@ fn convert_tldr(line: &str) -> String {
fn markdown_lines(query: &str, markdown: &str) -> Vec<String> {
format!(
- "% {}, tldr
- {}",
- query, markdown
+ "% {query}, tldr
+ {markdown}"
)
.lines()
.map(convert_tldr)
@@ -70,9 +69,8 @@ Make sure tldr is correctly installed.
Refer to https://github.com/tldr-pages/tldr for more info.
Note:
-{}
-",
- VERSION_DISCLAIMER
+{VERSION_DISCLAIMER}
+"
);
return Err(anyhow!(msg));
}
diff --git a/src/commands/core/actor.rs b/src/commands/core/actor.rs
index 36e2960..9d49717 100644
--- a/src/commands/core/actor.rs
+++ b/src/commands/core/actor.rs
@@ -77,7 +77,7 @@ fn prompt_finder(
name = variable_name,
extra = extra_preview
.clone()
- .map(|e| format!(" echo; {}", e))
+ .map(|e| format!(" echo; {e}"))
.unwrap_or_default(),
)
} else {
@@ -93,7 +93,7 @@ fn prompt_finder(
name = variable_name,
extra = extra_preview
.clone()
- .map(|e| format!(" echo; {}", e))
+ .map(|e| format!(" echo; {e}"))
.unwrap_or_default(),
eof = EOF,
)
@@ -105,9 +105,9 @@ fn prompt_finder(
..initial_opts.clone().unwrap_or_else(FinderOpts::var_default)
};
- opts.query = env_var::get(format!("{}__query", variable_name)).ok();
+ opts.query = env_var::get(format!("{variable_name}__query")).ok();
- if let Ok(f) = env_var::get(format!("{}__best", variable_name)) {
+ if let Ok(f) = env_var::get(format!("{variable_name}__best")) {
opts.filter = Some(f);
opts.suggestion_type = SuggestionType::SingleSelection;
}
@@ -229,7 +229,7 @@ pub fn act(
match CONFIG.action() {
Action::Print => {
- println!("{}", interpolated_snippet);
+ println!("{interpolated_snippet}");
}
Action::Execute => match key {
"ctrl-y" => {
diff --git a/src/commands/func/widget.rs b/src/commands/func/widget.rs
index fc15c80..e888518 100644
--- a/src/commands/func/widget.rs
+++ b/src/commands/func/widget.rs
@@ -11,7 +11,7 @@ pub fn last_command() -> Result<()> {
for p in parts {
for (pattern, escaped) in replacements.clone() {
- if p.contains(pattern) && p != pattern && p != format!("{}{}", pattern, pattern) {
+ if p.contains(pattern) && p != pattern && p != format!("{pattern}{pattern}") {
let replacement = p.replace(pattern, escaped);
text = text.replace(&p, &replacement);
}
diff --git a/src/commands/preview/mod.rs b/src/commands/preview/mod.rs
index dfd6d37..e571b78 100644
--- a/src/commands/preview/mod.rs
+++ b/src/commands/preview/mod.rs
@@ -30,7 +30,7 @@ impl Runnable for Input {
println!(
"{comment} {tags} \n{snippet}",
comment = style(comment).with(CONFIG.comment_color()),
- tags = style(format!("[{}]", tags)).with(CONFIG.tag_color()),
+ tags = style(format!("[{tags}]")).with(CONFIG.tag_color()),
snippet = style(deser::fix_newlines(snippet)).with(CONFIG.snippet_color()),
);
diff --git a/src/commands/preview/var.rs b/src/commands/preview/var.rs
index 4cf773e..0b76f67 100644
--- a/src/commands/preview/var.rs
+++ b/src/commands/preview/var.rs
@@ -42,10 +42,10 @@ impl Runnable for Input {
println!(
"{comment} {tags}",
comment = style(comment).with(CONFIG.comment_color()),
- tags = style(format!("[{}]", tags)).with(CONFIG.tag_color()),
+ tags = style(format!("[{tags}]")).with(CONFIG.tag_color()),
);
- let bracketed_current_variable = format!("<{}>", variable);
+ let bracketed_current_variable = format!("<{variable}>");
let bracketed_variables: Vec<&str> = {
if snippet.contains(&bracketed_current_variable) {
@@ -102,7 +102,7 @@ impl Runnable for Input {
}
println!("{snippet}", snippet = deser::fix_newlines(&colored_snippet));
- println!("{variables}", variables = variables);
+ println!("{variables}");
process::exit(0)
}
diff --git a/src/commands/repo/add.rs b/src/commands/repo/add.rs
index 20d481e..0c00a75 100644
--- a/src/commands/repo/add.rs
+++ b/src/commands/repo/add.rs
@@ -41,13 +41,13 @@ pub fn main(uri: String) -> Result<()> {
eprintln!("Cloning {} into {}...\n", &actual_uri, &tmp_path_str);
git::shallow_clone(actual_uri.as_str(), tmp_path_str)
- .with_context(|| format!("Failed to clone `{}`", actual_uri))?;
+ .with_context(|| format!("Failed to clone `{actual_uri}`"))?;
let all_files = filesystem::all_cheat_files(&tmp_pathbuf).join("\n");
let opts = FinderOpts {
suggestion_type: SuggestionType::MultipleSelections,
- preview: Some(format!("cat '{}/{{}}'", tmp_path_str)),
+ preview: Some(format!("cat '{tmp_path_str}/{{}}'")),
header: Some("Select the cheatsheets you want to import with <TAB> then hit <Enter>\nUse Ctrl-R for (de)selecting all".to_string()),
preview_window: Some("right:30%".to_string()),
..Default::default()
@@ -69,7 +69,7 @@ pub fn main(uri: String) -> Result<()> {
let to_folder = {
let mut p = cheat_pathbuf;
- p.push(format!("{}__{}", user, repo));
+ p.push(format!("{user}__{repo}"));
p
};
diff --git a/src/commands/repo/browse.rs b/src/commands/repo/browse.rs
index f14cd16..48d2828 100644
--- a/src/commands/repo/browse.rs
+++ b/src/commands/repo/browse.rs
@@ -21,7 +21,7 @@ pub fn main() -> Result<String> {
let (repo_url, _, _) = git::meta("denisidoro/cheats");
git::shallow_clone(repo_url.as_str(), repo_path_str)
- .with_context(|| format!("Failed to clone `{}`", repo_url))?;
+ .with_context(|| format!("Failed to clone `{repo_url}`"))?;
let feature_repos_file = {
let mut p = repo_pathbuf.clone();
diff --git a/src/commands/repo/mod.rs b/src/commands/repo/mod.rs
index 385eadf..be5dd25 100644
--- a/src/commands/repo/mod.rs
+++ b/src/commands/repo/mod.rs
@@ -27,13 +27,13 @@ impl Runnable for Input {
match &self.cmd {
RepoCommand::Add { uri } => {
add::main(uri.clone())
- .with_context(|| format!("Failed to import cheatsheets from `{}`", uri))?;
+ .with_context(|| format!("Failed to import cheatsheets from `{uri}`"))?;
commands::core::main()
}
RepoCommand::Browse => {
let repo = browse::main().context("Failed to browse featured cheatsheets")?;
add::main(repo.clone())
- .with_context(|| format!("Failed to import cheatsheets from `{}`", repo))?;
+ .with_context(|| format!("Failed to import cheatsheets from `{repo}`"))?;
commands::core::main()
}
}
diff --git a/src/commands/shell.rs b/src/commands/shell.rs
index f8da4cf..ca64d0f 100644
--- a/src/commands/shell.rs
+++ b/src/commands/shell.rs
@@ -36,7 +36,7 @@ impl Runnable for Input {
Shell::Elvish => include_str!("../../shell/navi.plugin.elv"),
};
- println!("{}", content);
+ println!("{content}");
Ok(())
}
diff --git a/src/common/clipboard.rs b/src/common/clipboard.rs
index 0e81c72..47cb761 100644
--- a/src/common/clipboard.rs
+++ b/src/common/clipboard.rs
@@ -23,14 +23,11 @@ _copy() {
.arg(
format!(
r#"{cmd}
- read -r -d '' x <<'{eof}'
+ read -r -d '' x <<'{EOF}'
{text}
-{eof}
+{EOF}
echo -n "$x" | _copy"#,
- cmd = cmd,
- text = text,
- eof = EOF,
)
.as_str(),
)
diff --git a/src/common/git.rs b/src/common/git.rs
index 9024613..2823fe6 100644
--- a/src/common/git.rs
+++ b/src/common/git.rs
@@ -16,7 +16,7 @@ pub fn meta(uri: &str) -> (String, String, String) {
let actual_uri = if uri.contains("://") || uri.contains('@') {
uri.to_string()
} else {
- format!("https://github.com/{}", uri)
+ format!("https://github.com/{uri}")
};
let uri_to_split = actual_uri.replace(':', "/");
diff --git a/src/common/terminal.rs b/src/common/terminal.rs
index bf7fb8c..e20432b 100644
--- a/src/common/terminal.rs
+++ b/src/common/terminal.rs
@@ -46,7 +46,7 @@ pub fn width() -> u16 {
}
pub fn parse_ansi(ansi: &str) -> Option<style::Color> {
- style::Color::parse_ansi(&format!("5;{}", ansi))
+ style::Color::parse_ansi(&format!("5;{ansi}"))
}
#[derive(Debug, Clone)]
diff --git a/src/common/url.rs b/src/common/url.rs
index b5b820d..a0e294e 100644
--- a/src/common/url.rs
+++ b/src/common/url.rs
@@ -26,14 +26,11 @@ _open_url() {
let cmd = format!(
r#"{code}
-read -r -d '' url <<'{eof}'
+read -r -d '' url <<'{EOF}'
{url}
-{eof}
+{EOF}
_open_url "$url""#,
- code = code,
- url = url,
- eof = EOF,
);
shell::out()
.arg(cmd.as_str())
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 6da5382..774f930 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -22,7 +22,7 @@ impl Config {
pub fn new() -> Self {
let env = EnvConfig::new();
let yaml = YamlConfig::get(&env).unwrap_or_else(|e| {
- eprintln!("Error parsing config file: {}", e);
+ eprintln!("Error parsing config file: {e}");
eprintln!("Fallbacking to default one...");
eprintln!();
YamlConfig::default()
diff --git a/src/config/yaml.rs b/src/config/yaml.rs
index ac59549..8c4a693 100644
--- a/src/config/yaml.rs
+++ b/src/config/yaml.rs
@@ -21,7 +21,7 @@ where
{
let s: String = Deserialize::deserialize(deserializer)?;
TerminalColor::try_from(s.as_str())
- .map_err(|_| de::Error::custom(format!("Failed to deserialize color: {}", s)))
+ .map_err(|_| de::Error::custom(format!("Failed to deserialize color: {s}")))
}
#[derive(Deserialize)]
@@ -55,7 +55,7 @@ where
{
let s: String = Deserialize::deserialize(deserializer)?;
FinderChoice::from_str(s.to_lowercase().as_str())
- .map_err(|_| de::Error::custom(format!("Failed to deserialize finder: {}", s)))
+ .map_err(|_| de::Error::custom(format!("Failed to deserialize finder: {s}")))
}
#[derive(Deserialize, Default)]
diff --git a/src/env_var.rs b/src/env_var.rs
index cd1c3a0..8097edd 100644
--- a/src/env_var.rs
+++ b/src/env_var.rs
@@ -31,7 +31,7 @@ pub fn must_get(name: &str) -> String {
if let Ok(v) = env::var(name) {
v
} else {
- panic!("{} not set", name)
+ panic!("{name} not set")
}
}
diff --git a/src/filesystem.rs b/src/filesystem.rs
index 9dc9f4e..d5f2962 100644
--- a/src/filesystem.rs
+++ b/src/filesystem.rs
@@ -94,8 +94,8 @@ fn interpolate_paths(paths: String) -> String {
let varname = c.as_str().replace(['$', '{', '}'], "");
if let Ok(replacement) = &env_var::get(&varname) {
newtext = newtext
- .replace(&format!("${}", varname), replacement)
- .replace(&format!("${{{}}}", varname), replacement);
+ .replace(&format!("${varname}"), replacement)
+ .replace(&format!("${{{varname}}}"), replacement);
}
}
}
diff --git a/src/finder/mod.rs b/src/finder/mod.rs
index ba33b41..b18888f 100644
--- a/src/finder/mod.rs
+++ b/src/finder/mod.rs
@@ -38,7 +38,7 @@ fn parse(out: Output, opts: Opts) -> Result<String> {
_ => {
let err = String::from_utf8(out.stderr)
.unwrap_or_else(|_| "<stderr contains invalid UTF-8>".to_owned());
- panic!("External command failed:\n {}", err)
+ panic!("External command failed:\n {err}")
}
};
@@ -74,12 +74,12 @@ impl FinderChoice {
"--preview",
"",
"--preview-window",
- format!("up:{}:nohidden", preview_height).as_str(),
+ format!("up:{preview_height}:nohidden").as_str(),
"--delimiter",
deser::terminal::DELIMITER.to_string().as_str(),
"--ansi",
"--bind",
- format!("ctrl-j:down,ctrl-k:up{}", bindings).as_str(),
+ format!("ctrl-j:down,ctrl-k:up{bindings}").as_str(),
"--exact",
]);
diff --git a/src/finder/post.rs b/src/finder/post.rs
index 717b7a9..9daa962 100644
--- a/src/finder/post.rs
+++ b/src/finder/post.rs
@@ -7,13 +7,13 @@ use std::process::Stdio;
fn apply_map(text: String, map_fn: Option<String>) -> Result<String> {
if let Some(m) = map_fn {
let cmd = if CONFIG.shell().contains("fish") {
- format!(r#"printf "%s" "{text}" | {m}"#, m = m, text = text)
+ format!(r#"printf "%s" "{text}" | {m}"#)
} else {
format!(
r#"_navi_input() {{
-cat <<'{eof}'
+cat <<'{EOF}'
{text}
-{eof}
+{EOF}
}}
_navi_map_fn() {{
@@ -24,10 +24,7 @@ _navi_nonewline() {{
printf "%s" "$(cat)"
}}
-_navi_input | _navi_map_fn | _navi_nonewline"#,
- m = m,
- text = text,
- eof = EOF
+_navi_input | _navi_map_fn | _navi_nonewline"#
)
};
diff --git a/src/parser.rs b/src/parser.rs
index 9498ed4..8b4dd10 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -247,7 +247,7 @@ impl<'a> Parser<'a> {
for (line_nr, line_result) in lines.enumerate() {
let line = line_result
- .with_context(|| format!("Failed to read line number {} in cheatsheet `{}`", line_nr, id))?;
+ .with_context(|| format!("Failed to read line number {line_nr} in cheatsheet `{id}`"))?;
if should_break {
break;