#!/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" ]; then DRLIST="$HOME/devel /Data /work /Volumes/Data/devel" for d in $DRLIST; do test -d "$d" && DEVROOT="$d" && break; done fi export DEVROOT # svn sometimes forgets about vi and wants me to use nano... #export EDITOR=vim dev() { if [ $# -lt 1 ]; then #ls $DEVROOT/*/.profile | sed 's,.*/\([^/]*\)/.profile,\1,' for f in "$DEVROOT/"*; do test -e "$f/.profile" || continue; echo ${f##*/}; done return 0 fi if [ "x$1" = "x--help" ]; then echo "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 1 fi if [ "x$1" = "x-n" -a -n "$2" ]; then shift mkdir "$DEVROOT/$1" && touch "$DEVROOT/$1/.profile" # fallback fi export DEVPROJ="$1" if [ ! -d "$DEVROOT/$1" ]; then echo "invalid project name '$1'" return 1 fi # change to the project root folder cd "$DEVROOT/$1" # use a specific history file export HISTFILE="$DEVROOT/$1/.bash_history" # and bump up the history limits export HISTSIZE=1000 export HISTFILESIZE=100000 export HISTCONTROL=ignoreboth # and force loading the new histfile history -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" in dumb|emacs) # simpler prompt export 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 much case "$OSTYPE" in beos|haiku) prio $$ 1 ;; darwin10.*) renice 3 $$ ;; linux-*) # linux doesn't really need it much #renice 3 $$ ;; esac # check for a TODO list for f in TODO TODO.org todo todo.org; do test -e "$f" && grep '^* ' "$f" | grep --color=always ' TODO ' | head -5 && break done DEVUPCMD="" # source the specific profile file # (which will likely cd to the checkout directory) test -f .profile && . .profile # if no editor defined, set one test -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 name test -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/"*; do test -e "$f/.profile" || continue grep "^# AUTOUP$" "$f/.profile" > /dev/null 2>&1 || continue p="${f##*/}" _devup_notify "Updating $p..." devup "$p" && _devup_notify "Updated $p: OK" || (_devup_notify "Updating $p: Error: $?"; read) done return 0 fi # subshell!!! ( export DEVPROJ="$1" if [ ! -d "$DEVROOT/$1" ]; then echo "invalid project name '$1'" return 1 fi # change to the project root folder cd "$DEVROOT/$1" # lower priority so background builds don't slow the GUI too much case "$OSTYPE" in beos|haiku) prio $$ 1 ;; darwin10.*) renice 3 $$ ;; linux-*) # linux doesn't really need it much #renice 3 $$ ;; esac DEVUPCMD="" # source the specific profile file test -f .profile && . .profile # make sure the update action is the first found in history. if [ -z "$DEVUPCMD" ]; then test -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" fi test -n "$DEVUPCMD" || return 7 # run the update command... eval "$DEVUPCMD" return $? ) return $? } complete -W complete -W "$(dev)" devup