mirror of
https://github.com/denisidoro/navi.git
synced 2026-07-17 16:49:25 +00:00
Make bash available on Windows
This commit is contained in:
parent
b4ce885253
commit
90b409f613
4 changed files with 62 additions and 0 deletions
|
|
@ -231,3 +231,45 @@ finder:
|
|||
You can override this configuration with the `--delimiter` instruction in the variable definition of your cheat.\
|
||||
See [/docs/cheatsheet/syntax/](/docs/cheatsheet/syntax/README.md#advanced-variable-options) for more details.
|
||||
|
||||
## Changing shell
|
||||
|
||||
You can change the shell that is used inside navi.
|
||||
|
||||
```yaml
|
||||
shell:
|
||||
command: bash
|
||||
finder_command: bash
|
||||
```
|
||||
|
||||
`shell.command` is used to execute commands that generate possible values for variables.
|
||||
`shell.finder_command` is used inside fzf.
|
||||
|
||||
For example, suppose you have the following cheat sheet.
|
||||
|
||||
```
|
||||
# ISO 8061
|
||||
date -I<iso_unit>
|
||||
|
||||
$ iso_unit: echo -e 'date\nhours\nminutes\nseconds\nns'
|
||||
```
|
||||
|
||||
The command `echo -e 'date\nhours\nminutes\nseconds\nns'` is executed in the shell specified by `shell.command`.
|
||||
|
||||
### Use bash on Windows
|
||||
|
||||
On Windows, there are several bash environments available, including MSYS2's bash, Git Bash, and [w64devkit](https://github.com/skeeto/w64devkit)'s bash.
|
||||
The w64devkit's bash isn't actually bash, but it can be used just like bash.
|
||||
Here is an example of using Git Bash.
|
||||
|
||||
```yaml
|
||||
shell:
|
||||
command: "\"C:/Program Files/Git/bin/bash.exe\""
|
||||
finder_command: "C:/Program Files/Git/bin/bash.exe"
|
||||
forward_slash_path: true
|
||||
```
|
||||
|
||||
If the path to the executable contains spaces, it must be quoted in the `shell.command`.
|
||||
Unlike `shell.command`, `shell.finder_command` does not require the path to be quoted even if it contains spaces.
|
||||
Additionaly, `shell.forward_slash_path` must be set to `true`.
|
||||
`shell.forward_slash_path: true` can be used with bash environments that interpret paths with forward slashes (e.g., `C:/path/to/bash.exe`).
|
||||
Other than Windows, setting `shell.forward_slash_path` has no effect.
|
||||
|
|
|
|||
|
|
@ -90,6 +90,20 @@ fn exe_abs_string() -> Result<String> {
|
|||
pathbuf_to_string(&exe_pathbuf()?)
|
||||
}
|
||||
|
||||
#[cfg(target_family = "windows")]
|
||||
pub fn exe_string() -> String {
|
||||
exe_abs_string()
|
||||
.map(|exe| {
|
||||
if CONFIG.forward_slash_path() {
|
||||
exe.replace("\\", "/")
|
||||
} else {
|
||||
exe
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|_| "navi".to_string())
|
||||
}
|
||||
|
||||
#[cfg(not(target_family = "windows"))]
|
||||
pub fn exe_string() -> String {
|
||||
exe_abs_string().unwrap_or_else(|_| "navi".to_string())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,6 +146,10 @@ impl Config {
|
|||
.unwrap_or_else(|| self.yaml.shell.command.clone())
|
||||
}
|
||||
|
||||
pub fn forward_slash_path(&self) -> bool {
|
||||
self.yaml.shell.forward_slash_path
|
||||
}
|
||||
|
||||
pub fn tag_rules(&self) -> Option<String> {
|
||||
self.clap
|
||||
.tag_rules
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ pub struct Search {
|
|||
pub struct Shell {
|
||||
pub command: String,
|
||||
pub finder_command: Option<String>,
|
||||
pub forward_slash_path: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
|
@ -187,6 +188,7 @@ impl Default for Shell {
|
|||
Self {
|
||||
command: "bash".to_string(),
|
||||
finder_command: None,
|
||||
forward_slash_path: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue