2008-05-20 04:27:44 +04:00
|
|
|
#!/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
|
2010-01-14 18:25:54 +03:00
|
|
|
# after exporting DEVROOT optionally to point to the projects folder.
|
2008-05-20 04:27:44 +04:00
|
|
|
#
|
|
|
|
# setup:
|
|
|
|
# - edit DRLIST below to include your own possible devroots
|
|
|
|
# (ie. where you have subfolders for your own projects)
|
2010-01-14 18:25:54 +03:00
|
|
|
# or export DEVROOT before sourcing dev-perso.
|
2008-05-20 04:27:44 +04:00
|
|
|
# - optionally edit PWLIST below to where you possibly have a
|
|
|
|
# PASSWDS/ folder with passwords stored as plain text.
|
|
|
|
# (not really a good idea though :) It's exported
|
|
|
|
# for use by project's .profile
|
|
|
|
# - 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='...'
|
|
|
|
#
|
|
|
|
# # shortcut to display password file for this svn
|
|
|
|
# alias pass="cat $PASSWDS/myself.developer.berlios.de.pass"
|
|
|
|
#
|
|
|
|
# # 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...
|
2010-01-14 18:25:54 +03:00
|
|
|
if [ -z "$DEVROOT" ]; then
|
|
|
|
DRLIST="$HOME/devel /Data /work /Volumes/Data/devel"
|
|
|
|
for d in $DRLIST; do
|
2012-02-23 04:56:30 +04:00
|
|
|
test -d "$d" && DEVROOT="$d" && break;
|
2010-01-14 18:25:54 +03:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
export DEVROOT
|
|
|
|
|
|
|
|
# automagically find password files
|
2008-05-20 04:27:44 +04:00
|
|
|
PWLIST="/Data /fat32 $HOME"
|
|
|
|
for d in $PWLIST; do
|
2012-02-23 04:56:30 +04:00
|
|
|
test -d "$d/PASSWDS" && PASSWDS="$d/PASSWDS" && break;
|
2008-05-20 04:27:44 +04:00
|
|
|
done
|
|
|
|
export PASSWDS
|
|
|
|
|
|
|
|
# svn sometimes forgets about vi and wants me to use nano...
|
|
|
|
#export EDITOR=vim
|
|
|
|
|
2012-02-23 04:56:30 +04:00
|
|
|
dev() {
|
2008-05-20 04:27:44 +04:00
|
|
|
if [ $# -lt 1 ]; then
|
2009-12-06 17:31:24 +03:00
|
|
|
#ls $DEVROOT/*/.profile | sed 's,.*/\([^/]*\)/.profile,\1,'
|
|
|
|
for f in "$DEVROOT/"*; do test -e "$f/.profile" || continue; echo ${f##*/}; done
|
2008-05-20 04:27:44 +04:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if [ "x$1" = "x--help" ]; then
|
|
|
|
echo "setup project-specific development environment"
|
2010-01-14 18:25:54 +03:00
|
|
|
echo "usage: dev [-n] [project]"
|
2008-05-20 04:27:44 +04:00
|
|
|
echo "running without argument lists available projects"
|
2010-01-14 18:25:54 +03:00
|
|
|
echo "-n projname initializes a new project"
|
2008-05-20 04:27:44 +04:00
|
|
|
return 1
|
|
|
|
fi
|
2010-01-14 18:25:54 +03:00
|
|
|
if [ "x$1" = "x-n" -a -n "$2" ]; then
|
|
|
|
shift
|
|
|
|
mkdir "$DEVROOT/$1" && touch "$DEVROOT/$1/.profile"
|
|
|
|
# fallback
|
|
|
|
fi
|
2012-02-23 04:56:30 +04:00
|
|
|
|
2010-03-16 17:52:19 +03:00
|
|
|
export DEVPROJ="$1"
|
2008-05-20 04:27:44 +04:00
|
|
|
if [ ! -d "$DEVROOT/$1" ]; then
|
|
|
|
echo "invalid project name '$1'"
|
|
|
|
return 1
|
|
|
|
fi
|
2012-02-23 04:56:30 +04:00
|
|
|
|
|
|
|
# change to the project root folder
|
2008-05-20 04:27:44 +04:00
|
|
|
cd "$DEVROOT/$1"
|
2012-02-23 04:56:30 +04:00
|
|
|
|
2008-05-20 04:27:44 +04:00
|
|
|
# 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
|
2012-02-23 04:56:30 +04:00
|
|
|
|
|
|
|
# force default locale so that compiler errors and such are reported in english
|
|
|
|
#export LC_ALL=C.UTF-8
|
|
|
|
|
2008-05-20 04:27:44 +04:00
|
|
|
# set the prompt
|
|
|
|
# cf. http://tldp.org/HOWTO/Bash-Prompt-HOWTO/
|
2010-04-10 19:39:36 +04:00
|
|
|
NICEPS1='\[\033[1m\][\u@\h \w]\[\033[0m\]\$ '
|
2008-05-20 04:27:44 +04:00
|
|
|
case "$TERM" in
|
2009-01-23 04:02:04 +03:00
|
|
|
dumb|emacs)
|
2008-05-20 04:27:44 +04:00
|
|
|
# simpler prompt
|
|
|
|
export PS1='[\u@\h \w]\$ '
|
|
|
|
;;
|
2010-04-10 19:39:36 +04:00
|
|
|
linux)
|
|
|
|
export PS1="$NICEPS1"
|
|
|
|
;;
|
2008-05-20 04:27:44 +04:00
|
|
|
*)
|
|
|
|
# prompt: set window title to [project:folder] also
|
2008-06-12 15:57:20 +04:00
|
|
|
#export PS1='\[\033]0;['$1':\W]\a\]\[\033[1m\][\u@\h \w]\[\033[0m\]\$ '
|
2009-01-23 04:02:04 +03:00
|
|
|
#export PS1='\033]0;['$1':\W]\a\033[1m[\u@\h \w]\033[0m\$ '
|
2010-04-10 19:39:36 +04:00
|
|
|
export PS1="$NICEPS1"
|
2009-02-04 15:59:02 +03:00
|
|
|
export PROMPT_COMMAND='echo -en "\033]0;['$1':${PWD##*/}]\a"'
|
2008-05-20 04:27:44 +04:00
|
|
|
;;
|
|
|
|
esac
|
2012-02-23 04:56:30 +04:00
|
|
|
|
2008-05-20 04:27:44 +04:00
|
|
|
# lower priority so background builds don't slow the GUI too much
|
|
|
|
case "$OSTYPE" in
|
|
|
|
beos|haiku)
|
|
|
|
prio $$ 1
|
|
|
|
;;
|
2010-04-10 19:39:36 +04:00
|
|
|
darwin10.*)
|
|
|
|
renice 3 $$
|
|
|
|
;;
|
2008-05-20 04:27:44 +04:00
|
|
|
linux-*)
|
|
|
|
# linux doesn't really need it much
|
|
|
|
#renice 3 $$
|
|
|
|
;;
|
|
|
|
esac
|
2012-02-23 04:56:30 +04:00
|
|
|
|
|
|
|
DEVUPCMD=""
|
|
|
|
|
2008-05-20 04:27:44 +04:00
|
|
|
# source the specific profile file
|
2009-12-06 17:31:24 +03:00
|
|
|
test -f .profile && . .profile
|
|
|
|
|
|
|
|
# if no editor defined, set one
|
|
|
|
test -z "$EDITOR" -a -z "$SVN_EDITOR" && export EDITOR=vim
|
2008-05-20 04:27:44 +04:00
|
|
|
|
|
|
|
# make sure the update action is the first found in history.
|
2012-04-21 12:31:33 +04:00
|
|
|
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 .git && DEVUPCMD="git pull"
|
|
|
|
test -z "$DEVUPCMD" -a -d CVS && DEVUPCMD="cvs up -d"
|
2012-04-21 17:28:48 +04:00
|
|
|
test -z "$DEVUPCMD" -a \( -f _FOSSIL_ -o -f .fslckout \) && DEVUPCMD="fossil pull"
|
2012-04-21 12:31:33 +04:00
|
|
|
test -z "$DEVUPCMD" -a -n "$P4PORT" && DEVUPCMD="p4 sync"
|
2012-02-23 04:56:30 +04:00
|
|
|
test -n "$DEVUPCMD" && history -s "$DEVUPCMD"
|
2008-05-20 04:27:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
complete -W complete -W "$(dev)" dev
|
|
|
|
|
2012-02-23 05:39:09 +04:00
|
|
|
_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
|
2008-05-20 04:27:44 +04:00
|
|
|
|