()
| 1433 | help="Install shell completions for marimo. Supports bash, zsh, and fish." |
| 1434 | ) |
| 1435 | def shell_completion() -> None: |
| 1436 | shell = os.environ.get("SHELL", "") |
| 1437 | if not shell: |
| 1438 | raise MarimoCLIRuntimeError( |
| 1439 | "Could not determine shell. Please set $SHELL environment variable.", |
| 1440 | ) |
| 1441 | |
| 1442 | # in case we're on a windows system, use .stem to remove extension |
| 1443 | shell_name = Path(shell).stem |
| 1444 | |
| 1445 | # N.B. change the help message above when changing supported shells |
| 1446 | commands = { |
| 1447 | "bash": ( |
| 1448 | 'eval "$(_MARIMO_COMPLETE=bash_source marimo)"', |
| 1449 | ".bashrc", |
| 1450 | ), |
| 1451 | "zsh": ( |
| 1452 | 'eval "$(_MARIMO_COMPLETE=zsh_source marimo)"', |
| 1453 | ".zshrc", |
| 1454 | ), |
| 1455 | "fish": ( |
| 1456 | "_MARIMO_COMPLETE=fish_source marimo | source", |
| 1457 | ".config/fish/completions/marimo.fish", |
| 1458 | ), |
| 1459 | } |
| 1460 | |
| 1461 | if shell_name not in commands: |
| 1462 | supported = ", ".join(commands.keys()) |
| 1463 | raise MarimoCLIRuntimeError( |
| 1464 | f"Unsupported shell: {shell_name} (from $SHELL). Supported shells: {supported}", |
| 1465 | ) |
| 1466 | |
| 1467 | cmd, rc_file = commands[shell_name] |
| 1468 | click.secho("Run this command to enable completions:", fg="green") |
| 1469 | click.secho(f"\n echo '{cmd}' >> ~/{rc_file}\n", fg="yellow") |
| 1470 | click.secho( |
| 1471 | "\nThen restart your shell or run 'source ~/" |
| 1472 | + rc_file |
| 1473 | + "' to enable completions", |
| 1474 | fg="green", |
| 1475 | ) |
| 1476 | |
| 1477 | |
| 1478 | @main.command(help="""Check and format marimo files.""") |
nothing calls this directly
no test coverage detected
searching dependent graphs…