27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

alias vf='cd'<br />

alias moer='more'<br />

alias moew='more'<br />

alias kk='ll'<br />

#−−−−−−−−−−−−−−−−<br />

# a few fun ones<br />

#−−−−−−−−−−−−−−−−<br />

function xtitle ()<br />

{<br />

case "$TERM" in<br />

*term | rxvt)<br />

echo −n −e "\033]0;$*\007" ;;<br />

*)<br />

;;<br />

esac<br />

}<br />

# aliases...<br />

alias top='xtitle Processes on $HOST && top'<br />

alias make='xtitle Making $(basename $PWD) ; make'<br />

alias ncftp="xtitle ncFTP ; ncftp"<br />

# .. and functions<br />

function man ()<br />

{<br />

for i ; do<br />

xtitle The $(basename $1|tr −d .[:digit:]) manual<br />

command man −F −a "$i"<br />

done<br />

}<br />

function ll(){ ls −l "$@"| egrep "^d" ; ls −lXB "$@" 2>&−| egrep −v "^d|total "; }<br />

function te() # wrapper around xemacs/gnuserv<br />

{<br />

if [ "$(gnuclient −batch −eval t 2>&−)" == "t" ]; then<br />

gnuclient −q "$@";<br />

else<br />

( xemacs "$@" &);<br />

fi<br />

}<br />

#−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# File & strings related functions:<br />

#−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

# Find a file with a pattern in name:<br />

function ff() { find . −type f −iname '*'$*'*' −ls ; }<br />

# Find a file with pattern $1 in name and Execute $2 on it:<br />

function fe() { find . −type f −iname '*'$1'*' −exec "${2:−file}" {} \; ; }<br />

# find pattern in a set of filesand highlight them:<br />

function fstr()<br />

{<br />

OPTIND=1<br />

local case=""<br />

local usage="fstr: find string in files.<br />

Usage: fstr [−i] \"pattern\" [\"filename pattern\"] "<br />

while getopts :it opt<br />

do<br />

case "$opt" in<br />

i) case="−i " ;;<br />

Appendix G. A Sample .bashrc File 422

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!