Skip to content

Commit

Permalink
Source completions automatically on nostromo init
Browse files Browse the repository at this point in the history
  • Loading branch information
saheljalal committed Sep 7, 2019
1 parent c6ceddd commit b3cbe5f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
7 changes: 6 additions & 1 deletion shell/startupfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
const (
beginBlockComment = "# nostromo [section begin]"
endBlockComment = "# nostromo [section end]"
sourceCompletion = "eval \"$(nostromo completion%s)\""
)

var (
Expand Down Expand Up @@ -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)
}

0 comments on commit b3cbe5f

Please sign in to comment.