#!/bin/bash # ------------------------------------------------------------------------------ # Aliases # # --- a bit of fiddling about uname=`uname` [[ `uname` == SunOS && `uname -r` == 5.* ]] && uname=Solaris case "$uname" in SunOS | Solaris) alias pr='/usr/5bin/pr' alias ar='/usr/5bin/ar' # alias ls='/usr/5bin/ls' ;; *) ;; esac # --- standard stuff alias h=history alias a=alias alias d=type alias ll='ls -l' alias lf='ls -aF' alias la='ls -a' # ------------------------------------------------------------------------------ # path manipulation SHOWPATH () { [[ $# == 0 ]] && echo "SHOWPATH colon-paths" && return; echo "$1" | tr : "\n" | ( i=0 while read d; do printf "%3d %s" $i "$d"; [[ -d "$d" ]] || printf " (not found)"; echo ""; i=$((i + 1)) done ); } alias path='SHOWPATH "$PATH"' alias libpath='SHOWPATH "$LD_LIBRARY_PATH"' alias manpath='SHOWPATH "$MANPATH"' ADDPATH () { [[ $# == 0 ]] && echo "ADDPATH env-var new-tails" 1>&2 && return 1; local p="$1"; shift; local IFS=""; export $p=$(buildpath "${!p}" "$@"); } PATHADD () { [[ $# == 0 ]] && echo "PATHADD env-var new-heads" 1>&2 && return 1; local p="$1"; shift; local IFS=""; export $p=$(buildpath "$@" "${!p}"); } alias addpath=ADDPATH alias pathadd=PATHADD REMPATH () { [[ $# == 0 ]] && echo "REMPATH env-var dirs-to-remove" 1>&2 && return 1; local p op d; p="$1"; shift; op="<:${!p}:>"; for d in "$@"; do op=${op//:${d}:/:}; done; op="${op//<:/}"; op="${op/:>/}"; export $p="$op"; } alias rempath=REMPATH alias addcdpath='ADDPATH CDPATH' alias addxpath='ADDPATH PATH' alias addmanpath='ADDPATH MANPATH' alias addlibpath='ADDPATH LD_LIBRARY_PATH' # ------------------------------------------------------------------------------ # --- named-char/hex dump (if you want non-named chars use "od -tcxC" alias xd='od -taxC' alias del='rm -i' alias cls='tput clear' alias cwd='echo $PWD' psf () { ps -ef | grep "$@" | grep -v grep; } psu () { ps -fu "$USER"; } psuf () { ps -fu "$USER" | grep "$@" | grep -v grep; } pskill () { typeset sig='' typeset prn=0 loop=1 while (( loop == 1 )); do case "$1" in -h|--help) exec 1>&2 echo "pskill [-p] [-signal] process-name-pattern" ;; -p) prn=1 ; shift ;; -[0-9]*) sig="$1" ; loop=0 ; shift ;; -[A-Z]*) sig="$1" ; loop=0 ; shift ;; *) break ;; esac done typeset pidno=$( colno=0 set -- `ps -ef | head -1` while [[ $1 != "" ]]; do ((colno += 1)) if [[ $1 == PID ]]; then break; fi shift done echo $colno ) typeset cmdno=$( colno=0 set -- `ps -ef | head -1` while [[ $1 != "" ]]; do ((colno += 1)) if [[ $1 == COMMAND ]]; then break; fi shift done echo $colno ) [[ $prn == 1 ]] && ps -ef | grep "$@" | grep -v grep typeset list=$( ps -ef | grep "$@" | grep -v grep | \ sed -e 's/ */ /g' -e 's/^ //' | \ cut -d' ' -f$pidno | grep -e "^[0-9][0-9]*$" ) echo kill $sig $list } # ------------------------------------------------------------------------------ # --- finding things - file names ff () { find * -name "${1:-*}" -print; } ff. () { find . -name "${1:-*}" -print; } ffl () { find . -name "${1:-*}" -exec ls -ld {} ';'; } fff () { find "$PWD" -name "${1:-*}" -print; } fff. () { find `pwd` -name "${1:-*}" -print; } ffd () { find "$PWD" -type d -name "${1:-*}" -print; } ffr () { local u='usage: ffr start-dir name'; local p="${1:?$u}"; shift; find "$p" -name "${@:?$u}" -print; } ff/ () { find / -name "$1" -print; } # removing files ffrm () { find . -depth -name "$1" -exec rm {} ';'; } ffrmi () { find . -depth -name "$1" -exec rm -i {} ';'; } # executing for all files ffx () { local p="$1"; shift; find . -name "$p" -exec "$@" {} ';'; } # general find things in files: $1 is file pattern, $2-$ are grep things find_prefix='local p="$1"; shift; find . -type f -name "$p" -exec grep' eval 'f () { '"$find_prefix"' -n "$@" {} /dev/null \; ; }' eval 'fI () { '"$find_prefix"' -ni "$@" {} /dev/null \; ; }' eval 'fq () { '"$find_prefix"' -l "$@" {} \; ; }' unset find_prefix # specialised instances for finding things in C source files alias fh="f '*.h'" alias fc="f '*.c'" alias fch="f '*.[ch]'" alias fchi="f '*.[chi]'" alias fh++="f '*.h*'" alias fc++="f '*.c*'" alias fch++="f '*.[chCH]*'" alias fchi++="f '*.[chiCHI]*'" # specialised instances for finding things in C source files - case insensitive alias fih="fI '*.h'" alias fic="fI '*.c'" alias fich="fI '*.[ch]'" alias fichi="fI '*.[chi]'" alias fih++="fI '*.[hH]*'" alias fic++="fI '*.[cC]*'" alias fich++="fI '*.[chCH]*'" alias fichi++="fI '*.[chiCHI]*'" alias fichi++="fI '*.[chiCHI]*'" # finding and editing things # in C files or in all files (in this directory) vif () { p="$1"; shift; vi +/"$p" $(grep -l "$p" "$@"); } vig () { vi +/"$*" $(grep -l "$*" "*.[ch]"); } vigc () { vi +/"$*" $(grep -l "$*" "*.c"); } vigh () { vi +/"$*" $(grep -l "$*" "*.h"); } viga () { vi +/"$*" $(grep -l "$*" "*"); } vig++ () { vi +/"$*" $(grep -l "$*" "*.[chiCHI]*"); } # recursive find and edit aliases vifr () { p="$1"; shift; vi +/"$p" $(fq "$@" "$p"); } vigr () { vi +/"$*" $(fq "*.[ch]" "$*"); } vigrc () { vi +/"$*" $(fq "*.c" "$*"); } vigrh () { vi +/"$*" $(fq "*.h" "$*"); } vigra () { vi +/"$*" $(fq "*" "$*"); } vigr++ () { vi +/"$*" $(fq "*.[chiCHI]*" "$*"); } # --- other stuff display () { export DISPLAY=$1 ; } alias sd='echo export DISPLAY=$DISPLAY' function = () { echo 'scale = 8; ' "$@" | bc -l; } # --- DISPLAY? if [[ -n "$DISPLAY" ]]; then alias ned='nc -noask ' fi # --- use of par - see http://www.nicemice.net/par/ export PARINIT='rTbgqR B=.,?_A_a Q=_s>|' # ------------------------------------------------------------------------------ # Extra aliases # # --- Makes it all a bit slower for aliaspath in ~ ~/.util; do # check out any .aliasrc files if [[ -r $aliaspath/.bashaliasrc ]]; then . $aliaspath/.bashaliasrc fi done unset aliaspath