Skip to content
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
2 changes: 1 addition & 1 deletion oks_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def version():
print(importlib.metadata.version(__package__))

@cli.command("install-completion", help="Install shell completion scripts.")
@click.option('--type', required=True, help="Shell, supported [bash,zsh]")
@click.option('--type', help="Shell, supported [bash,zsh]")
def install_completion(type):
"""Install shell completion scripts for the CLI."""
install_completions(type)
Expand Down
11 changes: 11 additions & 0 deletions oks_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,17 @@ def find_shell_profile(home, shell_type):
def install_completions(shell_type):
"""Install shell completion scripts for bash or zsh."""
home = os.path.expanduser('~')

if shell_type is None:
try:
shell_pid = os.getppid()
result = subprocess.run(['ps', '-p', str(shell_pid), '-o', 'comm='], capture_output=True, text=True)
shell_name = result.stdout.strip()

shell_type = os.path.basename(shell_name).lstrip('-')
except subprocess.SubProcessError:
click.echo("Failed to determine shell type, please specify it by --type")

completion_dir = os.path.join(home, ".oks_cli", "completions")
os.makedirs(completion_dir, exist_ok=True)

Expand Down
24 changes: 0 additions & 24 deletions tests/test_install_completion.py

This file was deleted.