### -*-sh-*- ### ### Description: .profile2 script for GNU Bash. ### Author: Tudor Hulubei ### $Id: .profile2,v 1.1 2005/05/09 17:04:03 tudor Exp $ ### Note: This file is called by .profile only if $SHLVL is 1. ### # Bash configuration. shopt -s cdspell; shopt -s checkhash; shopt -s checkwinsize; shopt -s cmdhist; shopt -s dotglob; shopt -s histappend; shopt -s no_empty_cmd_completion; # Check for the presence of 'less'. type -path less >/dev/null 2>&1; if [ $? -eq 0 ]; then HAVE_LESS=yes; else unset -v HAVE_LESS; fi # Various settings. LESS='-MM'; # `less' options. MAILCHECK=15; # Check the mail every 15 seconds. HISTSIZE=2000; # At most 2000 entries. HISTCONTROL=ignoredups; # No duplicates. FCEDIT=vi; # The editor used by the 'fc' builtin command. IGNOREEOF=0; # Exit at the first EOF. BAUD=38400; # Some editors work better with this. EDITOR=vi; # `vi' is the default editor. TEXTEDIT="$EDITOR"; # Some programs use TEXTEDIT instead. # Arguments for ps. System dependent. if [ x"$OS" = x"Linux" -o x"$OS" = x"ULTRIX" ]; then # Linux, ULTRIX __PS_ARGS='aux'; __PS_LARGS='auxw'; else # HP-UX, SunOS __PS_ARGS='-ef'; __PS_LARGS='-efl'; fi # Pager functions. if [ "$HAVE_LESS" ]; then function pager() { less "$@"; } function more() { less "$@"; } PAGER=less; else function pager() { more "$@"; } PAGER=more; fi # GIT stuff. GIT_PAGER="$PAGER"; GIT_RMAIL="emacs -f vm"; GIT_BROWSER="browser"; # Build a `.tar.gz' archive. function ab() { if [ $# -ne 1 ]; then echo "usage: ab archive"; return 1; fi tar cvpf - "$1" | gzip -9 -c > "$1.tar.gz"; } # Extract a `.tar.gz' or `.tar.Z' archive. function ax() { if [ $# -ne 1 ]; then echo "usage: ax archive"; return 1; fi gitunpack . "$1"; } # Verify the integrity of a `.tar.gz' or `.tar.Z' archive. function av() { if [ $# -ne 1 ]; then echo "usage: av archive"; return 1; fi gunzip -c "$1" | tar tvf -; } # Recursive remove. function rrm() { if [ $# -eq 0 ]; then echo "usage: rrm \'files\'"; return 1; fi find . -name "$1" -print -exec rm -f '{}' \;; } # Find file from the current directory. function ff() { if [ $# -ne 1 ]; then echo "usage: ff \'files\'"; return 1; fi find . -name "$1" -print; } # These ones should be defined carefully, avoiding infinite recursion. if [ x"$OS" = x"Linux" ]; then unset -f df; __DF="`type -path df`"; if [ $? -eq 0 ]; then function df() { "$__DF" -aT "$@"; } fi fi # Kill all the programs that might play sound. function ss() { cdstop 2>/dev/null; killall -KILL raplayer gmod drvmidi wavplay workman xmcd pvftobasic amp\ playmidi splaymidi xplaymidi m3play xamp x11amp gmplayer\ mplayer xmms 2>/dev/null; } # Copy directories across file systems preserving permissions. function cpdir() { if [ $# -ne 2 ]; then echo "usage: cpdir srcdir destdir"; return 1; fi (cd $1 && tar cf - .) | (mkdir "$2"; cd "$2" && tar xvfp -) } # Start `git' and change the directory to the path git was last in. # This won't work if you suspend git. function g() { git -p "$@" 3>/tmp/git.p.$$; if [ -s /tmp/git.p.$$ ]; then if [ -d "`cat /tmp/git.p.$$`" ]; then cd "`cat /tmp/git.p.$$`"; else cd; fi fi rm -f /tmp/git.p.$$; } # Remove all the semaphores. function rmsems() { while read n; do ipcrm sem "$n" >/dev/null 2>&1; done <<- EOF `ipcs -s | cut -d\ -f 2` EOF } # Remove all the shared memory chunks. function rmshms() { while read n; do ipcrm shm "$n" >/dev/null 2>&1; done <<- EOF `ipcs -m | cut -d\ -f 2` EOF } # Remove all the messages. function rmmsgs() { while read n; do ipcrm msg "$n" >/dev/null 2>&1; done <<- EOF `ipcs -q | cut -d\ -f 2` EOF } # Miscelaneous functions. function d() { export DISPLAY="$1":0.0; } function h() { history "$@" | pager; } function j() { jobs -l "$@"; } function k() { kill "$@"; } function ka() { killall "$@"; } function ka9() { killall -9 "$@"; } function n() { browser "$@"; } function m() { make "$@"; } function p() { ps "$__PS_ARGS" "$@" | grep "$USER" | pager; } function pp() { ps "$__PS_ARGS" "$@" | pager; } function pg() { ps "$__PS_LARGS" | grep $1 | grep -v grep; } function qp() { rpm -qa | grep "$1"; } function qf() { rpm -qf "$1"; } function r() { fc -s "$@"; } function ll() { ls -l "$@"; } function la() { ls -a "$@"; } function lla() { ls -la "$@"; } function logs() { tail -f /var/log/messages; } function rnl() { rm -f ~/.netscape/lock; } function rmipcs() { rmsems; rmshms; rmmsgs; } function get() { for variable in "$@"; do set | grep ^"$variable"=; done; } function rgrep() { gitrgrep "$@"; } function rfgrep() { gitrfgrep "$@"; } function regrep() { gitregrep "$@"; } function unix2dos() { recode lat1:ibmpc "$@"; } function dos2unix() { recode ibmpc:lat1 "$@"; } function unix2mac() { recode lat1:applemac "$@"; } function mac2unix() { recode applemac:lat1 "$@"; } function pppon() { ifup ppp0; } function pppoff() { ifdown ppp0; } function e() { type xemacs >/dev/null 2>&1; if [ $? -eq 0 ]; then xemacs "$@"; else type emacs >/dev/null 2>&1; if [ $? -eq 0 ]; then emacs "$@"; else type vi >/dev/null 2>&1; if [ $? -eq 0 ]; then vi "$@"; else echo "bash: e: command not found"; return 127; fi fi fi } function palm_sync() { pilot-xfer -s ~/.palm; } function palm_addr() { pilot-xfer -d AddressDB; echo "Press the \`telephone' button, then HotSync again..."; pilot-addresses -r ~/palm.csv; } # WARNING: Don't execute any program that might output something # unless the standard output is connected to a terminal, otherwise # the entire shell session may be stopped (.profile2 & .profile). # I've noticed this being a problem with scp. --tudor if [ -t 1 ]; then # ALL COMMANDS THAT PRINT STUFF ON THE SCREEN SHOULD GO HERE! if [ -f /proc/apm ]; then apm 2>/dev/null; else if [ -x ~/bin/acpi.sh ]; then ~/bin/acpi.sh; fi fi if [ -t 0 ]; then fortune 2> /dev/null; echo "Happy hacking!"; fi fi