limeyd (owner)

Revisions

gist: 61862 Download_button fork
public
Description:
bash functions for a lazy django developer
Public Clone URL: git://gist.github.com/61862.git
Embed All Files: show embed
bashrc #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# simple shortcuts
 
export MY_DEV_PATH=~/development
export MY_EDITOR=mate
 
ed () {
    if [ "$#" -lt 1 ]; then
           echo "Usage: ed \"editor args + directory or filename\""
           return;
    fi
    $MY_EDITOR $*;
}
 
bashrc () {
    ed ~/.bashrc;
}
 
reload () {
source ~/.bashrc;
source ~/.profile;
echo '.bashrc and .profile reloaded!';
}
 
#python
py () { python $*; }
ipy () { ipython $*; }
 
#django
export DEV_DJANGO=$MY_DEV_PATH/django
export DEV_DJANGO_APPS=$DEV_DJANGO/apps
export DEV_DJANGO_SITES=$DEV_DJANGO/sites
 
dj () {
    # list all django commands here incase i forget them :)
    echo "=== DJANGO COMMANDS ========================";
    echo "djd args - changes directories to django development and allows for path to app or site.";
    echo " >> e.g. djd app/django_foo djd sites/django_bar";
 
    echo "djrs calls runserver in the current site/project and passes on optional arguments";
 
    echo "djsh - atempts to run django shell_plus but defaults to shell if django-extentions are not installed!"
 
    echo "";
    echo "=== DJANGO SITES ========================";
    echo "djs - changes directories to django sites development and allows for direct access site";
    echo " >> e.g. djs django_site";
    echo "djes - same as above but launches the folder in you favorite editor.";
    
    echo "";
    echo "=== DJANGO APPS ========================";
    echo "dja - changes directories to django app development and allows for direct access to an app";
    echo " >> e.g. dja django_app";
    echo "djea - same as above but launches the folder in you favorite editor.";
    
    echo "djmka - creates a reusealble director with django-app-name and default files also initilizes the folder as git repo";
    echo " >> e.g. djmka foo-bar";
    echo "djea - same as above but launches the folder in you favorite editor.";
    
}
 
#django dev
djd () { cd $DEV_DJANGO/$*;}
 
#django runserver
djrs () { ./manage.py runserver $*; }
 
#django shellplus requires django_extensions
djsh () {
    ./manage.py shell_plus || echo "Using Default Django shell instead!" && djshb;
}
 
djshb () {
    ./manage.py shell;
}
 
 
djsdb () { ./manage.py syncdb; }
 
djre () {
    if [ "$#" -lt 1 ]; then
        echo "Usage: djre \"django app name\""
        return;
    fi
    
    ./manage.py reset $1;
}
 
# django app functions
dja () { cd $DEV_DJANGO_APPS/$*; }
 
djea () {
    if [ "$#" -lt 1 ]; then
        echo "Usage: djea \"django app name\""
        return;
    fi
 
    ed $DEV_DJANGO_APPS/$1;
}
djmka () {
    if [ "$#" -lt 1 ]; then
        echo "Usage: djmka \"django app name\""
        return;
    fi
    
    # define path
    new_app_path=$DEV_DJANGO_APPS/"django-"$1;
    
    # make default folders
    mkdir -p $new_app_path"/examples" $new_app_path"/docs" $new_app_path"/tests";
    
    cd $new_app_path
    
    # create default files
    touch AUTHORS && echo "django-"$1" == TODO" > AUTHORS
    touch README && echo "django-"$1" == TODO" > README
    touch INSTALL && echo "django-"$1" == TODO" > INSTALL
    touch setup.py && echo "django-"$1" == TODO" > setup.py
    touch LICENSE && echo "django-"$1" == TODO" > LICENSE
    
    # create app
    django-admin.py startapp $1;
    
    # setup initial repo
    git init -q && git add . && git commit -q -m "Initial Commit";
    
    # add app to python path requires pylink/plink
    plink $1 $1;
    
}
 
djs () { cd $DEV_DJANGO_SITES/$*; }
djes () {
    if [ "$#" -lt 1 ]; then
        echo "Usage: djse \"django site name\""
        return;
    fi
    cd $DEV_DJANGO_SITES/$1;
    ed .;
}
 
djmks () {
    if [ "$#" -lt 1 ]; then
        echo "Usage: da \"django project name\""
        return;
    fi
 
    pushd $DEV_DJANGO_SITES;
    django-admin.py startproject $1;
    popd;
}