Skip to content

Commit

Permalink
Fixed #19523 -- Improved performance of Django's bash completion
Browse files Browse the repository at this point in the history
Previous version took about 150ms to source, even on a warm cache,
primarily because it forks+execs /usr/bin/basename 44 times.
This patch makes it faster by a factor of 5 (and I imagine that a little
more thought would reduce the time to effectively zero).
  • Loading branch information
andersk authored and claudep committed Jan 22, 2013
1 parent cc4de61 commit e535da6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions extras/django_bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ complete -F _django_completion -o default django-admin.py manage.py django-admin
_python_django_completion()
{
if [[ ${COMP_CWORD} -ge 2 ]]; then
PYTHON_EXE=$( basename -- ${COMP_WORDS[0]} )
PYTHON_EXE=${COMP_WORDS[0]##*/}
echo $PYTHON_EXE | egrep "python([2-9]\.[0-9])?" >/dev/null 2>&1
if [[ $? == 0 ]]; then
PYTHON_SCRIPT=$( basename -- ${COMP_WORDS[1]} )
PYTHON_SCRIPT=${COMP_WORDS[1]##*/}
echo $PYTHON_SCRIPT | egrep "manage\.py|django-admin(\.py)?" >/dev/null 2>&1
if [[ $? == 0 ]]; then
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]:1}" \
Expand All @@ -61,7 +61,7 @@ unset pythons
if command -v whereis &>/dev/null; then
python_interpreters=$(whereis python | cut -d " " -f 2-)
for python in $python_interpreters; do
pythons="${pythons} $(basename -- $python)"
pythons="${pythons} ${python##*/}"
done
pythons=$(echo $pythons | tr " " "\n" | sort -u | tr "\n" " ")
else
Expand Down

0 comments on commit e535da6

Please sign in to comment.