Skip to content

Add ability to write completions to the file #192

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 docs/use.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Below are various examples of enabling `shtab`'s own tab completion scripts.
```sh
mkdir -p ~/.zsh/completions
fpath=($fpath ~/.zsh/completions) # must be before `compinit` lines
shtab --shell=zsh shtab.main.get_main_parser > ~/.zsh/completions/_shtab
shtab --shell=zsh shtab.main.get_main_parser -o ~/.zsh/completions/_shtab
```

=== "tcsh"
Expand Down
4 changes: 3 additions & 1 deletion shtab/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def get_main_parser():
parser.add_argument("parser", help="importable parser (or function returning parser)")
parser.add_argument("--version", action="version", version="%(prog)s " + __version__)
parser.add_argument("-s", "--shell", default=SUPPORTED_SHELLS[0], choices=SUPPORTED_SHELLS)
parser.add_argument("-o", "--output", help="write output to file instead of stdout",
type=argparse.FileType("w"), default=sys.stdout)
parser.add_argument("--prefix", help="prepended to generated functions to avoid clashes")
parser.add_argument("--preamble", help="prepended to generated script")
parser.add_argument("--prog", help="custom program name (overrides `parser.prog`)")
Expand Down Expand Up @@ -54,4 +56,4 @@ def main(argv=None):
other_parser.prog = args.prog
print(
complete(other_parser, shell=args.shell, root_prefix=args.prefix
or args.parser.split(".", 1)[0], preamble=args.preamble))
or args.parser.split(".", 1)[0], preamble=args.preamble), file=args.output)