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# 21# setup: 22# - edit DRLIST below to include your own possible devroots 23# (ie. where you have subfolders for your own projects) 24# - optionally edit PWLIST below to where you possibly have a 25# PASSWDS/ folder with passwords stored as plain text. 26# (not really a good idea though :) It's exported 27# for use by project's .profile 28# - optionally force EDITOR globally (for all projects) 29# - for each project create a .profile in the subfolder, 30# which might include commands like the following, but can remain empty. 31# usually it will just contain a "cd" to the source/trunk subfolder... 32# 33# # force svn ssh user for this project 34# export SVN_SSH='ssh -l myuser' 35# 36# # force CVSROOT for this project 37# export CVSROOT='...' 38# 39# # shortcut to display password file for this svn 40# alias pass="cat $PASSWDS/myself.developer.berlios.de.pass" 41# 42# # change to the source tree 43# cd trunk 44# # ease use of cd 45# export CDPATH=":$PWD" 46# 47# Now you just have to type: 48# dev h[TAB] 49# to complete to "dev haiku", [RET] and you'll get the history from the 50# last time you worked on it, and everything set up. 51 52 53# automagically find them on different machines... 54DRLIST="/Data /work $HOME/devel" 55PWLIST="/Data /fat32 $HOME" 56for d in $DRLIST; do 57 test -d $d && DEVROOT=$d && break; 58done 59for d in $PWLIST; do 60 test -d $d/PASSWDS && PASSWDS=$d/PASSWDS && break; 61done 62export DEVROOT 63export PASSWDS 64 65# svn sometimes forgets about vi and wants me to use nano... 66#export EDITOR=vim 67 68function dev() { 69 if [ $# -lt 1 ]; then 70 ls $DEVROOT/*/.profile | sed 's,.*/\([^/]*\)/.profile,\1,' 71 return 0 72 fi 73 if [ "x$1" = "x--help" ]; then 74 echo "setup project-specific development environment" 75 echo "usage: dev [project]" 76 echo "running without argument lists available projects" 77 return 1 78 fi 79 if [ ! -d "$DEVROOT/$1" ]; then 80 echo "invalid project name '$1'" 81 return 1 82 fi 83 cd "$DEVROOT/$1" 84 # use a specific history file 85 export HISTFILE="$DEVROOT/$1/.bash_history" 86 # and bump up the history limits 87 export HISTSIZE=1000 88 export HISTFILESIZE=100000 89 export HISTCONTROL=ignoreboth 90 # and force loading the new histfile 91 history -r 92 # set the prompt 93 # cf. http://tldp.org/HOWTO/Bash-Prompt-HOWTO/ 94 case "$TERM" in 95 dump|emacs) 96 # simpler prompt 97 export PS1='[\u@\h \w]\$ ' 98 ;; 99 *) 100 # prompt: set window title to [project:folder] also 101 #export PS1='\[\033]0;['$1':\W]\a\]\[\033[1m\][\u@\h \w]\[\033[0m\]\$ ' 102 export PS1='\033]0;['$1':\W]\a\033[1m[\u@\h \w]\033[0m\$ ' 103 ;; 104 esac 105 # lower priority so background builds don't slow the GUI too much 106 case "$OSTYPE" in 107 beos|haiku) 108 prio $$ 1 109 ;; 110 linux-*) 111 # linux doesn't really need it much 112 #renice 3 $$ 113 ;; 114 esac 115 116 # source the specific profile file 117 source .profile 118 119 # make sure the update action is the first found in history. 120 test -d .svn && history -s svn up 121 test -d .hg && history -s hg pull 122 test -d CVS && history -s cvs up -d 123 test -n "$P4PORT" && history -s p4 sync 124} 125 126complete -W complete -W "$(dev)" dev 127 128 129