[auton-users] handy shell aliases
Dan Pelleg
dpelleg+ at cs.cmu.edu
Tue Oct 29 09:26:00 EST 2002
Here's a short guide to set up convenient shell aliases to reduce typing.
I believe I've posted most of this before, but I'm doing it again because
there are new people in the lab, and to make sure it's archived (btw, the
list's archives are now linked from the lab's web page).
Before we begin: if you don't know which shell you're using, then it's
probably tcsh if you're on a SCS-facilitized machine, bash if you're on
other GNU/Linux machines. Type "echo $SHELL" and look at the last component
to find out. I'll provide instructions for both.
***
First trick: tab-completion for host names. You probably know you can hit
"tab" for the shell to auto-complete a file name you've started
typing. We'll do the same for hostname so you can type something like:
ssh lok<TAB>
and have it auto-complete to
ssh loki.auton.cs.cmu.edu
==============================tcsh: add this to ~/.login:
set hostnames = (gs166.sp.cs.cmu.edu loki.auton.cs.cmu.edu liver.auton.cs.cmu.edu)
complete ssh 'p/*/$hostnames/'
complete ping 'p/*/$hostnames/'
complete xss 'p/*/$hostnames/'
complete ftp 'p/1/$hostnames/'
complete scp 'p/*/$hostnames/'
complete traceroute 'p/*/$hostnames/'
========================================
------------------------------bash: add this to ~/.bash_login:
hostnames="{gs166,lamp,loop,limp,leem,ux7}.sp.cs.cmu.edu \
{limey,lazy,liver,loki,loon,lank,like}.auton.cs.cmu.edu"
complete -W "$hostnames" ssh ping host xss ftp traceroute
----------------------------------------
***
Second trick:
Add an alias "xss" that, once called with a host name:
- starts up a new xterm window
- sets the window's title to the name of the host
- in that window, ssh-es to that host
==============================tcsh: add to ~/.login
alias xss "xterm -T \!^ -e ssh -X \!^ &"
==============================
------------------------------bash: add to ~/.bash_login:
function xss() {
xterm -T $1 -e ssh -X $1 &
}
----------------------------------------
***
saw-woman-in-half trick:
Add tab-completion to CVS commands. So you can type "cvs co<TAB>" and have
it auto-complete to "cvs commit", saving you a total of THREE KEYSTROKES.
==============================tcsh
complete cvs \
'p/1/(add annotate checkout commit diff edit editors export\
history import init log login logout rdiff release remove rtag\
status tag unedit update watch watchers)/'\
'n/{add,commit,log,diff,status}/f/'\
'n/checkout/d/'
========================================
------------------------------bash
complete -F complete_cvs cvs
# completion for "cvs"
function complete_cvs() {
# when we're called, we have COMP_WORDS the string array with
# the current line in it, and COMP_CWORD pointing to the currently
# edited (completing) word in it
# we return the list of possible completions in the
# array COMPREPLY
#
# the first word should be "cvs"
# are we called to complete the second word? - suggest
# the CVS commands
if [[ ${COMP_CWORD} -eq 1 ]]; then
COMPREPLY=( `compgen -W "add annotate checkout commit diff edit editors export\
history import init log login logout rdiff release remove rtag\
status tag unedit update watch watchers" ${COMP_WORDS[$COMP_CWORD]}` )
# are we called to complete the third word? - suggest
# some files
elif [[ ${COMP_CWORD} -eq 2 ]]; then
# decide whether to suggest files or directories
case ${COMP_WORDS[$COMP_CWORD]} in
add | commit | log | diff | status )
list=f # files
;;
checkout)
list=d # directories
;;
*)
list=f # files
;;
esac
COMPREPLY=( `compgen -$list ${COMP_WORDS[$COMP_CWORD]}` )
fi
}
----------------------------------------
Note I only said "saw in half". You didn't want your wife back in one
piece, now did you?
--
Dan Pelleg
More information about the Autonlab-users
mailing list