1#!/bin/sh 2# /etc/profile.d/dev-perso 3# 4# (c) 2006-2008, mmu_man 5# 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 11# for quick access 12# - has a nice prompt 13# - lowers shell priority on BeOS to limit the effects of svn or jam on 14# the gui 15# - automatically completes project names on the "dev" function 16# from project subfolders containing a .profile 17# 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. 21# 22# setup: 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 edit PWLIST below to where you possibly have a 27# PASSWDS/ folder with passwords stored as plain text. 28# (not really a good idea though :) It's exported 29# for use by project's .profile 30# - optionally force EDITOR globally (for all projects) 31# - for each project create a .profile in the subfolder, 32# which might include commands like the following, but can remain empty. 33# usually it will just contain a "cd" to the source/trunk subfolder... 34# 35# # force svn ssh user for this project 36# export SVN_SSH='ssh -l myuser' 37# 38# # force CVSROOT for this project 39# export CVSROOT='...' 40# 41# # shortcut to display password file for this svn 42# alias pass="cat $PASSWDS/myself.developer.berlios.de.pass" 43# 44# # change to the source tree 45# cd trunk 46# # ease use of cd 47# export CDPATH=":$PWD" 48# 49# Now you just have to type: 50# dev h[TAB] 51# to complete to "dev haiku", [RET] and you'll get the history from the 52# last time you worked on it, and everything set up. 53 54 55# automagically find them on different machines... 56if [ -z "$DEVROOT" ]; then 57 DRLIST="$HOME/devel /Data /work /Volumes/Data/devel" 58 for d in $DRLIST; do 59 test -d "$d" && DEVROOT="$d" && break; 60 done 61fi 62export DEVROOT 63 64# automagically find password files 65PWLIST="/Data /fat32 $HOME" 66for d in $PWLIST; do 67 test -d "$d/PASSWDS" && PASSWDS="$d/PASSWDS" && break; 68done 69export PASSWDS 70 71# svn sometimes forgets about vi and wants me to use nano... 72#export EDITOR=vim 73 74dev() { 75 if [ $# -lt 1 ]; then 76 #ls $DEVROOT/*/.profile | sed 's,.*/\([^/]*\)/.profile,\1,' 77 for f in "$DEVROOT/"*; do test -e "$f/.profile" || continue; echo ${f##*/}; done 78 return 0 79 fi 80 if [ "x$1" = "x--help" ]; then 81 echo "setup project-specific development environment" 82 echo "usage: dev [-n] [project]" 83 echo "running without argument lists available projects" 84 echo "-n projname initializes a new project" 85 return 1 86 fi 87 if [ "x$1" = "x-n" -a -n "$2" ]; then 88 shift 89 mkdir "$DEVROOT/$1" && touch "$DEVROOT/$1/.profile" 90 # fallback 91 fi 92 93 export DEVPROJ="$1" 94 if [ ! -d "$DEVROOT/$1" ]; then 95 echo "invalid project name '$1'" 96 return 1 97 fi 98 99 # change to the project root folder 100 cd "$DEVROOT/$1" 101 102 # use a specific history file 103 export HISTFILE="$DEVROOT/$1/.bash_history" 104 # and bump up the history limits 105 export HISTSIZE=1000 106 export HISTFILESIZE=100000 107 export HISTCONTROL=ignoreboth 108 # and force loading the new histfile 109 history -r 110 111 # force default locale so that compiler errors and such are reported in english 112 #export LC_ALL=C.UTF-8 113 114 # set the prompt 115 # cf. http://tldp.org/HOWTO/Bash-Prompt-HOWTO/ 116 NICEPS1='\[\033[1m\][\u@\h \w]\[\033[0m\]\$ ' 117 case "$TERM" in 118 dumb|emacs) 119 # simpler prompt 120 export PS1='[\u@\h \w]\$ ' 121 ;; 122 linux) 123 export PS1="$NICEPS1" 124 ;; 125 *) 126 # prompt: set window title to [project:folder] also 127 #export PS1='\[\033]0;['$1':\W]\a\]\[\033[1m\][\u@\h \w]\[\033[0m\]\$ ' 128 #export PS1='\033]0;['$1':\W]\a\033[1m[\u@\h \w]\033[0m\$ ' 129 export PS1="$NICEPS1" 130 export PROMPT_COMMAND='echo -en "\033]0;['$1':${PWD##*/}]\a"' 131 ;; 132 esac 133 134 # lower priority so background builds don't slow the GUI too much 135 case "$OSTYPE" in 136 beos|haiku) 137 prio $$ 1 138 ;; 139 darwin10.*) 140 renice 3 $$ 141 ;; 142 linux-*) 143 # linux doesn't really need it much 144 #renice 3 $$ 145 ;; 146 esac 147 148 DEVUPCMD="" 149 150 # source the specific profile file 151 test -f .profile && . .profile 152 153 # if no editor defined, set one 154 test -z "$EDITOR" -a -z "$SVN_EDITOR" && export EDITOR=vim 155 156 # make sure the update action is the first found in history. 157 test -z "$DEVUPCMD" -a -d .svn && DEVUPCMD="svn up" 158 test -z "$DEVUPCMD" -a -d .bzr && DEVUPCMD="bzr update" 159 test -z "$DEVUPCMD" -a -d .hg && DEVUPCMD="hg pull" 160 test -z "$DEVUPCMD" -a -d .git && DEVUPCMD="git pull" 161 test -z "$DEVUPCMD" -a -d CVS && DEVUPCMD="cvs up -d" 162 test -z "$DEVUPCMD" -a \( -f _FOSSIL_ -o -f .fslckout \) && DEVUPCMD="fossil update" 163 test -z "$DEVUPCMD" -a -n "$P4PORT" && DEVUPCMD="p4 sync" 164 test -n "$DEVUPCMD" && history -s "$DEVUPCMD" 165} 166 167complete -W complete -W "$(dev)" dev 168 169_devup_notify() { 170 echo "#### $*" >&2 171} 172 173devup() { 174 if [ $# -lt 1 ]; then 175 #ls $DEVROOT/*/.profile | sed 's,.*/\([^/]*\)/.profile,\1,' 176 for f in "$DEVROOT/"*; do 177 test -e "$f/.profile" || continue 178 grep "^# AUTOUP$" "$f/.profile" > /dev/null 2>&1 || continue 179 p="${f##*/}" 180 _devup_notify "Updating $p..." 181 devup "$p" && _devup_notify "Updated $p: OK" || (_devup_notify "Updating $p: Error: $?"; read) 182 done 183 return 0 184 fi 185 186 # subshell!!! 187 ( 188 189 export DEVPROJ="$1" 190 if [ ! -d "$DEVROOT/$1" ]; then 191 echo "invalid project name '$1'" 192 return 1 193 fi 194 195 # change to the project root folder 196 cd "$DEVROOT/$1" 197 198 # lower priority so background builds don't slow the GUI too much 199 case "$OSTYPE" in 200 beos|haiku) 201 prio $$ 1 202 ;; 203 darwin10.*) 204 renice 3 $$ 205 ;; 206 linux-*) 207 # linux doesn't really need it much 208 #renice 3 $$ 209 ;; 210 esac 211 212 DEVUPCMD="" 213 214 # source the specific profile file 215 test -f .profile && . .profile 216 217 # make sure the update action is the first found in history. 218 if [ -z "$DEVUPCMD" ]; then 219 test -d .svn && DEVUPCMD="svn up" 220 test -d .bzr && DEVUPCMD="bzr update" 221 test -d .hg && DEVUPCMD="hg pull" 222 test -d .git && DEVUPCMD="git pull" 223 test -d CVS && DEVUPCMD="cvs up -d" 224 test -n "$P4PORT" && DEVUPCMD="p4 sync" 225 fi 226 227 test -n "$DEVUPCMD" || return 7 228 229 # run the update command... 230 eval "$DEVUPCMD" 231 232 return $? 233 ) 234 235 return $? 236} 237 238complete -W complete -W "$(dev)" devup 239 240