Skip to content

Commit d6c78de

Browse files
Skye Sossshanduur
authored andcommitted
feat: support TALOS_HOME env var
Use TALOS_HOME for state instead of ~/.talos, when defined. Signed-off-by: Skye Soss <skye@soss.website> (cherry picked from commit 4f62186)
1 parent 4040e08 commit d6c78de

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

cmd/talosctl/cmd/completion.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ Note for zsh users: [1] zsh completions are only supported in versions of zsh >=
3838
## Load the talosctl completion code for bash into the current shell
3939
source <(talosctl completion bash)
4040
## Write bash completion code to a file and source if from .bash_profile
41-
talosctl completion bash > ~/.talos/completion.bash.inc
42-
printf "
41+
talosctl completion bash > "${TALOS_HOME:-$HOME/.talos}/completion.bash.inc"
42+
printf '
4343
# talosctl shell completion
44-
source '$HOME/.talos/completion.bash.inc'
45-
" >> $HOME/.bash_profile
44+
source "${TALOS_HOME:-$HOME/.talos}/completion.bash.inc"
45+
' >> $HOME/.bash_profile
4646
source $HOME/.bash_profile
4747
# Load the talosctl completion code for fish[1] into the current shell
4848
talosctl completion fish | source

pkg/machinery/client/config/path.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ type Path struct {
2020
WriteAllowed bool
2121
}
2222

23-
// GetTalosDirectory returns path to Talos directory (~/.talos).
23+
// GetTalosDirectory returns path to Talos directory ($TALOS_HOME or ~/.talos).
2424
func GetTalosDirectory() (string, error) {
25+
if path, ok := os.LookupEnv(constants.TalosHomeEnvVar); ok && filepath.IsAbs(path) {
26+
return path, nil
27+
}
28+
2529
home, err := os.UserHomeDir()
2630
if err != nil {
2731
return "", err

pkg/machinery/constants/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ const (
602602
// TalosConfigEnvVar is the environment variable for setting the Talos configuration file path.
603603
TalosConfigEnvVar = "TALOSCONFIG"
604604

605+
// TalosHomeEnvVar is the environment variable for setting the Talos state directory file path.
606+
TalosHomeEnvVar = "TALOS_HOME"
607+
605608
// APISocketPath is the path to file socket of apid.
606609
APISocketPath = SystemRunPath + "/apid/apid.sock"
607610

website/content/v1.12/reference/cli.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,11 @@ talosctl completion SHELL [flags]
432432
## Load the talosctl completion code for bash into the current shell
433433
source <(talosctl completion bash)
434434
## Write bash completion code to a file and source if from .bash_profile
435-
talosctl completion bash > ~/.talos/completion.bash.inc
436-
printf "
435+
talosctl completion bash > "${TALOS_HOME:-$HOME/.talos}/completion.bash.inc"
436+
printf '
437437
# talosctl shell completion
438-
source '$HOME/.talos/completion.bash.inc'
439-
" >> $HOME/.bash_profile
438+
source "${TALOS_HOME:-$HOME/.talos}/completion.bash.inc"
439+
' >> $HOME/.bash_profile
440440
source $HOME/.bash_profile
441441
# Load the talosctl completion code for fish[1] into the current shell
442442
talosctl completion fish | source

0 commit comments

Comments
 (0)