mirror of
https://github.com/denisidoro/navi
synced 2024-11-10 05:54:18 +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
|
||||
};
|
||||
|
||||
let exe = fs::exe_string()?;
|
||||
let exe = fs::exe_string();
|
||||
let extra = extra_preview.clone().unwrap_or_default();
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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(
|
||||
extractions: Result<extractor::Output>,
|
||||
files: Vec<String>,
|
||||
|
@ -197,14 +204,17 @@ pub fn act(
|
|||
env_var::set(env_var::PREVIEW_TAGS, &tags);
|
||||
env_var::set(env_var::PREVIEW_COMMENT, &comment);
|
||||
|
||||
let interpolated_snippet = writer::with_new_lines(
|
||||
replace_variables_from_snippet(
|
||||
let interpolated_snippet = {
|
||||
let mut s = replace_variables_from_snippet(
|
||||
snippet,
|
||||
tags,
|
||||
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() {
|
||||
Action::Print => {
|
||||
|
|
|
@ -54,7 +54,7 @@ pub enum SuggestionType {
|
|||
impl Opts {
|
||||
pub fn from_config(config: &Config) -> Result<Opts> {
|
||||
let opts = Opts {
|
||||
preview: Some(format!("{} preview {{}}", filesystem::exe_string()?)),
|
||||
preview: Some(format!("{} preview {{}}", filesystem::exe_string())),
|
||||
overrides: config.fzf_overrides(),
|
||||
suggestion_type: SuggestionType::SnippetSelection,
|
||||
query: if config.best_match() {
|
||||
|
|
|
@ -67,10 +67,14 @@ fn exe_pathbuf() -> Result<PathBuf> {
|
|||
follow_symlink(pathbuf)
|
||||
}
|
||||
|
||||
pub fn exe_string() -> Result<String> {
|
||||
fn exe_abs_string() -> Result<String> {
|
||||
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<()> {
|
||||
create_dir_all(path).with_context(|| {
|
||||
format!(
|
||||
|
|
Loading…
Reference in a new issue