xref: /haiku/3rdparty/mmu_man/scripts/dev-perso (revision 3c6e2dd68577c34d93e17f19711f6245bf6d0915)
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="$HOME/devel /Data /work /Volumes/Data/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		for f in "$DEVROOT/"*; do test -e "$f/.profile" || continue; echo ${f##*/}; done
72		return 0
73	fi
74	if [ "x$1" = "x--help" ]; then
75		echo "setup project-specific development environment"
76		echo "usage: dev [project]"
77		echo "running without argument lists available projects"
78		return 1
79	fi
80	if [ ! -d "$DEVROOT/$1" ]; then
81		echo "invalid project name '$1'"
82		return 1
83	fi
84	cd "$DEVROOT/$1"
85	# use a specific history file
86	export HISTFILE="$DEVROOT/$1/.bash_history"
87	# and bump up the history limits
88	export HISTSIZE=1000
89	export HISTFILESIZE=100000
90	export HISTCONTROL=ignoreboth
91	# and force loading the new histfile
92	history -r
93	# set the prompt
94	# cf. http://tldp.org/HOWTO/Bash-Prompt-HOWTO/
95	case "$TERM" in
96	dumb|emacs)
97		# simpler prompt
98		export PS1='[\u@\h \w]\$ '
99		;;
100	*)
101		# prompt: set window title to [project:folder] also
102		#export PS1='\[\033]0;['$1':\W]\a\]\[\033[1m\][\u@\h \w]\[\033[0m\]\$ '
103		#export PS1='\033]0;['$1':\W]\a\033[1m[\u@\h \w]\033[0m\$ '
104		export PS1='\[\033[1m\][\u@\h \w]\[\033[0m\]\$ '
105		export PROMPT_COMMAND='echo -en "\033]0;['$1':${PWD##*/}]\a"'
106		;;
107	esac
108	# lower priority so background builds don't slow the GUI too much
109	case "$OSTYPE" in
110	beos|haiku)
111		prio $$ 1
112		;;
113	linux-*)
114		# linux doesn't really need it much
115		#renice 3 $$
116		;;
117	esac
118
119	# source the specific profile file
120	test -f .profile && . .profile
121
122	# if no editor defined, set one
123	test -z "$EDITOR" -a -z "$SVN_EDITOR" && export EDITOR=vim
124
125	# make sure the update action is the first found in history.
126	test -d .svn && history -s svn up
127	test -d .hg && history -s hg pull
128	test -d .git && history -s git pull
129	test -d CVS && history -s cvs up -d
130	test -n "$P4PORT" && history -s p4 sync
131}
132
133complete -W complete -W "$(dev)" dev
134
135
136