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 # spice up terminal window title for git, add current branch name 167 test -d .git && PROMPT_COMMAND='echo -en "\033]0;['$DEVPROJ':`git branch | sed "/^[^*]/d;s/^\*\s//"`:${PWD##*/}]\a"' 168} 169 170complete -W complete -W "$(dev)" dev 171 172_devup_notify() { 173 echo "#### $*" >&2 174} 175 176devup() { 177 if [ $# -lt 1 ]; then 178 #ls $DEVROOT/*/.profile | sed 's,.*/\([^/]*\)/.profile,\1,' 179 for f in "$DEVROOT/"*; do 180 test -e "$f/.profile" || continue 181 grep "^# AUTOUP$" "$f/.profile" > /dev/null 2>&1 || continue 182 p="${f##*/}" 183 _devup_notify "Updating $p..." 184 devup "$p" && _devup_notify "Updated $p: OK" || (_devup_notify "Updating $p: Error: $?"; read) 185 done 186 return 0 187 fi 188 189 # subshell!!! 190 ( 191 192 export DEVPROJ="$1" 193 if [ ! -d "$DEVROOT/$1" ]; then 194 echo "invalid project name '$1'" 195 return 1 196 fi 197 198 # change to the project root folder 199 cd "$DEVROOT/$1" 200 201 # lower priority so background builds don't slow the GUI too much 202 case "$OSTYPE" in 203 beos|haiku) 204 prio $$ 1 205 ;; 206 darwin10.*) 207 renice 3 $$ 208 ;; 209 linux-*) 210 # linux doesn't really need it much 211 #renice 3 $$ 212 ;; 213 esac 214 215 DEVUPCMD="" 216 217 # source the specific profile file 218 test -f .profile && . .profile 219 220 # make sure the update action is the first found in history. 221 if [ -z "$DEVUPCMD" ]; then 222 test -d .svn && DEVUPCMD="svn up" 223 test -d .bzr && DEVUPCMD="bzr update" 224 test -d .hg && DEVUPCMD="hg pull" 225 test -d .git && DEVUPCMD="git pull" 226 test -d CVS && DEVUPCMD="cvs up -d" 227 test -n "$P4PORT" && DEVUPCMD="p4 sync" 228 fi 229 230 test -n "$DEVUPCMD" || return 7 231 232 # run the update command... 233 eval "$DEVUPCMD" 234 235 return $? 236 ) 237 238 return $? 239} 240 241complete -W complete -W "$(dev)" devup 242 243