Skip to content

Commit

Permalink
pass --settings and --pythonpath on bash completions #68
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Nov 21, 2024
1 parent cf17787 commit 3b482d5
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion django_typer/scripts/bash.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
%(complete_func)s() {
local IFS=$'
'
# 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=0; i<COMP_CWORD; i++)); do
case "${COMP_WORDS[i]}" in
--settings)
# Ensure the next word exists and is not another flag
if [[ $((i + 1)) -lt $COMP_CWORD ]]; then
settings_option="--settings=${COMP_WORDS[i+1]}"
fi
;;
--pythonpath)
# Ensure the next word exists and is not another flag
if [[ $((i + 1)) -lt $COMP_CWORD ]]; then
pythonpath_option="--pythonpath=${COMP_WORDS[i+1]}"
fi
;;
esac
done

COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
%(autocomplete_var)s=complete_bash $1 {{ django_command }} {{ color }} complete ) )
%(autocomplete_var)s=complete_bash $1 {{ django_command }} ${settings_option:+${settings_option}} ${pythonpath_option:+${pythonpath_option}} {{ color }} complete ) )
return 0
}

Expand Down

0 comments on commit 3b482d5

Please sign in to comment.