Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shell completion for nf-core tools commands #2070

Merged
merged 6 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ pip install --upgrade nf-core

Please refer to the respective documentation for further details to manage packages, as for example [conda](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-pkgs.html#updating-packages) or [pip](https://packaging.python.org/en/latest/tutorials/installing-packages/#upgrading-packages).

### Activate shell completions for nf-core/tools

Auto-completion for the `nf-core` command is available for bash, zsh and fish. To activate it, add the following lines to the respective shell config files.
shell | shell config file | command
--- | --- | ---
bash | ~/.bashrc | `eval "$(_NF_CORE_COMPLETE=bash_source nf-core)"`
Zsh | ~/.zshrc | `eval "$(_NF_CORE_COMPLETE=zsh_source nf-core)"`
fish | ~/.config/fish/completions/nf-core.fish | `eval (env _NF_CORE_COMPLETE=fish_source nf-core)`

After a restart of the shell session you should have auto-completion for the `nf-core` command and all its sub-commands and options.

> **NB:** The added line will run the command `nf-core` (which will also slow down startup time of your shell). You should therefore either have the nf-core/tools installed globally.
> You can also wrap it inside `if type nf-core > /dev/null; then ` \<YOUR EVAL CODE LINE\> `fi` for bash and zsh or `if command -v nf-core &> /dev/null eval (env _NF_CORE_COMPLETE=fish_source nf-core) end` for fish. You need to then source the config in your environment for the completions to be activated.

> **NB:** If you see the error `command not found compdef` , be sure that your config file contains the line `autoload -Uz compinit && compinit` before the eval line.

## Listing pipelines

The command `nf-core list` shows all available nf-core pipelines along with their latest version, when that was published and how recently the pipeline code was pulled to your local system (if at all).
Expand Down
43 changes: 22 additions & 21 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,28 @@


def run_nf_core():
# Print nf-core header
stderr.print(f"\n[green]{' ' * 42},--.[grey39]/[green],-.", highlight=False)
stderr.print("[blue] ___ __ __ __ ___ [green]/,-._.--~\\", highlight=False)
stderr.print(r"[blue] |\ | |__ __ / ` / \ |__) |__ [yellow] } {", highlight=False)
stderr.print(r"[blue] | \| | \__, \__/ | \ |___ [green]\`-._,-`-,", highlight=False)
stderr.print("[green] `._,._,'\n", highlight=False)
stderr.print(
f"[grey39] nf-core/tools version {nf_core.__version__} - [link=https://nf-co.re]https://nf-co.re[/]",
highlight=False,
)
try:
is_outdated, _, remote_vers = nf_core.utils.check_if_outdated()
if is_outdated:
stderr.print(
f"[bold bright_yellow] There is a new version of nf-core/tools available! ({remote_vers})",
highlight=False,
)
except Exception as e:
log.debug(f"Could not check latest version: {e}")
stderr.print("\n")

# print nf-core header if environment variable is not set
if os.environ.get("_NF_CORE_COMPLETE") is None:
# Print nf-core header
stderr.print(f"\n[green]{' ' * 42},--.[grey39]/[green],-.", highlight=False)
stderr.print("[blue] ___ __ __ __ ___ [green]/,-._.--~\\", highlight=False)
stderr.print(r"[blue] |\ | |__ __ / ` / \ |__) |__ [yellow] } {", highlight=False)
stderr.print(r"[blue] | \| | \__, \__/ | \ |___ [green]\`-._,-`-,", highlight=False)
stderr.print("[green] `._,._,'\n", highlight=False)
stderr.print(
f"[grey39] nf-core/tools version {nf_core.__version__} - [link=https://nf-co.re]https://nf-co.re[/]",
highlight=False,
)
try:
is_outdated, _, remote_vers = nf_core.utils.check_if_outdated()
if is_outdated:
stderr.print(
f"[bold bright_yellow] There is a new version of nf-core/tools available! ({remote_vers})",
highlight=False,
)
except Exception as e:
log.debug(f"Could not check latest version: {e}")
stderr.print("\n")
# Launch the click cli
nf_core_cli(auto_envvar_prefix="NFCORE")

Expand Down