Add `tool.shell` configuration key (#302)

pull/304/head
Leonardo Mello 1 year ago committed by GitHub
parent ba611e1c1e
commit a8d1db4c57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,11 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
<!--## Unreleased--> ## Unreleased
### Added
* New [`tool.shell`](docs/tool-shell.md) configuration key to set a custom shell (contributed by [@lsvmello](https://github.com/mickael-menu/zk/pull/302)).
## 0.13.0 ## 0.13.0

@ -6,7 +6,7 @@ Declaring your own aliases is a great way to make your experience with `zk` easi
## Configuring aliases ## Configuring aliases
Command aliases are declared in your [configuration file](config.md), under the `[alias]` section. They are executed with `$SHELL -c`, which allows you to: Command aliases are declared in your [configuration file](config.md), under the `[alias]` section. They are executed with [your default shell](tool-shell.md), which allows you to:
* expand arguments with `$@` or `$*` * expand arguments with `$@` or `$*`
* expand environment variables * expand environment variables

@ -8,6 +8,7 @@ Each [notebook](notebook.md) contains a configuration file used to customize you
* `[format]` configures the [note format settings](note-format.md), such as Markdown options * `[format]` configures the [note format settings](note-format.md), such as Markdown options
* `[tool]` customizes interaction with external programs such as: * `[tool]` customizes interaction with external programs such as:
* [your default editor](tool-editor.md) * [your default editor](tool-editor.md)
* [your default shell](tool-shell.md)
* [your default pager](tool-pager.md) * [your default pager](tool-pager.md)
* [`fzf`](tool-fzf.md) * [`fzf`](tool-fzf.md)
* `[lsp]` setups the [Language Server Protocol settings](config-lsp.md) for [editors integration](editors-integration.md) * `[lsp]` setups the [Language Server Protocol settings](config-lsp.md) for [editors integration](editors-integration.md)
@ -63,10 +64,10 @@ author = "Mickaël"
# GROUP OVERRIDES # GROUP OVERRIDES
[dir.journal] [group.journal]
paths = ["journal/weekly", "journal/daily"] paths = ["journal/weekly", "journal/daily"]
[dir.journal.note] [group.journal.note]
filename = "{{format-date now}}" filename = "{{format-date now}}"
@ -84,6 +85,9 @@ colon-tags = true
# Default editor used to open notes. # Default editor used to open notes.
editor = "nvim" editor = "nvim"
# Default shell used by aliases and commands.
shell = "/bin/bash"
# Pager used to scroll through long output. # Pager used to scroll through long output.
pager = "less -FIRX" pager = "less -FIRX"

@ -0,0 +1,14 @@
# Setting your default shell
This is *currently* not supported on Windows (that defaults always to `cmd`).
You can customize which shell to use to run aliases and commands either from the [configuration file](config.md) or environment variables. In order of precedence, `zk` will use:
1. `ZK_SHELL` environment variable
2. `shell` configuration property
```toml
[tool]
shell = "/bin/bash"
```
3. `SHELL` environment variable
4. `sh` as fallback

@ -71,6 +71,11 @@ func NewContainer(version string) (*Container, error) {
} }
} }
// Set the default shell if not already set
if osutil.GetOptEnv("ZK_SHELL").IsNull() && !config.Tool.Shell.IsEmpty() {
os.Setenv("ZK_SHELL", config.Tool.Shell.Unwrap())
}
return &Container{ return &Container{
Version: version, Version: version,
Config: config, Config: config,

@ -148,6 +148,7 @@ type MarkdownConfig struct {
// ToolConfig holds the external tooling configuration. // ToolConfig holds the external tooling configuration.
type ToolConfig struct { type ToolConfig struct {
Editor opt.String Editor opt.String
Shell opt.String
Pager opt.String Pager opt.String
FzfPreview opt.String FzfPreview opt.String
FzfLine opt.String FzfLine opt.String
@ -355,6 +356,9 @@ func ParseConfig(content []byte, path string, parentConfig Config) (Config, erro
if tool.Editor != nil { if tool.Editor != nil {
config.Tool.Editor = opt.NewNotEmptyString(*tool.Editor) config.Tool.Editor = opt.NewNotEmptyString(*tool.Editor)
} }
if tool.Shell != nil {
config.Tool.Shell = opt.NewNotEmptyString(*tool.Shell)
}
if tool.Pager != nil { if tool.Pager != nil {
config.Tool.Pager = opt.NewStringWithPtr(tool.Pager) config.Tool.Pager = opt.NewStringWithPtr(tool.Pager)
} }
@ -511,6 +515,7 @@ type tomlMarkdownConfig struct {
type tomlToolConfig struct { type tomlToolConfig struct {
Editor *string Editor *string
Shell *string
Pager *string Pager *string
FzfPreview *string `toml:"fzf-preview"` FzfPreview *string `toml:"fzf-preview"`
FzfLine *string `toml:"fzf-line"` FzfLine *string `toml:"fzf-line"`

@ -40,6 +40,7 @@ func TestParseDefaultConfig(t *testing.T) {
}, },
Tool: ToolConfig{ Tool: ToolConfig{
Editor: opt.NullString, Editor: opt.NullString,
Shell: opt.NullString,
Pager: opt.NullString, Pager: opt.NullString,
FzfPreview: opt.NullString, FzfPreview: opt.NullString,
FzfLine: opt.NullString, FzfLine: opt.NullString,
@ -86,6 +87,7 @@ func TestParseComplete(t *testing.T) {
[tool] [tool]
editor = "vim" editor = "vim"
shell = "/bin/bash"
pager = "less" pager = "less"
fzf-preview = "bat {1}" fzf-preview = "bat {1}"
fzf-line = "{{title}}" fzf-line = "{{title}}"
@ -228,6 +230,7 @@ func TestParseComplete(t *testing.T) {
}, },
Tool: ToolConfig{ Tool: ToolConfig{
Editor: opt.NewString("vim"), Editor: opt.NewString("vim"),
Shell: opt.NewString("/bin/bash"),
Pager: opt.NewString("less"), Pager: opt.NewString("less"),
FzfPreview: opt.NewString("bat {1}"), FzfPreview: opt.NewString("bat {1}"),
FzfLine: opt.NewString("{{title}}"), FzfLine: opt.NewString("{{title}}"),

@ -10,7 +10,10 @@ import (
// Getenv returns an optional String for the environment variable with given // Getenv returns an optional String for the environment variable with given
// key. // key.
func GetOptEnv(key string) opt.String { func GetOptEnv(key string) opt.String {
return opt.NewNotEmptyString(os.Getenv(key)) if value, ok := os.LookupEnv(key); ok {
return opt.NewNotEmptyString(value)
}
return opt.NullString
} }
// Env returns a map of environment variables. // Env returns a map of environment variables.

Loading…
Cancel
Save