#!/bin/sh# /etc/profile.d/dev-perso## (c) 2006-2008, mmu_man## project-specific environment handling:# - sources project-specific .profile,# - maintains project-specific .bash_history with bigger default size,# to avoid mixing command histories# - pushes "cvs up -d" or "svn up" or "p4 sync" as last history command# for quick access# - has a nice prompt# - lowers shell priority on BeOS to limit the effects of svn or jam on# the gui# - automatically completes project names on the "dev" function# from project subfolders containing a .profile## This script should be sourced by bash, either from /etc/profile# (in /etc/profile.d/) or your own .bashrc or .profile# after exporting DEVROOT optionally to point to the projects folder.## setup:# - edit DRLIST below to include your own possible devroots# (ie. where you have subfolders for your own projects)# or export DEVROOT before sourcing dev-perso.# - optionally force EDITOR globally (for all projects)# - for each project create a .profile in the subfolder,# which might include commands like the following, but can remain empty.# usually it will just contain a "cd" to the source/trunk subfolder...## # force svn ssh user for this project# export SVN_SSH='ssh -l myuser'## # force CVSROOT for this project# export CVSROOT='...'## # change to the source tree# cd trunk# # ease use of cd# export CDPATH=":$PWD"## Now you just have to type:# dev h[TAB]# to complete to "dev haiku", [RET] and you'll get the history from the# last time you worked on it, and everything set up.# automagically find them on different machines...if [ -z "$DEVROOT" ]; thenDRLIST="$HOME/devel /Data /work /Volumes/Data/devel"for d in $DRLIST; dotest -d "$d" && DEVROOT="$d" && break;donefiexport DEVROOT# svn sometimes forgets about vi and wants me to use nano...#export EDITOR=vimdev() {if [ $# -lt 1 ]; then#ls $DEVROOT/*/.profile | sed 's,.*/\([^/]*\)/.profile,\1,'for f in "$DEVROOT/"*; do test -e "$f/.profile" || continue; echo ${f##*/}; donereturn 0fiif [ "x$1" = "x--help" ]; thenecho "setup project-specific development environment"echo "usage: dev [-n] [project]"echo "running without argument lists available projects"echo "-n projname initializes a new project"return 1fiif [ "x$1" = "x-n" -a -n "$2" ]; thenshiftmkdir "$DEVROOT/$1" && touch "$DEVROOT/$1/.profile"# fallbackfiexport DEVPROJ="$1"if [ ! -d "$DEVROOT/$1" ]; thenecho "invalid project name '$1'"return 1fi# change to the project root foldercd "$DEVROOT/$1"# use a specific history fileexport HISTFILE="$DEVROOT/$1/.bash_history"# and bump up the history limitsexport HISTSIZE=1000export HISTFILESIZE=100000export HISTCONTROL=ignoreboth# and force loading the new histfilehistory -r# force default locale so that compiler errors and such are reported in english#export LC_ALL=C.UTF-8# set the prompt# cf. http://tldp.org/HOWTO/Bash-Prompt-HOWTO/NICEPS1='\[\033[1m\][\u@\h \w]\[\033[0m\]\$ 'case "$TERM" indumb|emacs)# simpler promptexport PS1='[\u@\h \w]\$ ';;linux)export PS1="$NICEPS1";;*)# prompt: set window title to [project:folder] also#export PS1='\[\033]0;['$1':\W]\a\]\[\033[1m\][\u@\h \w]\[\033[0m\]\$ '#export PS1='\033]0;['$1':\W]\a\033[1m[\u@\h \w]\033[0m\$ 'export PS1="$NICEPS1"export PROMPT_COMMAND='echo -en "\033]0;['$1':${PWD##*/}]\a"';;esac# lower priority so background builds don't slow the GUI too muchcase "$OSTYPE" inbeos|haiku)prio $$ 1;;darwin10.*)renice 3 $$;;linux-*)# linux doesn't really need it much#renice 3 $$;;esac# check for a TODO listfor f in TODO TODO.org todo todo.org; dotest -e "$f" && grep '^* ' "$f" | grep --color=always ' TODO ' | head -5 && breakdoneDEVUPCMD=""# source the specific profile file# (which will likely cd to the checkout directory)test -f .profile && . .profile# if no editor defined, set onetest -z "$EDITOR" -a -z "$SVN_EDITOR" && export EDITOR=vim# make sure the update action is the first found in history.test -z "$DEVUPCMD" -a -d .git && DEVUPCMD="git pull"test -z "$DEVUPCMD" -a -d .svn && DEVUPCMD="svn up"test -z "$DEVUPCMD" -a -d .bzr && DEVUPCMD="bzr update"test -z "$DEVUPCMD" -a -d .hg && DEVUPCMD="hg pull"test -z "$DEVUPCMD" -a -d CVS && DEVUPCMD="cvs up -d"test -z "$DEVUPCMD" -a \( -f _FOSSIL_ -o -f .fslckout \) && DEVUPCMD="fossil update"test -z "$DEVUPCMD" -a -n "$P4PORT" && DEVUPCMD="p4 sync"test -n "$DEVUPCMD" && history -s "$DEVUPCMD"# spice up terminal window title for git, add current branch nametest -d .git && PROMPT_COMMAND='echo -en "\033]0;['$DEVPROJ':`git branch 2>/dev/null | sed "/^[^*]/d;s/^\*\s//"`:${PWD##*/}]\a"'}complete -W complete -W "$(dev)" dev_devup_notify() {echo "#### $*" >&2}devup() {if [ $# -lt 1 ]; then#ls $DEVROOT/*/.profile | sed 's,.*/\([^/]*\)/.profile,\1,'for f in "$DEVROOT/"*; dotest -e "$f/.profile" || continuegrep "^# AUTOUP$" "$f/.profile" > /dev/null 2>&1 || continuep="${f##*/}"_devup_notify "Updating $p..."devup "$p" && _devup_notify "Updated $p: OK" || (_devup_notify "Updating $p: Error: $?"; read)donereturn 0fi# subshell!!!(export DEVPROJ="$1"if [ ! -d "$DEVROOT/$1" ]; thenecho "invalid project name '$1'"return 1fi# change to the project root foldercd "$DEVROOT/$1"# lower priority so background builds don't slow the GUI too muchcase "$OSTYPE" inbeos|haiku)prio $$ 1;;darwin10.*)renice 3 $$;;linux-*)# linux doesn't really need it much#renice 3 $$;;esacDEVUPCMD=""# source the specific profile filetest -f .profile && . .profile# make sure the update action is the first found in history.if [ -z "$DEVUPCMD" ]; thentest -d .svn && DEVUPCMD="svn up"test -d .bzr && DEVUPCMD="bzr update"test -d .hg && DEVUPCMD="hg pull"test -d .git && DEVUPCMD="git pull"test -d CVS && DEVUPCMD="cvs up -d"test -n "$P4PORT" && DEVUPCMD="p4 sync"fitest -n "$DEVUPCMD" || return 7# run the update command...eval "$DEVUPCMD"return $?)return $?}complete -W complete -W "$(dev)" devup