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 74function dev() { 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 export DEVPROJ="$1" 93 if [ ! -d "$DEVROOT/$1" ]; then 94 echo "invalid project name '$1'" 95 return 1 96 fi 97 cd "$DEVROOT/$1" 98 # use a specific history file 99 export HISTFILE="$DEVROOT/$1/.bash_history" 100 # and bump up the history limits 101 export HISTSIZE=1000 102 export HISTFILESIZE=100000 103 export HISTCONTROL=ignoreboth 104 # and force loading the new histfile 105 history -r 106 # set the prompt 107 # cf. http://tldp.org/HOWTO/Bash-Prompt-HOWTO/ 108 NICEPS1='\[\033[1m\][\u@\h \w]\[\033[0m\]\$ ' 109 case "$TERM" in 110 dumb|emacs) 111 # simpler prompt 112 export PS1='[\u@\h \w]\$ ' 113 ;; 114 linux) 115 export PS1="$NICEPS1" 116 ;; 117 *) 118 # prompt: set window title to [project:folder] also 119 #export PS1='\[\033]0;['$1':\W]\a\]\[\033[1m\][\u@\h \w]\[\033[0m\]\$ ' 120 #export PS1='\033]0;['$1':\W]\a\033[1m[\u@\h \w]\033[0m\$ ' 121 export PS1="$NICEPS1" 122 export PROMPT_COMMAND='echo -en "\033]0;['$1':${PWD##*/}]\a"' 123 ;; 124 esac 125 # lower priority so background builds don't slow the GUI too much 126 case "$OSTYPE" in 127 beos|haiku) 128 prio $$ 1 129 ;; 130 darwin10.*) 131 renice 3 $$ 132 ;; 133 linux-*) 134 # linux doesn't really need it much 135 #renice 3 $$ 136 ;; 137 esac 138 139 # source the specific profile file 140 test -f .profile && . .profile 141 142 # if no editor defined, set one 143 test -z "$EDITOR" -a -z "$SVN_EDITOR" && export EDITOR=vim 144 145 # make sure the update action is the first found in history. 146 test -d .svn && history -s svn up 147 test -d .hg && history -s hg pull 148 test -d .git && history -s git pull 149 test -d CVS && history -s cvs up -d 150 test -n "$P4PORT" && history -s p4 sync 151} 152 153complete -W complete -W "$(dev)" dev 154 155 156