2 # /etc/profile.d/dev-perso
4 # (c) 2006-2008, mmu_man
6 # project-specific environment handling:
7 # - sources project-specific .profile,
8 # - maintains project-specific .bash_history with bigger default size,
9 # to avoid mixing command histories
10 # - pushes "cvs up -d" or "svn up" or "p4 sync" as last history command
13 # - lowers shell priority on BeOS to limit the effects of svn or jam on
15 # - automatically completes project names on the "dev" function
16 # from project subfolders containing a .profile
18 # This script should be sourced by bash, either from /etc/profile
19 # (in /etc/profile.d/) or your own .bashrc or .profile
20 # after exporting DEVROOT optionally to point to the projects folder.
23 # - edit DRLIST below to include your own possible devroots
24 # (ie. where you have subfolders for your own projects)
25 # or export DEVROOT before sourcing dev-perso.
26 # - optionally force EDITOR globally (for all projects)
27 # - for each project create a .profile in the subfolder,
28 # which might include commands like the following, but can remain empty.
29 # usually it will just contain a "cd" to the source/trunk subfolder...
31 # # force svn ssh user for this project
32 # export SVN_SSH='ssh -l myuser'
34 # # force CVSROOT for this project
35 # export CVSROOT='...'
37 # # change to the source tree
40 # export CDPATH=":$PWD"
42 # Now you just have to type:
44 # to complete to "dev haiku", [RET] and you'll get the history from the
45 # last time you worked on it, and everything set up.
48 # automagically find them on different machines...
49 if [ -z "$DEVROOT" ]; then
50 DRLIST
="$HOME/devel /Data /work /Volumes/Data/devel"
52 test -d "$d" && DEVROOT
="$d" && break;
57 # svn sometimes forgets about vi and wants me to use nano...
62 #ls $DEVROOT/*/.profile | sed 's,.*/\([^/]*\)/.profile,\1,'
63 for f
in "$DEVROOT/"*; do test -e "$f/.profile" ||
continue; echo ${f##*/}; done
66 if [ "x$1" = "x--help" ]; then
67 echo "setup project-specific development environment"
68 echo "usage: dev [-n] [project]"
69 echo "running without argument lists available projects"
70 echo "-n projname initializes a new project"
73 if [ "x$1" = "x-n" -a -n "$2" ]; then
75 mkdir
"$DEVROOT/$1" && touch "$DEVROOT/$1/.profile"
80 if [ ! -d "$DEVROOT/$1" ]; then
81 echo "invalid project name '$1'"
85 # change to the project root folder
88 # use a specific history file
89 export HISTFILE
="$DEVROOT/$1/.bash_history"
90 # and bump up the history limits
92 export HISTFILESIZE
=100000
93 export HISTCONTROL
=ignoreboth
94 # and force loading the new histfile
97 # force default locale so that compiler errors and such are reported in english
98 #export LC_ALL=C.UTF-8
101 # cf. http://tldp.org/HOWTO/Bash-Prompt-HOWTO/
102 NICEPS1
='\[\033[1m\][\u@\h \w]\[\033[0m\]\$ '
106 export PS1
='[\u@\h \w]\$ '
109 export PS1
="$NICEPS1"
112 # prompt: set window title to [project:folder] also
113 #export PS1='\[\033]0;['$1':\W]\a\]\[\033[1m\][\u@\h \w]\[\033[0m\]\$ '
114 #export PS1='\033]0;['$1':\W]\a\033[1m[\u@\h \w]\033[0m\$ '
115 export PS1
="$NICEPS1"
116 export PROMPT_COMMAND
='echo -en "\033]0;['$1':${PWD##*/}]\a"'
120 # lower priority so background builds don't slow the GUI too much
129 # linux doesn't really need it much
134 # check for a TODO list
135 for f
in TODO TODO.org todo todo.org
; do
136 test -e "$f" && grep '^* ' "$f" |
grep --color=always
' TODO ' |
head -5 && break
141 # source the specific profile file
142 # (which will likely cd to the checkout directory)
143 test -f .profile
&& . .profile
145 # if no editor defined, set one
146 test -z "$EDITOR" -a -z "$SVN_EDITOR" && export EDITOR
=vim
148 # make sure the update action is the first found in history.
149 test -z "$DEVUPCMD" -a -d .git
&& DEVUPCMD
="git pull"
150 test -z "$DEVUPCMD" -a -d .svn
&& DEVUPCMD
="svn up"
151 test -z "$DEVUPCMD" -a -d .bzr
&& DEVUPCMD
="bzr update"
152 test -z "$DEVUPCMD" -a -d .hg
&& DEVUPCMD
="hg pull"
153 test -z "$DEVUPCMD" -a -d CVS
&& DEVUPCMD
="cvs up -d"
154 test -z "$DEVUPCMD" -a \
( -f _FOSSIL_
-o -f .fslckout \
) && DEVUPCMD
="fossil update"
155 test -z "$DEVUPCMD" -a -n "$P4PORT" && DEVUPCMD
="p4 sync"
156 test -n "$DEVUPCMD" && history -s "$DEVUPCMD"
158 # spice up terminal window title for git, add current branch name
159 test -d .git
&& PROMPT_COMMAND
='echo -en "\033]0;['$DEVPROJ':`git branch 2>/dev/null | sed "/^[^*]/d;s/^\*\s//"`:${PWD##*/}]\a"'
162 complete
-W complete
-W "$(dev)" dev
169 if [ $# -lt 1 ]; then
170 #ls $DEVROOT/*/.profile | sed 's,.*/\([^/]*\)/.profile,\1,'
171 for f
in "$DEVROOT/"*; do
172 test -e "$f/.profile" ||
continue
173 grep "^# AUTOUP$" "$f/.profile" > /dev
/null
2>&1 ||
continue
175 _devup_notify
"Updating $p..."
176 devup
"$p" && _devup_notify
"Updated $p: OK" ||
(_devup_notify
"Updating $p: Error: $?"; read)
185 if [ ! -d "$DEVROOT/$1" ]; then
186 echo "invalid project name '$1'"
190 # change to the project root folder
193 # lower priority so background builds don't slow the GUI too much
202 # linux doesn't really need it much
209 # source the specific profile file
210 test -f .profile
&& . .profile
212 # make sure the update action is the first found in history.
213 if [ -z "$DEVUPCMD" ]; then
214 test -d .svn
&& DEVUPCMD
="svn up"
215 test -d .bzr
&& DEVUPCMD
="bzr update"
216 test -d .hg
&& DEVUPCMD
="hg pull"
217 test -d .git
&& DEVUPCMD
="git pull"
218 test -d CVS
&& DEVUPCMD
="cvs up -d"
219 test -n "$P4PORT" && DEVUPCMD
="p4 sync"
222 test -n "$DEVUPCMD" ||
return 7
224 # run the update command...
233 complete
-W complete
-W "$(dev)" devup