Fix --map when using zsh

Fixes #584
This commit is contained in:
Denis Isidoro 2021-08-08 17:58:42 -03:00 committed by GitHub
parent 85ca69a263
commit 0f95a29dfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 16 deletions

View file

@ -67,8 +67,6 @@ fn prompt_finder(
let exe = fs::exe_string();
let subshell_prefix = if CONFIG.shell().contains("fish") { "" } else { "$" };
let preview = if cfg!(target_os = "windows") {
format!(
r#"(@echo.{{+}}{eof}{{q}}{eof}{name}{eof}{extra}) | {exe} preview-var-stdin"#,
@ -77,18 +75,27 @@ fn prompt_finder(
extra = extra_preview.clone().unwrap_or_default(),
eof = EOF,
)
} else if CONFIG.shell().contains("fish") {
format!(
r#"{exe} preview-var "{{+}}" "{{q}}" "{name}"; {extra}"#,
exe = exe,
name = variable_name,
extra = extra_preview
.clone()
.map(|e| format!(" echo; {}", e))
.unwrap_or_default(),
)
} else {
format!(
r#"{exe} preview-var "{subshell_prefix}(cat <<{eof}
r#"{exe} preview-var "$(cat <<{eof}
{{+}}
{eof}
)" "{subshell_prefix}(cat <<{eof}
)" "$(cat <<{eof}
{{q}}
{eof}
)" "{name}"; {extra}"#,
exe = exe,
name = variable_name,
subshell_prefix = subshell_prefix,
extra = extra_preview
.clone()
.map(|e| format!(" echo; {}", e))

View file

@ -1,3 +1,4 @@
use crate::config::CONFIG;
use crate::finder::structures::SuggestionType;
use crate::shell;
use anyhow::Context;
@ -7,21 +8,30 @@ use std::process::Stdio;
fn apply_map(text: String, map_fn: Option<String>) -> Result<String> {
if let Some(m) = map_fn {
let cmd = format!(
r#"
let cmd = if CONFIG.shell().contains("fish") {
format!(r#"printf "%s" "{text}" | {m}"#, m = m, text = text)
} else {
format!(
r#"_navi_input() {{
cat <<'{eof}'
{text}
{eof}
}}
_navi_map_fn() {{
{m}
}}
read -r -d '' _navi_input <<'{eof}'
{text}
{eof}
echo "$_navi_input" | _navi_map_fn"#,
m = m,
text = text,
eof = EOF
);
_navi_nonewline() {{
printf "%s" "$(cat)"
}}
_navi_input | _navi_map_fn | _navi_nonewline"#,
m = m,
text = text,
eof = EOF
)
};
let output = shell::out()
.arg(cmd.as_str())