mirror of
https://github.com/denisidoro/navi
synced 2024-11-24 20:43:06 +00:00
Use absolute path for navi when possible (#535)
This commit is contained in:
parent
baa477cd81
commit
30fbb30514
3 changed files with 21 additions and 7 deletions
20
src/actor.rs
20
src/actor.rs
|
@ -75,7 +75,7 @@ fn prompt_finder(
|
||||||
o
|
o
|
||||||
};
|
};
|
||||||
|
|
||||||
let exe = fs::exe_string()?;
|
let exe = fs::exe_string();
|
||||||
let extra = extra_preview.clone().unwrap_or_default();
|
let extra = extra_preview.clone().unwrap_or_default();
|
||||||
|
|
||||||
let preview = if cfg!(target_os = "windows") {
|
let preview = if cfg!(target_os = "windows") {
|
||||||
|
@ -180,6 +180,13 @@ fn replace_variables_from_snippet(snippet: &str, tags: &str, variables: Variable
|
||||||
Ok(interpolated_snippet)
|
Ok(interpolated_snippet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_absolute_path(snippet: String) -> String {
|
||||||
|
if let Some(s) = snippet.strip_prefix("navi ") {
|
||||||
|
return format!("{} {}", fs::exe_string(), s);
|
||||||
|
}
|
||||||
|
snippet
|
||||||
|
}
|
||||||
|
|
||||||
pub fn act(
|
pub fn act(
|
||||||
extractions: Result<extractor::Output>,
|
extractions: Result<extractor::Output>,
|
||||||
files: Vec<String>,
|
files: Vec<String>,
|
||||||
|
@ -197,14 +204,17 @@ pub fn act(
|
||||||
env_var::set(env_var::PREVIEW_TAGS, &tags);
|
env_var::set(env_var::PREVIEW_TAGS, &tags);
|
||||||
env_var::set(env_var::PREVIEW_COMMENT, &comment);
|
env_var::set(env_var::PREVIEW_COMMENT, &comment);
|
||||||
|
|
||||||
let interpolated_snippet = writer::with_new_lines(
|
let interpolated_snippet = {
|
||||||
replace_variables_from_snippet(
|
let mut s = replace_variables_from_snippet(
|
||||||
snippet,
|
snippet,
|
||||||
tags,
|
tags,
|
||||||
variables.expect("No variables received from finder"),
|
variables.expect("No variables received from finder"),
|
||||||
)
|
)
|
||||||
.context("Failed to replace variables from snippet")?,
|
.context("Failed to replace variables from snippet")?;
|
||||||
);
|
s = with_absolute_path(s);
|
||||||
|
s = writer::with_new_lines(s);
|
||||||
|
s
|
||||||
|
};
|
||||||
|
|
||||||
match CONFIG.action() {
|
match CONFIG.action() {
|
||||||
Action::Print => {
|
Action::Print => {
|
||||||
|
|
|
@ -54,7 +54,7 @@ pub enum SuggestionType {
|
||||||
impl Opts {
|
impl Opts {
|
||||||
pub fn from_config(config: &Config) -> Result<Opts> {
|
pub fn from_config(config: &Config) -> Result<Opts> {
|
||||||
let opts = Opts {
|
let opts = Opts {
|
||||||
preview: Some(format!("{} preview {{}}", filesystem::exe_string()?)),
|
preview: Some(format!("{} preview {{}}", filesystem::exe_string())),
|
||||||
overrides: config.fzf_overrides(),
|
overrides: config.fzf_overrides(),
|
||||||
suggestion_type: SuggestionType::SnippetSelection,
|
suggestion_type: SuggestionType::SnippetSelection,
|
||||||
query: if config.best_match() {
|
query: if config.best_match() {
|
||||||
|
|
|
@ -67,10 +67,14 @@ fn exe_pathbuf() -> Result<PathBuf> {
|
||||||
follow_symlink(pathbuf)
|
follow_symlink(pathbuf)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exe_string() -> Result<String> {
|
fn exe_abs_string() -> Result<String> {
|
||||||
pathbuf_to_string(&exe_pathbuf()?)
|
pathbuf_to_string(&exe_pathbuf()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn exe_string() -> String {
|
||||||
|
exe_abs_string().unwrap_or_else(|_| "navi".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create_dir(path: &Path) -> Result<()> {
|
pub fn create_dir(path: &Path) -> Result<()> {
|
||||||
create_dir_all(path).with_context(|| {
|
create_dir_all(path).with_context(|| {
|
||||||
format!(
|
format!(
|
||||||
|
|
Loading…
Reference in a new issue