summaryrefslogtreecommitdiff
path: root/.bash_completion.d
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2012-11-14 10:56:52 -0500
committerMike Crute <mike@crute.us>2012-11-14 10:56:52 -0500
commitad4c2f005b0898bac9ca58df33e0f5e84cf81d09 (patch)
tree0f265564c3cbc82275f73a06547a78ca1d6132bc /.bash_completion.d
parent6e8c9d0ba9edde55e4a0b68ddfdf99cc4df6500d (diff)
downloaddotfiles-ad4c2f005b0898bac9ca58df33e0f5e84cf81d09.tar.bz2
dotfiles-ad4c2f005b0898bac9ca58df33e0f5e84cf81d09.tar.xz
dotfiles-ad4c2f005b0898bac9ca58df33e0f5e84cf81d09.zip
Add django bash completion
Diffstat (limited to '.bash_completion.d')
-rwxr-xr-x.bash_completion.d/django_bash_completion72
1 files changed, 72 insertions, 0 deletions
diff --git a/.bash_completion.d/django_bash_completion b/.bash_completion.d/django_bash_completion
new file mode 100755
index 0000000..1c3887e
--- /dev/null
+++ b/.bash_completion.d/django_bash_completion
@@ -0,0 +1,72 @@
1# #########################################################################
2# This bash script adds tab-completion feature to django-admin.py and
3# manage.py.
4#
5# Testing it out without installing
6# =================================
7#
8# To test out the completion without "installing" this, just run this file
9# directly, like so:
10#
11# . ~/path/to/django_bash_completion
12#
13# Note: There's a dot ('.') at the beginning of that command.
14#
15# After you do that, tab completion will immediately be made available in your
16# current Bash shell. But it won't be available next time you log in.
17#
18# Installing
19# ==========
20#
21# To install this, point to this file from your .bash_profile, like so:
22#
23# . ~/path/to/django_bash_completion
24#
25# Do the same in your .bashrc if .bashrc doesn't invoke .bash_profile.
26#
27# Settings will take effect the next time you log in.
28#
29# Uninstalling
30# ============
31#
32# To uninstall, just remove the line from your .bash_profile and .bashrc.
33
34_django_completion()
35{
36 COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
37 COMP_CWORD=$COMP_CWORD \
38 DJANGO_AUTO_COMPLETE=1 $1 ) )
39}
40complete -F _django_completion -o default django-admin.py manage.py django-admin
41
42_python_django_completion()
43{
44 if [[ ${COMP_CWORD} -ge 2 ]]; then
45 PYTHON_EXE=$( basename -- ${COMP_WORDS[0]} )
46 echo $PYTHON_EXE | egrep "python([2-9]\.[0-9])?" >/dev/null 2>&1
47 if [[ $? == 0 ]]; then
48 PYTHON_SCRIPT=$( basename -- ${COMP_WORDS[1]} )
49 echo $PYTHON_SCRIPT | egrep "manage\.py|django-admin(\.py)?" >/dev/null 2>&1
50 if [[ $? == 0 ]]; then
51 COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]:1}" \
52 COMP_CWORD=$(( COMP_CWORD-1 )) \
53 DJANGO_AUTO_COMPLETE=1 ${COMP_WORDS[*]} ) )
54 fi
55 fi
56 fi
57}
58
59# Support for multiple interpreters.
60unset pythons
61if command -v whereis &>/dev/null; then
62 python_interpreters=$(whereis python | cut -d " " -f 2-)
63 for python in $python_interpreters; do
64 pythons="${pythons} $(basename -- $python)"
65 done
66 pythons=$(echo $pythons | tr " " "\n" | sort -u | tr "\n" " ")
67else
68 pythons=python
69fi
70
71complete -F _python_django_completion -o default $pythons
72