Skip to content

Commit

Permalink
Patch click Bash completion generation
Browse files Browse the repository at this point in the history
Fix for #10
  • Loading branch information
superatomic committed Aug 7, 2023
1 parent f389033 commit ecbf2be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/tldr_man/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
from click_help_colors import HelpColorsCommand

from tldr_man import pages
from tldr_man.shell_completion import page_shell_complete, language_shell_complete
from tldr_man.shell_completion import page_shell_complete, language_shell_complete, patch_bash_completion
from tldr_man.languages import get_locales
from tldr_man.platforms import get_page_sections, TLDR_PLATFORMS
from tldr_man.util import unique, mkstemp_path


patch_bash_completion() # See issue #10


def standalone_subcommand(func):
"""Function decorator to reduce boilerplate code at the start and end of all subcommand callback functions."""
@wraps(func)
Expand Down
11 changes: 10 additions & 1 deletion src/tldr_man/shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Rich shell completions for the client."""

from click import Context, Parameter
from click.shell_completion import CompletionItem
from click.shell_completion import CompletionItem, BashComplete

from tldr_man.pages import CACHE_DIR, get_dir_search_order
from tldr_man.languages import get_locales, all_language_codes
Expand Down Expand Up @@ -44,3 +44,12 @@ def language_shell_complete(_ctx: Context, _param: Parameter, _incomplete: str)
if not CACHE_DIR.exists():
return []
return [CompletionItem(code) for code in all_language_codes()]


def patch_bash_completion():
"""
Patches click Bash shell completion generation to not raise an error on generating for Bash versions older than 4.4.
Fixes <https://github.com/superatomic/tldr-man/issues/10>, <https://github.com/pallets/click/issues/2574>.
"""
BashComplete._check_version = lambda: None

0 comments on commit ecbf2be

Please sign in to comment.