mirror of
https://github.com/denisidoro/navi
synced 2024-11-24 20:43:06 +00:00
Fix Windows builds (#522)
This commit is contained in:
parent
639e1dc46a
commit
2266c1bc75
9 changed files with 92 additions and 30 deletions
42
src/actor.rs
42
src/actor.rs
|
@ -1,17 +1,18 @@
|
|||
use crate::clipboard;
|
||||
use crate::config::Action;
|
||||
|
||||
use crate::config::CONFIG;
|
||||
use crate::env_var;
|
||||
use crate::extractor;
|
||||
use crate::finder::structures::{Opts as FinderOpts, SuggestionType};
|
||||
use crate::finder::Finder;
|
||||
use crate::fs;
|
||||
use crate::shell;
|
||||
use crate::shell::ShellSpawnError;
|
||||
use crate::structures::cheat::{Suggestion, VariableMap};
|
||||
use crate::writer;
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use shell::EOF;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::process::Stdio;
|
||||
|
@ -75,19 +76,36 @@ fn prompt_finder(
|
|||
o
|
||||
};
|
||||
|
||||
let exe = fs::exe_string()?;
|
||||
let extra = extra_preview.clone().unwrap_or_default();
|
||||
|
||||
let preview = if cfg!(target_os = "macos") {
|
||||
format!(
|
||||
r#"(@echo.{{+}}{eof}{{q}}{eof}{name}){eof}{extra} | {exe} preview-var-stdin"#,
|
||||
exe = exe,
|
||||
name = variable_name,
|
||||
extra = extra,
|
||||
eof = EOF,
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
r#"{exe} preview-var "$(cat <<{eof}
|
||||
{{+}}
|
||||
{eof}
|
||||
)" "$(cat <<{eof}
|
||||
{{q}}
|
||||
{eof}
|
||||
)" "{name}"; {extra}"#,
|
||||
exe = exe,
|
||||
name = variable_name,
|
||||
extra = extra,
|
||||
eof = EOF,
|
||||
)
|
||||
};
|
||||
|
||||
let mut opts = FinderOpts {
|
||||
overrides,
|
||||
preview: Some(format!(
|
||||
r#"navi preview-var "$(cat <<NAVIEOF
|
||||
{{+}}
|
||||
NAVIEOF
|
||||
)" "$(cat <<NAVIEOF
|
||||
{{q}}
|
||||
NAVIEOF
|
||||
)" "{name}"; {extra}"#,
|
||||
name = variable_name,
|
||||
extra = extra_preview.clone().unwrap_or_default()
|
||||
)),
|
||||
preview: Some(preview),
|
||||
..initial_opts.clone().unwrap_or_default()
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::shell::{self, ShellSpawnError};
|
||||
use crate::shell::{self, ShellSpawnError, EOF};
|
||||
use anyhow::Result;
|
||||
|
||||
pub fn copy(text: String) -> Result<()> {
|
||||
|
@ -23,13 +23,15 @@ _copy() {
|
|||
.arg("-c")
|
||||
.arg(
|
||||
format!(
|
||||
r#"{}
|
||||
read -r -d '' x <<'NAVIEOF'
|
||||
{}
|
||||
NAVIEOF
|
||||
r#"{cmd}
|
||||
read -r -d '' x <<'{eof}'
|
||||
{text}
|
||||
{eof}
|
||||
|
||||
echo -n "$x" | _copy"#,
|
||||
cmd, text
|
||||
cmd = cmd,
|
||||
text = text,
|
||||
eof = EOF,
|
||||
)
|
||||
.as_str(),
|
||||
)
|
||||
|
|
|
@ -167,6 +167,9 @@ pub enum Command {
|
|||
/// Typed text
|
||||
variable: String,
|
||||
},
|
||||
/// Used for fzf's preview window when selecting variable suggestions
|
||||
#[clap(setting = AppSettings::Hidden)]
|
||||
PreviewVarStdin,
|
||||
/// Outputs shell widget source code
|
||||
Widget {
|
||||
#[clap(possible_values = WIDGET_POSSIBLE_VALUES, case_insensitive = true, default_value = "bash")]
|
||||
|
|
|
@ -2,6 +2,7 @@ use crate::finder::structures::SuggestionType;
|
|||
use crate::shell;
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use shell::EOF;
|
||||
use std::process::Stdio;
|
||||
|
||||
fn apply_map(text: String, map_fn: Option<String>) -> Result<String> {
|
||||
|
@ -9,15 +10,17 @@ fn apply_map(text: String, map_fn: Option<String>) -> Result<String> {
|
|||
let cmd = format!(
|
||||
r#"
|
||||
_navi_map_fn() {{
|
||||
{}
|
||||
{m}
|
||||
}}
|
||||
|
||||
read -r -d '' _navi_input <<'NAVIEOF'
|
||||
{}
|
||||
NAVIEOF
|
||||
read -r -d '' _navi_input <<'{eof}'
|
||||
{text}
|
||||
{eof}
|
||||
|
||||
echo "$_navi_input" | _navi_map_fn"#,
|
||||
m, text
|
||||
m = m,
|
||||
text = text,
|
||||
eof = EOF
|
||||
);
|
||||
|
||||
let output = shell::command()
|
||||
|
|
|
@ -3,11 +3,12 @@ pub mod func;
|
|||
pub mod info;
|
||||
pub mod preview;
|
||||
pub mod preview_var;
|
||||
pub mod preview_var_stdin;
|
||||
pub mod repo_add;
|
||||
pub mod repo_browse;
|
||||
pub mod shell;
|
||||
|
||||
use crate::config::Command::{Fn, Info, Preview, PreviewVar, Repo, Widget};
|
||||
use crate::config::Command::{Fn, Info, Preview, PreviewVar, PreviewVarStdin, Repo, Widget};
|
||||
use crate::config::{RepoCommand, CONFIG};
|
||||
use crate::handler;
|
||||
use anyhow::Context;
|
||||
|
@ -20,6 +21,8 @@ pub fn handle() -> Result<()> {
|
|||
Some(c) => match c {
|
||||
Preview { line } => handler::preview::main(line),
|
||||
|
||||
PreviewVarStdin => handler::preview_var_stdin::main(),
|
||||
|
||||
PreviewVar {
|
||||
selection,
|
||||
query,
|
||||
|
|
28
src/handler/preview_var_stdin.rs
Executable file
28
src/handler/preview_var_stdin.rs
Executable file
|
@ -0,0 +1,28 @@
|
|||
use crate::shell::{self, ShellSpawnError, EOF};
|
||||
use anyhow::Result;
|
||||
use std::io::{self, Read};
|
||||
|
||||
pub fn main() -> Result<()> {
|
||||
let mut text = String::new();
|
||||
io::stdin().read_to_string(&mut text)?;
|
||||
|
||||
let mut parts = text.split(EOF);
|
||||
let selection = parts.next().expect("Unable to get selection");
|
||||
let query = parts.next().expect("Unable to get query");
|
||||
let variable = parts.next().expect("Unable to get variable").trim();
|
||||
|
||||
super::handler::preview_var::main(selection, query, variable)?;
|
||||
|
||||
if let Some(extra) = parts.next() {
|
||||
if !extra.is_empty() {
|
||||
shell::command()
|
||||
.arg("-c")
|
||||
.arg(extra)
|
||||
.spawn()
|
||||
.map_err(|e| ShellSpawnError::new(extra, e))?
|
||||
.wait()?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -5,6 +5,8 @@ use std::io::{self, Read};
|
|||
use std::process::Command;
|
||||
use thiserror::Error;
|
||||
|
||||
pub const EOF: &str = "NAVIEOF";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Shell {
|
||||
Bash,
|
||||
|
|
13
src/url.rs
13
src/url.rs
|
@ -1,5 +1,6 @@
|
|||
use crate::shell::{self, ShellSpawnError};
|
||||
use anyhow::Result;
|
||||
use shell::EOF;
|
||||
|
||||
pub fn open(args: Vec<String>) -> Result<()> {
|
||||
let url = args
|
||||
|
@ -22,14 +23,16 @@ _open_url() {
|
|||
fi
|
||||
}"#;
|
||||
let cmd = format!(
|
||||
r#"{}
|
||||
r#"{code}
|
||||
|
||||
read -r -d '' url <<'NAVIEOF'
|
||||
{}
|
||||
NAVIEOF
|
||||
read -r -d '' url <<'{eof}'
|
||||
{url}
|
||||
{eof}
|
||||
|
||||
_open_url "$url""#,
|
||||
code, url
|
||||
code = code,
|
||||
url = url,
|
||||
eof = EOF,
|
||||
);
|
||||
shell::command()
|
||||
.arg("-c")
|
||||
|
|
|
@ -9,7 +9,7 @@ pub const DELIMITER: &str = r" ⠀";
|
|||
|
||||
lazy_static! {
|
||||
pub static ref NEWLINE_REGEX: Regex = Regex::new(r"\\\s+").expect("Invalid regex");
|
||||
pub static ref VAR_REGEX: Regex = Regex::new(r"<(\w[\w\d\-_]*)>").expect("Invalid regex");
|
||||
pub static ref VAR_REGEX: Regex = Regex::new(r"\\?<(\w[\w\d\-_]*)>").expect("Invalid regex");
|
||||
pub static ref COLUMN_WIDTHS: (usize, usize) = ui::get_widths();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue