.bashrc

#!/bin/bash
#
# GNU Bash configuration file (~/.bashrc) 
# 1999-2006,  kolter <kolter@openics.org>
#
#  This file is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY
#
 
# If running interactively, then:
if [ "$PS1" ]; then
 
    # enable core dumps
    ulimit -c 8192
 
    # some global vars
    export EDITOR="emacs -u $LOGNAME -nw"
    export EMAIL="kolter@openics.org"
    [ -x "$(which colorgcc)" ] && export CC="colorgcc"
 
    # PATH stuff
    export PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:/usr/games
 
    # where are we
    export _OS=$(uname -s)
 
    # don't put duplicate lines in the history. See bash(1) for more options
    export HISTCONTROL=ignoredups
 
    # check the window size after each command and, if necessary,
    # update the values of LINES and COLUMNS.
    shopt -s checkwinsize
    # correct minors errors in the spelling of directories
    shopt -s cdspell
    # append the history file instead of overwriting it
    shopt -s histappend
    # try to complete hostname
    shopt -s hostcomplete
 
    # User specific aliases and functions
    alias rm="rm -i"
    alias mv="mv -i"
    alias cp="cp -i"
    alias vlock="clear; vlock"
    alias emacs="emacs -u $LOGNAME -nw"
    alias e="emacs -u $LOGNAME -nw"
    alias gnus="emacs -u $LOGNAME -nw -f gnus"
    alias rbash="source ~/.bashrc"
    alias lm="tail -n 60 -f /var/log/messages"
    [ -x "$(which ccze)" ] && alias lm="tail -n 60 -f /var/log/messages | ccze"
    [ -x "$(which most)" ] && export PAGER=most ; alias more='most' ; alias less='most'
 
    case "$_OS" in
	Linux)
 
	    if [ "$TERM" != "dumb" ]; then
		if [ -r "~/.dircolors" ]; then
		    eval $(dircolors -b ~/.dircolors)
		else
		    eval $(dircolors -b)
		fi
		alias ls="ls -h --color=auto"
		alias l="ls -lh --color=auto"
	    else
		alias ls="ls -h"
		alias l="ls -lh"
	    fi
 
	    # enabling bash completion if present
	    [ -f /etc/bash_completion ] && source /etc/bash_completion	
	    ;;
 
	FreeBSD)
	    # using colortail if available
	    [ -x "$(which colortail)" ] && alias lm="colortail -n 60 -k /usr/local/share/examples/colortail/conf.messages -f /var/log/messages"
 
	    # GNU ls(1) from FreeBSD ports is named gnuls(1).
	    if [ -x "$(which gnuls)" ]; then 
		if [ "$TERM" != "dumb" ]; then
		    if [ -r "~/.dircolors" ]; then
			eval $(dircolors -b ~/.dircolors)
		    else
			eval $(dircolors -b)
		    fi
		    alias ls="gnuls -h --color=auto"
		    alias l="gnuls -lh --color=auto"
		else
		    alias ls="gnuls -h"
		    alias l="gnuls -lh"
		fi
	    else
		if [ "$TERM" != "dumb" ]; then
		    export LSCOLORS="exfxbxdxcxegedabagacad"
		    alias ls="ls -GFh"
		    alias l="ls -lGFh"
		else
		    alias ls="ls -Fh"
		    alias l="ls -lFh"
		fi
	    fi
	    # enabling bash completion if present
	    [ -f /usr/local/etc/bash_completion ] && source /usr/local/etc/bash_completion
	    ;;
 
	NetBSD|OpenBSD)
	    # GNU ls(1) from OpenBSD ports is named gls(1)/gdircolors(1).
            if [ -x "$(which gdircolors)" ]; then
		if [ -r "~/.dircolors" ]; then
		    eval $(gdircolors -b ~/.dircolors)
		else
		    eval $(gdircolors -b)
		fi
		if [ "$TERM" != "dumb" ]; then
		    alias ls="gls -h --color=auto"
		    alias l="gls -lh --color=auto"
		else
		    alias ls="gls -h"
		    alias l="gls -lh"
		fi
	    # colorls(1) is {Open,Net}BSD port name for FreeBSD ls(1)
	    elif [ -x "$(which colorls)" ]; then 
		if [ "$TERM" != "dumb" ]; then
		    export LSCOLORS="exfxbxdxcxegedabagacad"
		    alias ls="colorls -GFh"
		    alias l="colorls -lGFh"
		else
		    alias ls="colorls -Fh"
		    alias l="colorls -lFh"
		fi
	    else
		alias ls="ls -Fh"
	    fi
 
	    # enabling bash completion if present
	    [ -f /usr/local/etc/bash_completion ] && source /usr/local/etc/bash_completion
	    ;;
    esac
 
    # define some colors
    DEFAULT="\[\033[0;0m\]"
    BLACK="\[\033[0;30m\]"
    LIGHTBLUE="\[\033[0;34m\]"
    LIGHTGREEN="\[\033[0;32m\]"
    LIGHTCYAN="\[\033[0;36m\]"
    LIGHTRED="\[\033[0;31m\]"
    LIGHTPURPLE="\[\033[0;35m\]"
    BROWN="\[\033[0;33m\]"
    DARKGREY="\[\033[1;30m\]"
    LIGHTGREY="\[\033[0;37m\]"
    BLUE="\[\033[1;34m\]"
    GREEN="\[\033[1;32m\]"
    CYAN="\[\033[1;36m\]"
    RED="\[\033[1;31m\]"
    PURPLE="\[\033[1;35m\]"
    YELLOW="\[\033[1;33m\]"
    WHITE="\[\033[1;37m\]"
 
    # define prompt
    USERNAME="$USER"
    if [ "$TERM" != "dumb" ]; then
	if [ "$USERNAME" == "root" ]; then
	    USERNAME="$LIGHTRED$USERNAME"
	fi
	ClrA=$LIGHTCYAN
	ClrB=$DEFAULT
	ClrC=$RED
    else
	ClrA=
	ClrB=
	ClrC=
    fi
    PS1="$ClrA[$ClrB$USERNAME$ClrC@$ClrB\h$ClrA][$ClrB\$(date '+%H:%M')$ClrA]\n[$ClrB\w$ClrA]\n$ClrB>"
    PS2="> "
 
    # undefine vars
    unset _OS USERNAME
    unset DEFAULT BLACK LIGHTBLUE LIGHTGREEN LIGHTCYAN LIGHTRED LIGHTPURPLE
    unset BROWN DARKGREY LIGHTGREY BLUE GREEN CYAN RED PURPLE YELLOW WHITE
    unset ClrA ClrB ClrC
 
    # launching a program after adding its name in current konsole tab
    konsolewrap () {
	if [ "$1" = "-binonly" ]; then
	    cmd=$(basename $2)
	    shift 2
	    dcop $KONSOLE_DCOP_SESSION renameSession "$cmd"
	    $cmd $@
	else
	    cmd=$(basename $1)
	    shift 1
	    dcop $KONSOLE_DCOP_SESSION renameSession "$cmd $*"
	    $cmd $@
	fi
    }
 
    # bypass $KONSOLE_DCOP_SESSION while using su
    konsolesu() {
	dcopref="$KONSOLE_DCOP_SESSION"
	dcop $KONSOLE_DCOP_SESSION renameSession "su $*"
	unset KONSOLE_DCOP_SESSION
	su $@
	export KONSOLE_DCOP_SESSION="$dcopref"
	unset dcopref
    }
 
    # auto-magically set name in konsole tabs
    if [ "$KONSOLE_DCOP_SESSION" ]
	then
	alias ssh='konsolewrap ssh'
	alias lftp='konsolewrap lftp'
	alias sftp='konsolewrap sftp'
	alias su='konsolesu'
	alias ftp='konsolewrap ftp'
	alias scp='konsolewrap -binonly scp'
	alias e='konsolewrap -binonly emacs -u $LOGNAME -nw'
	alias g='konsolewrap gnus'
	alias mutt='konsolewrap mutt'
	alias muttng='konsolewrap muttng'
	alias gnus='konsolewrap gnus'
	alias mplayer='konsolewrap -binonly mplayer'
	alias mc='konsolewrap mc'
	alias man='konsolewrap man'
	alias top='konsolewrap top'
	alias htop='konsolewrap htop'	
 
	PROMPT_COMMAND='dcop $KONSOLE_DCOP_SESSION renameSession "`echo $PWD | sed s,^$HOME,~,`"'
    fi
 
    # auto-magically set name in screen tabs
    function screenwrap() {
	if [ "$1" = "-binonly" ]; then
	    cmd=$(basename $2)
	    shift 2
	    title="$cmd"
	else
	    cmd=$(basename $1)
	    shift 1
	    title="$cmd $@"
	fi
	echo -ne "\033k${title}\033\\"
	$cmd $@
    }
    if [ $TERM = "screen" ]; then
	alias weechat="screenwrap weechat-curses"
	alias weechat-curses="screenwrap weechat-curses"
	alias ssh="screenwrap ssh"
	alias lftp="screenwrap lftp"
	alias sftp="screenwrap sftp"
	alias su="screenwrap su"
	alias ftp="screenwrap ftp"
	alias scp="screenwrap -binonly scp"
	alias emacs="screenwrap -binonly emacs -u $LOGNAME"
	alias e="screenwrap -binonly emacs -u $LOGNAME"
	alias g='screenwrap gnus'
	alias mutt='screenwrap mutt'
	alias muttng='screenwrap muttng'
	alias mplayer="screenwrap -binonly mplayer"
	alias mc="screenwrap mc"
	alias man="screenwrap man"
	alias sudo="screenwrap sudo"
	alias alsamixer="screenwrap alsamixer"
	alias top='screenwrap top'
        alias htop='screenwrap htop'
 
	PROMPT_COMMAND='echo -ne "\033k$(echo -n $PWD | sed s,^$HOME,~,)\033\\"'
    fi
 
    ###############################################
    # WeeChat stuff
    alias weecvs='cvs -z3 -d:ext:kolter@cvs.sv.gnu.org:/sources/weechat'
    # use cvs completion template to complete weecvs command
    complete -F _cvs -o default weecvs
fi
 
config/bashrc/kolter.txt · Dernière modification: 2006/10/26 11:58 (modification externe)