mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
kitten run-shell: Forward KSI env var for no-rc
This is useless, since if you are doing manual shell integration anyway there is no point in running via the run-shell kitten. But, let's keep the pedants at bay. Fixes #7809
This commit is contained in:
@@ -135,33 +135,51 @@ func get_shell_name(argv0 string) (ans string) {
|
|||||||
return strings.TrimPrefix(ans, "-")
|
return strings.TrimPrefix(ans, "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
func rc_modification_allowed(ksi string) bool {
|
func rc_modification_allowed(ksi string) (allowed bool, set_ksi_env_var bool) {
|
||||||
|
allowed = ksi != ""
|
||||||
|
set_ksi_env_var = true
|
||||||
for _, x := range strings.Split(ksi, " ") {
|
for _, x := range strings.Split(ksi, " ") {
|
||||||
switch x {
|
switch x {
|
||||||
case "disabled", "no-rc":
|
case "disabled":
|
||||||
return false
|
allowed = false
|
||||||
|
set_ksi_env_var = false
|
||||||
|
break
|
||||||
|
case "no-rc":
|
||||||
|
allowed = false
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ksi != ""
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func copy_os_env_as_dict() map[string]string {
|
||||||
|
oenv := os.Environ()
|
||||||
|
env := make(map[string]string, len(oenv))
|
||||||
|
for _, x := range oenv {
|
||||||
|
if k, v, found := strings.Cut(x, "="); found {
|
||||||
|
env[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunShell(shell_cmd []string, shell_integration_env_var_val, cwd string) (err error) {
|
func RunShell(shell_cmd []string, shell_integration_env_var_val, cwd string) (err error) {
|
||||||
shell_name := get_shell_name(shell_cmd[0])
|
shell_name := get_shell_name(shell_cmd[0])
|
||||||
var shell_env map[string]string
|
var shell_env map[string]string
|
||||||
if rc_modification_allowed(shell_integration_env_var_val) && shell_integration.IsSupportedShell(shell_name) {
|
if shell_integration.IsSupportedShell(shell_name) {
|
||||||
oenv := os.Environ()
|
rc_mod_allowed, set_ksi_env_var := rc_modification_allowed(shell_integration_env_var_val)
|
||||||
env := make(map[string]string, len(oenv))
|
if rc_mod_allowed {
|
||||||
for _, x := range oenv {
|
// KITTY_SHELL_INTEGRATION is always set by this function
|
||||||
if k, v, found := strings.Cut(x, "="); found {
|
argv, env, err := shell_integration.Setup(shell_name, shell_integration_env_var_val, shell_cmd, copy_os_env_as_dict())
|
||||||
env[k] = v
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
shell_cmd = argv
|
||||||
|
shell_env = env
|
||||||
|
} else if set_ksi_env_var {
|
||||||
|
shell_env = copy_os_env_as_dict()
|
||||||
|
shell_env["KITTY_SHELL_INTEGRATION"] = shell_integration_env_var_val
|
||||||
}
|
}
|
||||||
argv, env, err := shell_integration.Setup(shell_name, shell_integration_env_var_val, shell_cmd, env)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
shell_cmd = argv
|
|
||||||
shell_env = env
|
|
||||||
}
|
}
|
||||||
exe := shell_cmd[0]
|
exe := shell_cmd[0]
|
||||||
if runtime.GOOS == "darwin" && (os.Getenv("KITTY_RUNNING_SHELL_INTEGRATION_TEST") != "1" || os.Getenv("KITTY_RUNNING_BASH_INTEGRATION_TEST") != "") {
|
if runtime.GOOS == "darwin" && (os.Getenv("KITTY_RUNNING_SHELL_INTEGRATION_TEST") != "1" || os.Getenv("KITTY_RUNNING_BASH_INTEGRATION_TEST") != "") {
|
||||||
|
|||||||
Reference in New Issue
Block a user