photon complete <shell> prints a completion script for zsh, bash, fish, or
PowerShell. Load the script in your shell, and Tab completes photon’s commands:
photon pro completes to photon project, and photon project cr to
photon project create. The steps on this page were run with Photon CLI 3.0.2.
No install method turns completion on. The npm package has no install scripts,
and the standalone installers only add photon’s folder to your PATH. Add the
lines for your shell yourself, then open a new terminal.
zsh
Add these lines to~/.zshrc:
~/.zshrc
~/.zshrc already runs compinit, add only the second line, after it. When
compinit hasn’t run before the source line, a new terminal prints
command not found: compdef, and Tab doesn’t complete photon’s commands.
To save the script to a file instead, write it to a folder in zsh’s fpath,
and add that folder to fpath before compinit runs:
~/.zshrc
source
line makes a new script in every new terminal, so it doesn’t need this.
bash
Add this line to~/.bashrc:
~/.bashrc
~/.bashrc loads it. Without it, Tab prints
bash: _get_comp_words_by_ref: command not found.
bash reads ~/.bashrc when a terminal starts a non-login shell. A login shell
reads the first of ~/.bash_profile, ~/.bash_login, and ~/.profile that
exists instead. If your terminal starts login shells, have that file source
~/.bashrc.
To save the script to a file instead, write it to bash-completion’s folder for
your own completions. bash-completion loads it the first time you press Tab
after photon:
$BASH_COMPLETION_USER_DIR/completions when you set
BASH_COMPLETION_USER_DIR. Otherwise, when you set XDG_DATA_HOME, it’s
$XDG_DATA_HOME/bash-completion/completions.
fish
Save the script to fish’s completions folder. fish loads it the first time you press Tab afterphoton:
$XDG_CONFIG_HOME/fish/completions when you set
XDG_CONFIG_HOME.
PowerShell
Add this line to your PowerShell profile, the file$PROFILE names:
$PROFILE
The pho command
The npm package also installs photon aspho. The scripts complete the
photon command only, so pho pro followed by Tab completes nothing.
When the script isn’t saved
Thesource lines for zsh, bash, and PowerShell save no file. The rest of this
section is about saved scripts.
The shell opens the file before photon runs. When the folder doesn’t exist, the
shell reports No such file or directory and photon doesn’t run, so create the
folder first, as the commands above do.
On a full disk, Photon CLI 3.0.2 doesn’t always report that the script wasn’t
saved:
After a full disk, free some space and save the script again.
photon complete knows zsh, bash, fish, and powershell. For any other shell
name, such as a misspelled fsh, Photon CLI 3.0.2 prints nothing, exits with
code 0, and leaves an empty file.
To check a saved script, compare it with a new one. This prints saved only
when the file holds the whole script, so an empty or cut-off file prints
nothing: