Ticket #19523: patch

File patch, 1.4 KB (added by Raphaël Hertzog, 12 years ago)

Patch to get rid of basename in Django's bash completion

  • etc/bash_completion.d/django_bash_completion

    /etc/bash_completion.d/django_bash_completion takes about 150ms to source, 
    even on a warm cache, primarily because it forks+execs /usr/bin/basename 
    44 times.  This significantly slows down interactive logins.
    
    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).
    
     
    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}" \
     
    6161if 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" " ")
    6767else
Back to Top