Skip to content

Commit

Permalink
pass --settings and --pythonpath to complete on zshell, #68
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Nov 21, 2024
1 parent efc5156 commit cf17787
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
25 changes: 24 additions & 1 deletion django_typer/scripts/zsh.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
#compdef %(prog_name)s

%(complete_func)s() {
eval $(env _TYPER_COMPLETE_ARGS="${words[1,$CURRENT]}" %(autocomplete_var)s=complete_zsh ${words[0,1]} {{ django_command }} {{ color }} complete)

# Extract --settings and --pythonpath options and their values if present becase
# we need to pass these to the complete script - they may be necessary to find the command!
local settings_option=""
local pythonpath_option=""

for ((i=1; i<$CURRENT; i++)); do
case "${words[i]}" in
--settings)
# Only pass settings to completion script if we're sure it's value does not itself need completion!
if (( i + 1 < CURRENT )) && [[ -n "${words[i+1]}" ]] && [[ "${words[i+1]}" != --* ]]; then
settings_option="--settings=${words[i+1]}"
fi
;;
--pythonpath)
# Only pass pythonpath to completion script if we're sure it's value does not itself need completion!
if (( i + 1 < CURRENT )) && [[ -n "${words[i+1]}" ]] && [[ "${words[i+1]}" != --* ]]; then
pythonpath_option="--pythonpath=${words[i+1]}"
fi
;;
esac
done

eval $(env _TYPER_COMPLETE_ARGS="${words[1,$CURRENT]}" %(autocomplete_var)s=complete_zsh ${words[0,1]} {{ django_command }} ${settings_option:+${settings_option}} ${pythonpath_option:+${pythonpath_option}} {{ color }} complete)
}

compdef %(complete_func)s %(prog_name)s
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ classifiers = [
[tool.poetry.dependencies]
python = ">=3.9,<4.0"
Django = ">=3.2,<6.0"
click = "^8.1.0"
click = ">=8.1.0"

# typer's release history is full of breaking changes for minor versions
# given the reliance on some of its private internals we peg the typer
Expand Down Expand Up @@ -101,7 +101,7 @@ ruff = ">=0.4.1"
graphviz = ">=0.20.3"
sphinx-tabs = ">=3.4.5"
furo = ">=2024.7.18"
pluggy = "^1.5.0"
pluggy = ">=1.5.0"

[tool.poetry.extras]
rich = ["rich"]
Expand Down

0 comments on commit cf17787

Please sign in to comment.