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 completions by shtab #131

Merged
merged 1 commit into from
Nov 20, 2022
Merged

Add shell completions by shtab #131

merged 1 commit into from
Nov 20, 2022

Conversation

Freed-Wu
Copy link
Contributor

gpustat --print-completion bash | sudo tee /usr/share/bash-completion/completions/gpustat
gpustat --print-completion tcsh | sudo tee /etc/profile.d/gpustat.completion.csh
gpustat --print-completion zsh | sudo tee /usr/share/zsh/site-functions/_gpustat
% gpustat -i <TAB>
float
% gpustat -i -<TAB>
option
-a                   Display all gpu properties above
...

@Freed-Wu Freed-Wu mentioned this pull request Aug 28, 2022
@wookayin wookayin self-assigned this Sep 4, 2022
@wookayin wookayin added this to the 1.1 milestone Sep 4, 2022
@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Sep 13, 2022

I fixed the conflict.

Copy link
Owner

@wookayin wookayin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think the feature works nice but there are some corner cases.

gpustat/cli.py Outdated Show resolved Hide resolved
gpustat/cli.py Show resolved Hide resolved
@wookayin
Copy link
Owner

Another corner case: if we execute gpustat as python -m gpustat, the completion file will start with #compdef __main__.py instead of #compdef gpustat. It might be an issue of shtab itself, but do you have any idea about how we can force the program name to be gpustat?

@Freed-Wu
Copy link
Contributor Author

Another corner case: if we execute gpustat as python -m gpustat, the completion file will start with #compdef __main__.py instead of #compdef gpustat. It might be an issue of shtab itself, but do you have any idea about how we can force the program name to be gpustat?

Fixed. 😄

    parser = argparse.ArgumentParser(prog='gpustat')

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Sep 14, 2022

Any other problems? It still displays 1 review requesting changes.

Copy link
Owner

@wookayin wookayin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you. I will merge it soon and write docs for this.

@wookayin wookayin changed the title Add completes for shells by shtab Add shell completions by shtab Oct 15, 2022
Example:

gpustat --print-completion bash | sudo tee /usr/share/bash-completion/completions/gpustat
gpustat --print-completion tcsh | sudo tee /etc/profile.d/gpustat.completion.csh
gpustat --print-completion zsh | sudo tee /usr/share/zsh/site-functions/_gpustat
@wookayin
Copy link
Owner

I have rebased your commit due to conflicts. Let me add some minor touches.

@Freed-Wu Freed-Wu mentioned this pull request Nov 15, 2022
@Freed-Wu
Copy link
Contributor Author

Good. When can it be accepted?

@wookayin wookayin merged commit e639e31 into wookayin:master Nov 20, 2022
@wookayin
Copy link
Owner

@Freed-Wu Thank you for your contribution!

@wookayin
Copy link
Owner

wookayin commented Nov 20, 2022

For those who do not have root privileges, you can do like

$ pip install gpustat[completion]  # or do pip install shtab

$ gpustat --print-completion zsh > ~/.local/share/zsh/site-functions/_gpustat
$ gpustat --print-completion bash > ~/.bash_completion.d/gpustat

and add $HOME/.local/share/zsh/site-functions to $fpath (for zsh), or source the completion file (for bash).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants