Skip to content

Commit

Permalink
Fix --map when using zsh
Browse files Browse the repository at this point in the history
Fixes #584
  • Loading branch information
denisidoro authored Aug 8, 2021
1 parent 85ca69a commit 0f95a29
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
17 changes: 12 additions & 5 deletions src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"#,
Expand All @@ -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))
Expand Down
32 changes: 21 additions & 11 deletions src/finder/post.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::config::CONFIG;
use crate::finder::structures::SuggestionType;
use crate::shell;
use anyhow::Context;
Expand All @@ -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())
Expand Down

0 comments on commit 0f95a29

Please sign in to comment.