mirror of
https://github.com/denisidoro/navi
synced 2024-11-24 20:43:06 +00:00
parent
85ca69a263
commit
0f95a29dfd
2 changed files with 33 additions and 16 deletions
17
src/actor.rs
17
src/actor.rs
|
@ -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))
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue