mirror of
https://github.com/denisidoro/navi
synced 2024-11-13 23:37:10 +00:00
parent
5f8079668c
commit
8725654a74
11 changed files with 47 additions and 10 deletions
|
@ -29,3 +29,4 @@ finder:
|
|||
|
||||
shell:
|
||||
command: bash # shell used for shell out. possible values: bash, zsh, dash, ...
|
||||
# finder_command: bash # similar, but for fzf's internals
|
||||
|
|
|
@ -8,7 +8,6 @@ pub struct EnvConfig {
|
|||
pub config_yaml: Option<String>,
|
||||
pub config_path: Option<String>,
|
||||
pub path: Option<String>,
|
||||
pub shell: Option<String>,
|
||||
pub finder: Option<FinderChoice>,
|
||||
pub fzf_overrides: Option<String>,
|
||||
pub fzf_overrides_var: Option<String>,
|
||||
|
@ -20,7 +19,6 @@ impl EnvConfig {
|
|||
config_yaml: env_var::get(env_var::CONFIG_YAML).ok(),
|
||||
config_path: env_var::get(env_var::CONFIG).ok(),
|
||||
path: env_var::get(env_var::PATH).ok(),
|
||||
shell: env_var::get(env_var::SHELL).ok(),
|
||||
finder: env_var::get(env_var::FINDER)
|
||||
.ok()
|
||||
.and_then(|x| FinderChoice::from_str(&x).ok()),
|
||||
|
|
|
@ -93,6 +93,14 @@ impl Config {
|
|||
self.yaml.shell.command.clone()
|
||||
}
|
||||
|
||||
pub fn finder_shell(&self) -> String {
|
||||
self.yaml
|
||||
.shell
|
||||
.finder_command
|
||||
.clone()
|
||||
.unwrap_or_else(|| self.yaml.shell.command.clone())
|
||||
}
|
||||
|
||||
pub fn tag_rules(&self) -> Option<String> {
|
||||
self.clap
|
||||
.tag_rules
|
||||
|
|
|
@ -80,6 +80,7 @@ pub struct Search {
|
|||
#[serde(default)]
|
||||
pub struct Shell {
|
||||
pub command: String,
|
||||
pub finder_command: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
|
@ -177,6 +178,7 @@ impl Default for Shell {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
command: "bash".to_string(),
|
||||
finder_command: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ pub const FZF_OVERRIDES: &str = "NAVI_FZF_OVERRIDES";
|
|||
pub const FZF_OVERRIDES_VAR: &str = "NAVI_FZF_OVERRIDES_VAR";
|
||||
pub const FINDER: &str = "NAVI_FINDER";
|
||||
|
||||
pub const SHELL: &str = "NAVI_SHELL";
|
||||
|
||||
pub const CONFIG: &str = "NAVI_CONFIG";
|
||||
pub const CONFIG_YAML: &str = "NAVI_CONFIG_YAML";
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ impl Finder for FinderChoice {
|
|||
}
|
||||
|
||||
let child = command
|
||||
.env("SHELL", CONFIG.shell())
|
||||
.env("SHELL", CONFIG.finder_shell())
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn();
|
||||
|
|
12
src/shell.rs
12
src/shell.rs
|
@ -36,10 +36,14 @@ impl ShellSpawnError {
|
|||
}
|
||||
|
||||
pub fn out() -> Command {
|
||||
let shell = CONFIG.shell();
|
||||
let mut cmd = Command::new(&shell);
|
||||
let arg = if shell == "cmd.exe" { "/c" } else { "-c" };
|
||||
cmd.arg(arg);
|
||||
let words_str = CONFIG.shell();
|
||||
let mut words_vec = shellwords::split(&words_str).expect("empty shell command");
|
||||
let mut words = words_vec.iter_mut();
|
||||
let first_cmd = words.next().expect("absent shell binary");
|
||||
let mut cmd = Command::new(&first_cmd);
|
||||
cmd.args(words);
|
||||
let dash_c = if words_str.contains("cmd.exe") { "/c" } else { "-c" };
|
||||
cmd.arg(dash_c);
|
||||
cmd
|
||||
}
|
||||
|
||||
|
|
18
tests/config.yaml
Normal file
18
tests/config.yaml
Normal file
|
@ -0,0 +1,18 @@
|
|||
style:
|
||||
tag:
|
||||
color: cyan
|
||||
width_percentage: 26
|
||||
min_width: 20
|
||||
comment:
|
||||
color: yellow
|
||||
width_percentage: 42
|
||||
min_width: 45
|
||||
snippet:
|
||||
color: white
|
||||
|
||||
finder:
|
||||
command: fzf
|
||||
|
||||
shell:
|
||||
finder_command: bash
|
||||
command: env BASH_ENV="${NAVI_HOME}/tests/helpers.sh" bash --norc --noprofile
|
5
tests/helpers.sh
Normal file
5
tests/helpers.sh
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/usr/local/bin/env bash
|
||||
|
||||
myhelperfn() {
|
||||
echo "inside helper: $*"
|
||||
}
|
|
@ -61,6 +61,9 @@ echo "foo" \
|
|||
# multiline variable -> "foo bar"
|
||||
echo "<multilinevar>"
|
||||
|
||||
# helper -> "inside helper: 42"
|
||||
myhelperfn 42
|
||||
|
||||
$ x: echo '2'
|
||||
$ x2: echo "$((x+10))"
|
||||
$ y: echo 'a'
|
||||
|
|
|
@ -19,7 +19,7 @@ _navi() {
|
|||
local path="${NAVI_TEST_PATH:-$TEST_CHEAT_PATH}"
|
||||
path="${path//$HOME/~}"
|
||||
export NAVI_ENV_VAR_PATH="$path"
|
||||
RUST_BACKTRACE=1 NAVI_PATH='$NAVI_ENV_VAR_PATH' "$NAVI_EXE" "$@"
|
||||
RUST_BACKTRACE=1 NAVI_PATH='$NAVI_ENV_VAR_PATH' NAVI_CONFIG="${NAVI_HOME}/tests/config.yaml" "$NAVI_EXE" "$@"
|
||||
}
|
||||
|
||||
_navi_cases() {
|
||||
|
|
Loading…
Reference in a new issue