effluvium
mobility
screenshots
hate
obscura
shell
ligature
dissonance
Bashism
My shell of choice is
bash. It is highly customizable and I get along well with the
way it does loops and such.
Prompt
My current bash prompt looks something like this:
mazeone@fester:/home/mazeone/src ->
This is the string in my .bash_profile:
export PS1="\[\e[1;32m\]\u@\h\[\e[0m\]:\[\e[1;34m\]\$(pwd) \[\e[0m\]-> "
I like this prompt because it is fairly simple, and provides me with a line
that I can usually just paste into an scp line. It also goes nicely with the
default dircolors I get from GNU ls.
.bash_profile
.bash_profile is the script that bash sources when it starts a login
shell. I do all my customizing in this script and source it from my
.bashrc if necessary. My .bash_profile isn't all that complex, it
mainly just has some weirdness to deal with the various UNIXes I deal
with regularly:
# minimal path, so we can
find uname
PATH=/bin:/usr/bin
# figure out what UNIX we're running under
UNAME=$(uname)
# these always come first
MYPATH=$HOME/bin:/usr/local/bin
# these usually come next,
but not always (fucking IRIX)
SYSPATH=/usr/bin:/bin:/usr/sbin:/usr/bin/X11
# stupid echo, different
everywhere
# this is where we start customizing stuff for different UNIX
varients
if [ "$UNAME" == "Linux" ]; then
PATH=$MYPATH:$SYSPATH:/usr/X11R6/bin:/usr/games:/usr/local/lib/j2re1.4.1/bin
HOSTNAME="$(/bin/hostname -s)"
ECHO="/bin/echo -en"
FULLNAME="$(uname -a)"
elif [ "$UNAME" == "IRIX" -o "$UNAME" == "IRIX64" ]; then
export PATH=$MYPATH:/usr/freeware/bin:$SYSPATH:/usr/bsd:/usr/etc
export LD_LIBRARY_PATH=/usr/freeware/lib:/usr/freeware/lib32:/usr/freeware/lib64
# in case
we have gnu utils in /usr/freeware...
STTY=/usr/bin/stty
HOSTNAME="$(/usr/bsd/hostname -s)"
$STTY d26:5:d0cbd:b3b:2580:2580:3:1c:7f:15:4:0:0:1a:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:1
ECHO="/bin/echo -n"
# in case
GNU uname is installed
alias uname=/usr/bin/uname
FULLNAME="$(uname -aR)"
elif [ "$UNAME" == "SunOS" ]; then
export PATH=$MYPATH:$SYSPATH:/usr/ucb:/usr/ccs/bin:/usr/openwin/bin
HOSTNAME="$(/usr/bin/hostname)"
ECHO="/bin/echo"
FULLNAME="$(uname -a)"
# oh
solaris, i'm so disappointed...
if [ $TERM="xterm" -o $TERM="xterm-color" ]; then
export TERM=dtterm
fi
fi
# some useful shell options. check the window size, turn on
extended
# globbing, programmable completion and cd spellchecking
shopt -s checkwinsize extglob progcomp cdspell lithist
# some useful shell vars. Ignore some short commands in the history
and
# backup files in globs
export HISTIGNORE='ls:cd:&'
export GLOBIGNORE='*~'
export VISUAL=vi
# i fucking suck
alias mroe=more
alias mr=rm
alias vm=mv
alias sl=ls
# i love rename
alias updown="rename y/A-Z/a-z/ *"
alias nospace="rename 's/ /_/g' *"
alias cleanit="rename 's/[\(,\),\?,\*,\/,\\, ]/_/g' *"
# look for GNU ls, and if we've got it use colors
GNULS=$(ls --version 2>&1 | grep -i "free software foundation")
if [ -n "$GNULS" ]; then
alias ls="ls --color=auto"
fi
# these suck. i would like to do this with 'which; but that's
unreliable
if [ -f /usr/bin/less -o -f /usr/local/bin/less -o -f
/usr/freeware/bin/less ]; then
alias more=less
fi
if [ -f /usr/bin/gtar -o -f /usr/local/bin/gtar -o -f
/usr/freeware/bin/gtar ]; then
alias tar=gtar
fi
if [ -f /usr/bin/vim -o -f /usr/local/bin/vim -o -f
/usr/freeware/bin/vim ]; then
alias vi=vim
fi
# some simple completions. The complicated ones really kill slow
(ie
# pentium-class) machines
if [ "${BASH_VERSION%.*}" \> "2.04" ]; then
complete -a unalias
complete -c command which
complete -A shopt shopt
complete -A export printenv
complete -A directory mkdir rmdir
complete -A directory -o default cd
complete -f -d -X '*.gz' gzip
complete -f -d -X '*.bz2' bzip2
complete -f -o default -X '!*.gz' gunzip
complete -f -o default -X '!*.bz2' bunzip2
# it's all
about ljlane!
complete -W "\`sed 's/[, ].*//'
~/.ssh/known_hosts*\`" ssh
complete -f -W "\`sed 's/[, ].*/:/'
~/.ssh/known_hosts*\`" scp
fi
# where am I? what time is it?
DATE="$(date +'%A, %B %d %I:%M %p %Y AD')"
# rome_date is a goofy script i wrote that shows me the date and
# time in roman numerals/days/years.
if [ -f "$HOME/bin/rome_date.pl" -a -f "$HOME/lib/Roman.pm" ]; then
RDATE="$($HOME/bin/rome_date.pl)"
fi
echo $FULLNAME
echo "$DATE"
if [ -n "$RDATE" ]; then
echo "$RDATE"
fi
# if the terminal can handle it, look at the purty colors.
# if not, suffer.
if [ $TERM = "xterm-color" -o $TERM = "dtterm" -o $TERM = "linux"
];
then
export PS1="\[\e[1;32m\]\u@\h\[\e[0m\]:\[\e[1;34m\]\$(pwd)\[\e[0m\]-> "
else
export PS1="\u@\h:\$(pwd) -> "
fi
# try and set the xterm title to what machine we're on.
if [ $TERM = "xterm" -o $TERM = "xterm-color" -o $TERM = "dtterm" -o
$TERM = "iris-ansi" ]; then
$ECHO "\033]0;$HOSTNAME\007"
fi
# done. go get a sandwich
One-liners
One-liners are probably my favorite thing about Unix shells. I always get annoyed when I sit down at a Windows
box and realize that I can't do anything useful with it...Below is the basic format of 99% of the one-liners I
use:
for i in *\ *; {mv "$i" $(echo $i | sed 's/ /_/g'); }
This script will replace spaces in filenames with underscores for an entire directory. This format can be tweaked like
crazy to do everything.
random bashing
arithmatic: for some reason, i always use perl to do simple arithmatic from the
commandline, even tho bash can do it just fine. The syntax is:
echo $[ <arithmetical expression> ]
history substitution: richlowe pointed
this out to me--I knew that you could use ^foo^bar to replace foo
with bar in the previous command. What I didn't know is that you can do this,
which is much more convenient to type:
!:s/foo/bar/