Skip to content

Commit e535da6

Browse files
anderskclaudep
authored andcommitted
Fixed django#19523 -- Improved performance of Django's bash completion
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).
1 parent cc4de61 commit e535da6

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

extras/django_bash_completion

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ complete -F _django_completion -o default django-admin.py manage.py django-admin
4242
_python_django_completion()
4343
{
4444
if [[ ${COMP_CWORD} -ge 2 ]]; then
45-
PYTHON_EXE=$( basename -- ${COMP_WORDS[0]} )
45+
PYTHON_EXE=${COMP_WORDS[0]##*/}
4646
echo $PYTHON_EXE | egrep "python([2-9]\.[0-9])?" >/dev/null 2>&1
4747
if [[ $? == 0 ]]; then
48-
PYTHON_SCRIPT=$( basename -- ${COMP_WORDS[1]} )
48+
PYTHON_SCRIPT=${COMP_WORDS[1]##*/}
4949
echo $PYTHON_SCRIPT | egrep "manage\.py|django-admin(\.py)?" >/dev/null 2>&1
5050
if [[ $? == 0 ]]; then
5151
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]:1}" \
@@ -61,7 +61,7 @@ unset pythons
6161
if command -v whereis &>/dev/null; then
6262
python_interpreters=$(whereis python | cut -d " " -f 2-)
6363
for python in $python_interpreters; do
64-
pythons="${pythons} $(basename -- $python)"
64+
pythons="${pythons} ${python##*/}"
6565
done
6666
pythons=$(echo $pythons | tr " " "\n" | sort -u | tr "\n" " ")
6767
else

0 commit comments

Comments
 (0)