diff --git a/README.md b/README.md index 219e01a..b7bcc39 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ nostromo manifest show ``` ### Bash Completion -nostromo provides completion scripts to allow tab completion. You can get this by adding this to your shell init file: +nostromo provides completion scripts to allow tab completion. This is added by default when running `nostromo init` or by adding this to your shell init file: ```sh eval "$(nostromo completion)" # for bash eval "$(nostromo completion --zsh)" # for zsh diff --git a/cmd/completion.go b/cmd/completion.go index 9d16945..c22aebe 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -20,7 +20,8 @@ var completionCmd = &cobra.Command{ eval "$(nostromo completion)" # for bash eval "$(nostromo completion --zsh)" # for zsh -To configure your shell to load completions for each session add to your init files +To configure your shell to load completions for each session add to your init files. +Note that "nostromo init" will add this automatically. # In ~/.bashrc or ~/.bash_profile eval "$(nostromo completion)" diff --git a/shell/startupfile.go b/shell/startupfile.go index fda600a..85cdb61 100644 --- a/shell/startupfile.go +++ b/shell/startupfile.go @@ -15,6 +15,7 @@ import ( const ( beginBlockComment = "# nostromo [section begin]" endBlockComment = "# nostromo [section end]" + sourceCompletion = "eval \"$(nostromo completion%s)\"" ) var ( @@ -184,5 +185,9 @@ func (s *startupFile) makeAliasBlock() string { alias := strings.TrimSpace(fmt.Sprintf("alias %s='nostromo run %s \"$*\"'", a, a)) aliases = append(aliases, alias) } - return fmt.Sprintf("\n%s\n%s\n%s\n", beginBlockComment, strings.Join(aliases, "\n"), endBlockComment) + zsh := "" + if Which() == Zsh { + zsh = "--zsh" + } + return fmt.Sprintf("\n%s\n%s\n\n%s\n%s\n", beginBlockComment, fmt.Sprintf(sourceCompletion, zsh), strings.Join(aliases, "\n"), endBlockComment) }