#!/bin/sh # # cvs-switch.sh - easily switch between multiple CVS Repositories # # # Usage: add next line to your ~/.bashrc, ~/.zshrc or etc.: # # alias cvs-switch='eval `$HOME/prog/cvs/scripts/shell/cvs-switch/cvs-switch.sh`' # # Then you can easily switch between CVS Repositories with alias 'cvs-switch' # Available CVS Repositories are configured in your ~/.cvs-repositories.conf, # see cvs-repositories.conf example # # # Developed by Lubomir Host 'rajo' # Copyright (c) 2004 Platon SDG, http://platon.sk/ # Licensed under terms of GNU General Public License. # All rights reserved. # # Changelog: # 2004-04-13 - created # # $Platon: scripts/shell/cvs-switch/cvs-switch.sh,v 1.4 2004/10/31 12:11:11 rajo Exp $ # # This code is tested on Linux, FreeBSD and Solaris # print_message() { # {{{ echo $*" " > /dev/stderr } # }}} print_if_not_empty() { # {{{ name=$1 value=$2 if [ ! -z "$value" ]; then print_message " $name = $value" fi } # }}} print_exported() { # {{{ name=$1 value=$2 if [ -z $value ]; then echo "unset $name;" else echo "export $name=\"$value\";" fi } # }}} # # This can't be function loaded by the shell, because error message appears: # ... # switch-cvs:50: bad substitution # ... #switch-cvs() #{ # {{{ CVS_SWITCH_CONFIG="$HOME/.cvs-repositories.conf" # cmd for sed: TOLOWER="y/.-ABCDEFGHIJKLMNOPQRSTUVWXYZ/__abcdefghijklmnopqrstuvwxyz/" if [ -f "$CVS_SWITCH_CONFIG" ]; then . "$CVS_SWITCH_CONFIG"; fi UNAME="`uname`" # OS depend code {{{ case "$UNAME" in Linux) HOSTNAME="`hostname`" DOMAINNAME="`hostname -d`" ;; FreeBSD) HOSTNAME="`hostname -s`" DOMAINNAME="`hostname | sed 's/^[^.]*\.//g'`" ;; SunOS) HOSTNAME="`hostname`" DOMAINNAME="`domainname`" ;; *) print_message "Unsupported operating system, sorry..."; exit 1; ;; esac # }}} x_HOSTNAME=`echo "$HOSTNAME" | sed "$TOLOWER"` x_DOMAINNAME=`echo "$DOMAINNAME" | sed "$TOLOWER"` #echo "x_HOSTNAME='$x_HOSTNAME'" #echo "x_DOMAINNAME='$x_DOMAINNAME'" REPOSITORIES="DOMAIN_${x_DOMAINNAME}" #echo "Available repositories: ${!REPOSITORIES}"; SET_VARIABLES='title="TITLE_$rep"; cvsroot="CVSROOT_$rep"; cvs_rsh="CVS_RSH_$rep";' TITLE_none="NONE" CVSROOT_none="" CVS_RSH_none="" i=0 for rep in none ${!REPOSITORIES}; do eval rep_$i="$rep"; eval "$SET_VARIABLES"; print_message print_message "$i - ${!title}"; print_if_not_empty "CVSROOT" "${!cvsroot}" print_if_not_empty "CVS_RSH" "${!cvs_rsh}" i=$((i + 1)) done print_message print_message -en "Your choice: [0]:" read x if [ -z "$x" ]; then i=1; else i="$x"; fi myrep="rep_$i" rep=${!myrep}; eval "$SET_VARIABLES"; print_exported "CVSROOT" "${!cvsroot}" print_exported "CVS_RSH" "${!cvs_rsh}" #} # }}} #cvs-switch # vim: ts=4 # vim600: fdl=0 fdc=3 fdm=marker