github.com/jonsyu1/godel@v0.0.0-20171017211503-64567a0cf169/docs/Enable-command-completion.md (about)

     1  gödel supports command completion on Bash and Zsh using the functionality provided by the
     2  [`pkg/palantir/cli` package](https://github.com/palantir/pkg/tree/develop/cli). Because gödel is almost always invoked
     3  using the wrapper script `./godelw`, it is recommended that completion be set up on `godelw`.
     4  
     5  # Bash
     6  
     7  1. Run `./godelw _completion --prog=godelw --alias ./godelw --bash` in a project that has `godel`.
     8  2. This command will output text to the terminal:
     9  ```
    10  _completion_######() {
    11  ...
    12  }
    13  compdef _completion_###### "godelw"
    14  # Run 'eval "$(/<path...>/.godel/dists/godel-<version>/bin/darwin-amd64/godel --wrapper /<path...>/godelw _completion --prog=godelw --alias ./godelw --bash)"' to apply
    15  ```
    16  3. Copy all of the text except for the comment (starting at `_completion_######() {` and ending at `compdef _completion_###### "godelw"`).
    17  4. Add the command to the shell's startup environment (`~/.bash_profile` or equivalent):
    18  ```
    19  _completion_######() {
    20  ...
    21  }
    22  compdef _completion_###### "godelw"
    23  ```
    24  
    25  # Zsh
    26  
    27  1. Run `./godelw _completion --prog=godelw --alias ./godelw --zsh` in a project that has the `godel` version that should
    28     be used for completion.
    29  2. This command will output text to the terminal:
    30  ```
    31  _completion_######() {
    32  ...
    33  }
    34  compdef _completion_###### "godelw"
    35  # Run 'eval "$(/<path...>/.godel/dists/godel-<version>/bin/darwin-amd64/godel --wrapper /<path...>/godelw _completion --prog=godelw --alias ./godelw --zsh)"' to apply
    36  ```
    37  3. Copy all of the text except for the comment (starting at `_completion_######() {` and ending at `compdef _completion_###### "godelw"`).
    38  4. Add the command to the shell's startup environment (`~/.zshrc` or equivalent):
    39  ```
    40  _completion_######() {
    41  ...
    42  }
    43  compdef _completion_###### "godelw"
    44  ```
    45  
    46  # Update Completion
    47  The steps above should continue to work as long as the content of the completion script itself (or the way it is
    48  invoked) does not change. Such a change should not be common, and if it does occur it will be noted in the release
    49  notes. If the completion script does change, it can be updated by repeating the steps above using the new version of
    50  `godelw`.
    51  
    52  # Explanation
    53  The `--prog` flag determines the command for which completion should be performed. Because completion should be
    54  performed on `./godelw`, the value of `--prog` is set to `godelw` (Bash and Zsh both handle command completion on
    55  relative path invocation automatically). The `--alias` flag specifies the program that should be invoked to generate the
    56  completion. Because it is expected that completion will be performed in a directory that contains `./godelw`, the value
    57  is specified as `./godelw`. This ensures that command completion is provided by the proper version of gödel that is
    58  being used (which may be important in environments in which multiple versions of gödel exist).
    59  
    60  This setup assumes that `godelw` will always be invoked using `./godelw`. If this is not the case and completion is
    61  desired in those scenarios as well, the value provided go `--alias` can be changed to be the absolute path to a `godel`
    62  executable, which will make it such that the specified executable always generates the completions for the command. This
    63  has the down-side of tying all completions of `./godelw` to a specific version, but does allow for completion on
    64  invocations from any location.