LDP/LDP/guide/docbook/abs-guide/bashrc

639 lines
18 KiB
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#===============================================================
#
2003-05-12 14:45:05 +00:00
# PERSONAL $HOME/.bashrc FILE for bash-2.05a (or later)
#
# Last modified: Tue Apr 15 20:32:34 CEST 2003
2001-07-10 14:25:50 +00:00
#
# This file is read (normally) by interactive shells only.
# Here is the place to define your aliases, functions and
# other interactive features like your prompt.
2001-10-15 14:21:41 +00:00
#
2003-05-12 14:45:05 +00:00
# This file was designed (originally) for Solaris but based
# on Redhat's default .bashrc file
2001-07-10 14:25:50 +00:00
# --> Modified for Linux.
2003-05-12 14:45:05 +00:00
# The majority of the code you'll find here is based on code found
# on Usenet (or internet).
2001-10-15 14:21:41 +00:00
# This bashrc file is a bit overcrowded - remember it is just
2003-05-12 14:45:05 +00:00
# just an example. Tailor it to your needs
#
2001-07-10 14:25:50 +00:00
#
#===============================================================
# --> Comments added by HOWTO author.
2003-05-12 14:45:05 +00:00
# --> And then edited again by ER :-)
2001-07-10 14:25:50 +00:00
#-----------------------------------
# Source global definitions (if any)
#-----------------------------------
if [ -f /etc/bashrc ]; then
2001-10-15 14:21:41 +00:00
. /etc/bashrc # --> Read /etc/bashrc, if present.
2001-07-10 14:25:50 +00:00
fi
#-------------------------------------------------------------
# Automatic setting of $DISPLAY (if not set already)
2003-05-12 14:45:05 +00:00
# This works for linux - your mileage may vary....
# The problem is that different types of terminals give
# different answers to 'who am i'......
# I have not found a 'universal' method yet
2001-07-10 14:25:50 +00:00
#-------------------------------------------------------------
2003-05-12 14:45:05 +00:00
function get_xserver ()
{
case $TERM in
xterm )
XSERVER=$(who am i | awk '{print $NF}' | tr -d ')''(' )
XSERVER=${XSERVER%%:*}
;;
aterm | rxvt)
# find some code that works here.....
;;
esac
}
2001-07-10 14:25:50 +00:00
if [ -z ${DISPLAY:=""} ]; then
2003-05-12 14:45:05 +00:00
get_xserver
if [[ -z ${XSERVER} || ${XSERVER} == $(hostname) || ${XSERVER} == "unix" ]]; then
DISPLAY=":0.0" # Display on local host
else
DISPLAY=${XSERVER}:0.0 # Display on remote host
2001-07-10 14:25:50 +00:00
fi
fi
2003-05-12 14:45:05 +00:00
export DISPLAY
2001-07-10 14:25:50 +00:00
#---------------
# Some settings
#---------------
2003-05-12 14:45:05 +00:00
ulimit -S -c 0 # Don't want any coredumps
2001-07-10 14:25:50 +00:00
set -o notify
set -o noclobber
set -o ignoreeof
set -o nounset
2001-10-15 14:21:41 +00:00
#set -o xtrace # useful for debuging
2001-07-10 14:25:50 +00:00
2003-05-12 14:45:05 +00:00
# Enable options:
2001-10-15 14:21:41 +00:00
shopt -s cdspell
2001-07-10 14:25:50 +00:00
shopt -s cdable_vars
2001-10-15 14:21:41 +00:00
shopt -s checkhash
shopt -s checkwinsize
2001-07-10 14:25:50 +00:00
shopt -s mailwarn
shopt -s sourcepath
2003-05-12 14:45:05 +00:00
shopt -s no_empty_cmd_completion # bash>=2.04 only
shopt -s cmdhist
shopt -s histappend histreedit histverify
shopt -s extglob # necessary for programmable completion
# Disable options:
shopt -u mailwarn
unset MAILCHECK # I don't want my shell to warn me of incoming mail
export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n'
export HISTIGNORE="&:bg:fg:ll:h"
export HOSTFILE=$HOME/.hosts # Put a list of remote hosts in ~/.hosts
2001-07-10 14:25:50 +00:00
#-----------------------
# Greeting, motd etc...
#-----------------------
# Define some colors first:
red='\e[0;31m'
RED='\e[1;31m'
blue='\e[0;34m'
BLUE='\e[1;34m'
cyan='\e[0;36m'
CYAN='\e[1;36m'
2001-10-15 14:21:41 +00:00
NC='\e[0m' # No Color
2001-07-10 14:25:50 +00:00
# --> Nice. Has the same effect as using "ansi.sys" in DOS.
# Looks best on a black background.....
echo -e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}${CYAN} - DISPLAY on ${RED}$DISPLAY${NC}\n"
date
2003-05-12 14:45:05 +00:00
if [ -x /usr/games/fortune ]; then
2001-10-15 14:21:41 +00:00
/usr/games/fortune -s # makes our day a bit more fun.... :-)
fi
2001-07-10 14:25:50 +00:00
2003-05-12 14:45:05 +00:00
function _exit() # function to run upon exit of shell
2001-07-10 14:25:50 +00:00
{
echo -e "${RED}Hasta la vista, baby${NC}"
}
2003-05-12 14:45:05 +00:00
trap _exit EXIT
2001-07-10 14:25:50 +00:00
#---------------
2003-05-12 14:45:05 +00:00
# Shell Prompt
2001-07-10 14:25:50 +00:00
#---------------
2003-05-12 14:45:05 +00:00
if [[ "${DISPLAY#$HOST}" != ":0.0" && "${DISPLAY}" != ":0" ]]; then
HILIT=${red} # remote machine: prompt will be partly red
else
HILIT=${cyan} # local machine: prompt will be partly cyan
fi
# --> Replace instances of \W with \w in prompt functions below
#+ --> to get display of full path name.
2001-07-10 14:25:50 +00:00
function fastprompt()
{
unset PROMPT_COMMAND
case $TERM in
2001-10-15 14:21:41 +00:00
*term | rxvt )
2003-05-12 14:45:05 +00:00
PS1="${HILIT}[\h]$NC \W > \[\033]0;\${TERM} [\u@\h] \w\007\]" ;;
linux )
PS1="${HILIT}[\h]$NC \W > " ;;
2001-10-15 14:21:41 +00:00
*)
PS1="[\h] \W > " ;;
2001-07-10 14:25:50 +00:00
esac
}
function powerprompt()
{
2001-10-15 14:21:41 +00:00
_powerprompt()
{
LOAD=$(uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g")
}
2001-07-10 14:25:50 +00:00
PROMPT_COMMAND=_powerprompt
case $TERM in
2001-10-15 14:21:41 +00:00
*term | rxvt )
2003-05-12 14:45:05 +00:00
PS1="${HILIT}[\A \$LOAD]$NC\n[\h \#] \W > \[\033]0;\${TERM} [\u@\h] \w\007\]" ;;
2001-10-15 14:21:41 +00:00
linux )
2003-05-12 14:45:05 +00:00
PS1="${HILIT}[\A - \$LOAD]$NC\n[\h \#] \w > " ;;
2001-10-15 14:21:41 +00:00
* )
2003-05-12 14:45:05 +00:00
PS1="[\A - \$LOAD]\n[\h \#] \w > " ;;
2001-07-10 14:25:50 +00:00
esac
}
2001-10-15 14:21:41 +00:00
powerprompt # this is the default prompt - might be slow
# If too slow, use fastprompt instead....
2001-07-10 14:25:50 +00:00
#===============================================================
#
2001-10-15 14:21:41 +00:00
# ALIASES AND FUNCTIONS
2001-07-10 14:25:50 +00:00
#
2001-10-15 14:21:41 +00:00
# Arguably, some functions defined here are quite big
2001-07-10 14:25:50 +00:00
# (ie 'lowercase') but my workstation has 512Meg of RAM, so .....
# If you want to make this file smaller, these functions can
# be converted into scripts.
2001-10-15 14:21:41 +00:00
#
2001-07-10 14:25:50 +00:00
# Many functions were taken (almost) straight from the bash-2.04
# examples.
#
#===============================================================
#-------------------
# Personnal Aliases
#-------------------
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# -> Prevents accidentally clobbering files.
2003-05-12 14:45:05 +00:00
alias mkdir='mkdir -p'
2001-07-10 14:25:50 +00:00
alias h='history'
alias j='jobs -l'
alias r='rlogin'
2001-10-15 14:21:41 +00:00
alias which='type -all'
2001-07-10 14:25:50 +00:00
alias ..='cd ..'
alias path='echo -e ${PATH//:/\\n}'
2003-05-12 14:45:05 +00:00
alias print='/usr/bin/lp -o nobanner -d $LPDEST' # Assumes LPDEST is defined
2001-10-15 14:21:41 +00:00
alias pjet='enscript -h -G -fCourier9 -d $LPDEST' # Pretty-print using enscript
2003-05-12 14:45:05 +00:00
alias background='xv -root -quit -max -rmode 5' # Put a picture in the background
alias du='du -kh'
alias df='df -kTh'
2001-07-10 14:25:50 +00:00
2001-10-15 14:21:41 +00:00
# The 'ls' family (this assumes you use the GNU ls)
2003-05-12 14:45:05 +00:00
alias la='ls -Al' # show hidden files
2001-10-15 14:21:41 +00:00
alias ls='ls -hF --color' # add colors for filetype recognition
2003-05-12 14:45:05 +00:00
alias lx='ls -lXB' # sort by extension
alias lk='ls -lSr' # sort by size
alias lc='ls -lcr' # sort by change time
alias lu='ls -lur' # sort by access time
alias lr='ls -lR' # recursive ls
alias lt='ls -ltr' # sort by date
alias lm='ls -al |more' # pipe through 'more'
alias tree='tree -Csu' # nice alternative to 'ls'
2001-07-10 14:25:50 +00:00
2001-10-15 14:21:41 +00:00
# tailoring 'less'
2001-07-10 14:25:50 +00:00
alias more='less'
export PAGER=less
export LESSCHARSET='latin1'
2001-10-15 14:21:41 +00:00
export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' # Use this if lesspipe.sh exists
2001-07-10 14:25:50 +00:00
export LESS='-i -N -w -z-4 -g -e -M -X -F -R -P%t?f%f \
:stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...'
2001-10-15 14:21:41 +00:00
# spelling typos - highly personnal :-)
2001-07-10 14:25:50 +00:00
alias xs='cd'
alias vf='cd'
alias moer='more'
alias moew='more'
alias kk='ll'
#----------------
# a few fun ones
#----------------
2001-10-15 14:21:41 +00:00
function xtitle ()
{
2003-05-12 14:45:05 +00:00
case "$TERM" in
2001-10-15 14:21:41 +00:00
*term | rxvt)
echo -n -e "\033]0;$*\007" ;;
2003-05-12 14:45:05 +00:00
*)
;;
2001-07-10 14:25:50 +00:00
esac
}
2001-10-15 14:21:41 +00:00
# aliases...
2001-07-10 14:25:50 +00:00
alias top='xtitle Processes on $HOST && top'
alias make='xtitle Making $(basename $PWD) ; make'
alias ncftp="xtitle ncFTP ; ncftp"
2003-05-12 14:45:05 +00:00
# .. and functions
2001-07-10 14:25:50 +00:00
function man ()
{
2003-05-12 14:45:05 +00:00
for i ; do
xtitle The $(basename $1|tr -d .[:digit:]) manual
command man -F -a "$i"
done
2001-07-10 14:25:50 +00:00
}
2001-10-15 14:21:41 +00:00
function ll(){ ls -l "$@"| egrep "^d" ; ls -lXB "$@" 2>&-| egrep -v "^d|total "; }
2001-07-10 14:25:50 +00:00
function te() # wrapper around xemacs/gnuserv
{
if [ "$(gnuclient -batch -eval t 2>&-)" == "t" ]; then
2001-10-15 14:21:41 +00:00
gnuclient -q "$@";
2001-07-10 14:25:50 +00:00
else
2003-05-12 14:45:05 +00:00
( xemacs "$@" &);
2001-07-10 14:25:50 +00:00
fi
}
#-----------------------------------
# File & strings related functions:
#-----------------------------------
2003-05-12 14:45:05 +00:00
# Find a file with a pattern in name:
function ff() { find . -type f -iname '*'$*'*' -ls ; }
# Find a file with pattern $1 in name and Execute $2 on it:
function fe() { find . -type f -iname '*'$1'*' -exec "${2:-file}" {} \; ; }
# find pattern in a set of filesand highlight them:
function fstr()
2001-07-10 14:25:50 +00:00
{
2003-05-12 14:45:05 +00:00
OPTIND=1
local case=""
local usage="fstr: find string in files.
Usage: fstr [-i] \"pattern\" [\"filename pattern\"] "
while getopts :it opt
do
case "$opt" in
i) case="-i " ;;
*) echo "$usage"; return;;
esac
done
shift $(( $OPTIND - 1 ))
if [ "$#" -lt 1 ]; then
echo "$usage"
2001-10-15 14:21:41 +00:00
return;
2001-07-10 14:25:50 +00:00
fi
2003-05-12 14:45:05 +00:00
local SMSO=$(tput smso)
local RMSO=$(tput rmso)
find . -type f -name "${2:-*}" -print0 | xargs -0 grep -sn ${case} "$1" 2>&- | \
sed "s/$1/${SMSO}\0${RMSO}/gI" | more
2001-07-10 14:25:50 +00:00
}
2001-10-15 14:21:41 +00:00
2001-07-10 14:25:50 +00:00
function cuttail() # cut last n lines in file, 10 by default
{
nlines=${2:-10}
2001-10-15 14:21:41 +00:00
sed -n -e :a -e "1,${nlines}!{P;N;D;};N;ba" $1
2001-07-10 14:25:50 +00:00
}
function lowercase() # move filenames to lowercase
{
for file ; do
filename=${file##*/}
case "$filename" in
*/*) dirname==${file%/*} ;;
*) dirname=.;;
esac
nf=$(echo $filename | tr A-Z a-z)
newname="${dirname}/${nf}"
if [ "$nf" != "$filename" ]; then
mv "$file" "$newname"
echo "lowercase: $file --> $newname"
else
echo "lowercase: $file not changed."
fi
done
}
2001-10-15 14:21:41 +00:00
function swap() # swap 2 filenames around
2001-07-10 14:25:50 +00:00
{
local TMPFILE=tmp.$$
2003-05-12 14:45:05 +00:00
mv "$1" $TMPFILE
mv "$2" "$1"
mv $TMPFILE "$2"
2001-07-10 14:25:50 +00:00
}
2003-05-12 14:45:05 +00:00
2001-10-15 14:21:41 +00:00
#-----------------------------------
# Process/system related functions:
#-----------------------------------
function my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; }
function pp() { my_ps f | awk '!/awk/ && $0~var' var=${1:-".*"} ; }
# This function is roughly the same as 'killall' on linux
# but has no equivalent (that I know of) on Solaris
function killps() # kill by process name
{
local pid pname sig="-TERM" # default signal
2003-05-12 14:45:05 +00:00
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "Usage: killps [-SIGNAL] pattern"
return;
2001-10-15 14:21:41 +00:00
fi
if [ $# = 2 ]; then sig=$1 ; fi
for pid in $(my_ps| awk '!/awk/ && $0~pat { print $1 }' pat=${!#} ) ; do
2003-05-12 14:45:05 +00:00
pname=$(my_ps | awk '$1~var { print $5 }' var=$pid )
if ask "Kill process $pid <$pname> with signal $sig?"
then kill $sig $pid
fi
2001-10-15 14:21:41 +00:00
done
}
function my_ip() # get IP adresses
{
MY_IP=$(/sbin/ifconfig ppp0 | awk '/inet/ { print $2 } ' | sed -e s/addr://)
MY_ISP=$(/sbin/ifconfig ppp0 | awk '/P-t-P/ { print $3 } ' | sed -e s/P-t-P://)
}
function ii() # get current host related info
{
echo -e "\nYou are logged on ${RED}$HOST"
echo -e "\nAdditionnal information:$NC " ; uname -a
echo -e "\n${RED}Users logged on:$NC " ; w -h
echo -e "\n${RED}Current date :$NC " ; date
echo -e "\n${RED}Machine stats :$NC " ; uptime
echo -e "\n${RED}Memory stats :$NC " ; free
my_ip 2>&- ;
echo -e "\n${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"}
echo -e "\n${RED}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"}
echo
}
2001-07-10 14:25:50 +00:00
# Misc utilities:
2001-10-15 14:21:41 +00:00
function repeat() # repeat n times command
2001-07-10 14:25:50 +00:00
{
local i max
max=$1; shift;
for ((i=1; i <= max ; i++)); do # --> C-like syntax
2001-10-15 14:21:41 +00:00
eval "$@";
2001-07-10 14:25:50 +00:00
done
}
2001-10-15 14:21:41 +00:00
2001-07-10 14:25:50 +00:00
function ask()
{
echo -n "$@" '[y/n] ' ; read ans
case "$ans" in
y*|Y*) return 0 ;;
*) return 1 ;;
esac
}
#=========================================================================
#
2001-10-15 14:21:41 +00:00
# PROGRAMMABLE COMPLETION - ONLY SINCE BASH-2.04
2003-05-12 14:45:05 +00:00
# Most are taken from the bash 2.05 documentation and from Ian McDonalds
# 'Bash completion' package (http://www.caliban.org/bash/index.shtml#completion)
# You will in fact need bash-2.05a for some features
2001-07-10 14:25:50 +00:00
#
#=========================================================================
2001-10-15 14:21:41 +00:00
if [ "${BASH_VERSION%.*}" \< "2.05" ]; then
echo "You will need to upgrade to version 2.05 for programmable completion"
2001-07-10 14:25:50 +00:00
return
fi
2001-10-15 14:21:41 +00:00
shopt -s extglob # necessary
2003-05-12 14:45:05 +00:00
set +o nounset # otherwise some completions will fail
2001-07-10 14:25:50 +00:00
complete -A hostname rsh rcp telnet rlogin r ftp ping disk
complete -A export printenv
complete -A variable export local readonly unset
complete -A enabled builtin
complete -A alias alias unalias
complete -A function function
complete -A user su mail finger
2001-10-15 14:21:41 +00:00
complete -A helptopic help # currently same as builtins
2001-07-10 14:25:50 +00:00
complete -A shopt shopt
complete -A stopped -P '%' bg
complete -A job -P '%' fg jobs disown
complete -A directory mkdir rmdir
2001-10-15 14:21:41 +00:00
complete -A directory -o default cd
2003-05-12 14:45:05 +00:00
# Compression
complete -f -o default -X '*.+(zip|ZIP)' zip
complete -f -o default -X '!*.+(zip|ZIP)' unzip
complete -f -o default -X '*.+(z|Z)' compress
complete -f -o default -X '!*.+(z|Z)' uncompress
complete -f -o default -X '*.+(gz|GZ)' gzip
complete -f -o default -X '!*.+(gz|GZ)' gunzip
complete -f -o default -X '*.+(bz2|BZ2)' bzip2
complete -f -o default -X '!*.+(bz2|BZ2)' bunzip2
# Postscript,pdf,dvi.....
2001-10-15 14:21:41 +00:00
complete -f -o default -X '!*.ps' gs ghostview ps2pdf ps2ascii
complete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitype
2003-05-12 14:45:05 +00:00
complete -f -o default -X '!*.pdf' acroread pdf2ps
complete -f -o default -X '!*.+(pdf|ps)' gv
2001-10-15 14:21:41 +00:00
complete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf
2003-05-12 14:45:05 +00:00
complete -f -o default -X '!*.tex' tex latex slitex
complete -f -o default -X '!*.lyx' lyx
complete -f -o default -X '!*.+(htm*|HTM*)' lynx html2ps
# Multimedia
complete -f -o default -X '!*.+(jp*g|gif|xpm|png|bmp)' xv gimp
complete -f -o default -X '!*.+(mp3|MP3)' mpg123 mpg321
complete -f -o default -X '!*.+(ogg|OGG)' ogg123
2001-10-15 14:21:41 +00:00
2003-05-12 14:45:05 +00:00
complete -f -o default -X '!*.pl' perl perl5
2001-10-15 14:21:41 +00:00
# This is a 'universal' completion function - it works when commands have
2003-05-12 14:45:05 +00:00
# a so-called 'long options' mode , ie: 'ls --all' instead of 'ls -a'
_get_longopts ()
{
$1 --help | sed -e '/--/!d' -e 's/.*--\([^[:space:].,]*\).*/--\1/'| \
grep ^"$2" |sort -u ;
}
_longopts_func ()
2001-10-15 14:21:41 +00:00
{
2003-05-12 14:45:05 +00:00
case "${2:-*}" in
2001-10-15 14:21:41 +00:00
-*) ;;
*) return ;;
esac
case "$1" in
2003-05-12 14:45:05 +00:00
\~*) eval cmd="$1" ;;
2001-10-15 14:21:41 +00:00
*) cmd="$1" ;;
esac
2003-05-12 14:45:05 +00:00
COMPREPLY=( $(_get_longopts ${1} ${2} ) )
2001-10-15 14:21:41 +00:00
}
2003-05-12 14:45:05 +00:00
complete -o default -F _longopts_func configure bash
complete -o default -F _longopts_func wget id info a2ps ls recode
2001-07-10 14:25:50 +00:00
_make_targets ()
{
local mdef makef gcmd cur prev i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# if prev argument is -f, return possible filename completions.
# we could be a little smarter here and return matches against
# `makefile Makefile *.mk', whatever exists
case "$prev" in
2001-10-15 14:21:41 +00:00
-*f) COMPREPLY=( $(compgen -f $cur ) ); return 0;;
2001-07-10 14:25:50 +00:00
esac
# if we want an option, return the possible posix options
case "$cur" in
2001-10-15 14:21:41 +00:00
-) COMPREPLY=(-e -f -i -k -n -p -q -r -S -s -t); return 0;;
2001-07-10 14:25:50 +00:00
esac
# make reads `makefile' before `Makefile'
if [ -f makefile ]; then
2001-10-15 14:21:41 +00:00
mdef=makefile
2001-07-10 14:25:50 +00:00
elif [ -f Makefile ]; then
2001-10-15 14:21:41 +00:00
mdef=Makefile
2001-07-10 14:25:50 +00:00
else
2001-10-15 14:21:41 +00:00
mdef=*.mk # local convention
2001-07-10 14:25:50 +00:00
fi
# before we scan for targets, see if a makefile name was specified
# with -f
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
2001-10-15 14:21:41 +00:00
if [[ ${COMP_WORDS[i]} == -*f ]]; then
eval makef=${COMP_WORDS[i+1]} # eval for tilde expansion
break
fi
2001-07-10 14:25:50 +00:00
done
2001-10-15 14:21:41 +00:00
[ -z "$makef" ] && makef=$mdef
2001-07-10 14:25:50 +00:00
# if we have a partial word to complete, restrict completions to
# matches of that word
if [ -n "$2" ]; then gcmd='grep "^$2"' ; else gcmd=cat ; fi
# if we don't want to use *.mk, we can take out the cat and use
2001-10-15 14:21:41 +00:00
# test -f $makef and input redirection
COMPREPLY=( $(cat $makef 2>/dev/null | awk 'BEGIN {FS=":"} /^[^.# ][^=]*:/ {print $1}' | tr -s ' ' '\012' | sort -u | eval $gcmd ) )
2001-07-10 14:25:50 +00:00
}
complete -F _make_targets -X '+($*|*.[cho])' make gmake pmake
2001-10-15 14:21:41 +00:00
# cvs(1) completion
_cvs ()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD -eq 1 ] || [ "${prev:0:1}" = "-" ]; then
2003-05-12 14:45:05 +00:00
COMPREPLY=( $( compgen -W 'add admin checkout commit diff \
export history import log rdiff release remove rtag status \
tag update' $cur ))
2001-10-15 14:21:41 +00:00
else
2003-05-12 14:45:05 +00:00
COMPREPLY=( $( compgen -f $cur ))
2001-10-15 14:21:41 +00:00
fi
return 0
}
complete -F _cvs cvs
2001-07-10 14:25:50 +00:00
_killall ()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# get a list of processes (the first sed evaluation
# takes care of swapped out processes, the second
# takes care of getting the basename of the process)
COMPREPLY=( $( /usr/bin/ps -u $USER -o comm | \
2001-10-15 14:21:41 +00:00
sed -e '1,1d' -e 's#[]\[]##g' -e 's#^.*/##'| \
awk '{if ($0 ~ /^'$cur'/) print $0}' ))
2001-07-10 14:25:50 +00:00
return 0
}
2001-10-15 14:21:41 +00:00
complete -F _killall killall killps
2001-07-10 14:25:50 +00:00
2003-05-12 14:45:05 +00:00
# A meta-command completion function for commands like sudo(8), which need to
# first complete on a command, then complete according to that command's own
# completion definition - currently not quite foolproof (e.g. mount and umount
# don't work properly), but still quite useful - By Ian McDonald, modified by me.
_my_command()
{
local cur func cline cspec
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
if [ $COMP_CWORD = 1 ]; then
COMPREPLY=( $( compgen -c $cur ) )
elif complete -p ${COMP_WORDS[1]} &>/dev/null; then
cspec=$( complete -p ${COMP_WORDS[1]} )
if [ "${cspec%%-F *}" != "${cspec}" ]; then
# complete -F &lt;function&gt;
#
# COMP_CWORD and COMP_WORDS() are not read-only,
# so we can set them before handing off to regular
# completion routine
# set current token number to 1 less than now
COMP_CWORD=$(( $COMP_CWORD - 1 ))
# get function name
func=${cspec#*-F }
func=${func%% *}
# get current command line minus initial command
cline="${COMP_LINE#$1 }"
# split current command line tokens into array
COMP_WORDS=( $cline )
$func $cline
elif [ "${cspec#*-[abcdefgjkvu]}" != "" ]; then
# complete -[abcdefgjkvu]
#func=$( echo $cspec | sed -e 's/^.*\(-[abcdefgjkvu]\).*$/\1/' )
func=$( echo $cspec | sed -e 's/^complete//' -e 's/[^ ]*$//' )
COMPREPLY=( $( eval compgen $func $cur ) )
elif [ "${cspec#*-A}" != "$cspec" ]; then
# complete -A &lt;type&gt;
func=${cspec#*-A }
func=${func%% *}
COMPREPLY=( $( compgen -A $func $cur ) )
fi
else
COMPREPLY=( $( compgen -f $cur ) )
fi
}
complete -o default -F _my_command nohup exec eval trace truss strace sotruss gdb
complete -o default -F _my_command command type which man nice
2001-07-10 14:25:50 +00:00
# Local Variables:
# mode:shell-script
# sh-shell:bash
2001-10-15 14:21:41 +00:00
# End: