Description
I was wondering if we could change the session and client environment variables once Kakoune has started.
Having a way to access and change them could be nice to
- set and update Kakoune environment without having to restart Kakoune in a new shell,
- fine-tune tools to Kakoune client-server model.
Kakoune already does some path manipulation (#4433) by prefixing the currently running kak
binary in PATH
, and it could be a good way to expose shell scripts in Kakoune plugins (#4425).
The proposal is to add
set-environment [session|client] <name> <value>
,unset-environment [session|client] <name>
- and
%env{name}
expansion.
Here is a plugin example with the following files:
bin/:e -> :edit
bin/:edit
bin/:fzf
rc/connect.kak
rc/connect.kak
# Exposes bin in PATH.
set-environment session PATH "%sh{dirname ""$kak_source""}/../bin:%env{PATH}"
# Exposes the session and client environment variables,
# so :edit command has the necessary information to open files in a client/session.
#
# Note: needs a hook to handle session rename.
set-environment session kak_session %val{session}
hook global ClientCreate '.+' %{
set-environment client kak_client %val{client}
}
bin/:edit
#!/bin/sh
export file
for file do
echo evaluate-commands -client %env{kak_client} -- edit -- %env{file} |
kak -p "$kak_session"
# Note: We use the %env{name} expansion, so we don’t have to “kak quote” values; passing values is straightforward.
# We expose the `file` environment variable to the `kak` binary, and `kak_client` is already exported.
#
# Having `kak -p session_name -args -- 1 2 3` could be nice to pass values in %arg{@} expansion.
done
bin/:fzf
find "$@" -type f | fzf | xargs :edit --
In Kakoune, we can now do:
terminal :fzf
To tune FZF_DEFAULT_OPTS
in a client:
set-environment client FZF_DEFAULT_OPTS '--height=40% --layout=reverse --border'
# Similar syntax to `buffer=name` for `set-option`.
set-environment client=client2 FZF_DEFAULT_OPTS '--height=40% --layout=reverse --border'
Assuming we have a Kakoune command to spawn a program, it still convenient for interactive usage without writing a wrapper for every windowing system.
spawn alacritty -e :fzf
spawn tmux split :fzf path/to/dir
Since we have :edit
and :fzf
in PATH
, we can open a terminal from Kakoune and use the commands in the shell.
spawn alacritty
then in the terminal:
:e docs/*.txt
:fzf
Activity