/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).
|
|
|
42 | 42 | _python_django_completion() |
43 | 43 | { |
44 | 44 | if [[ ${COMP_CWORD} -ge 2 ]]; then |
45 | | PYTHON_EXE=$( basename -- ${COMP_WORDS[0]} ) |
| 45 | PYTHON_EXE=${COMP_WORDS[0]##*/} |
46 | 46 | echo $PYTHON_EXE | egrep "python([2-9]\.[0-9])?" >/dev/null 2>&1 |
47 | 47 | if [[ $? == 0 ]]; then |
48 | | PYTHON_SCRIPT=$( basename -- ${COMP_WORDS[1]} ) |
| 48 | PYTHON_SCRIPT=${COMP_WORDS[1]##*/} |
49 | 49 | echo $PYTHON_SCRIPT | egrep "manage\.py|django-admin(\.py)?" >/dev/null 2>&1 |
50 | 50 | if [[ $? == 0 ]]; then |
51 | 51 | COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]:1}" \ |
… |
… |
|
61 | 61 | if command -v whereis &>/dev/null; then |
62 | 62 | python_interpreters=$(whereis python | cut -d " " -f 2-) |
63 | 63 | for python in $python_interpreters; do |
64 | | pythons="${pythons} $(basename -- $python)" |
| 64 | pythons="${pythons} ${python##*/}" |
65 | 65 | done |
66 | 66 | pythons=$(echo $pythons | tr " " "\n" | sort -u | tr "\n" " ") |
67 | 67 | else |