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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

BLUE='\e[1;34m'<br />

cyan='\e[0;36m'<br />

CYAN='\e[1;36m'<br />

NC='\e[0m'<br />

# No Color<br />

# −−> Nice. Has the same effect as using "ansi.sys" in DOS.<br />

# Looks best on a black background.....<br />

echo −e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}${CYAN} − DISPLAY on ${RED}$DISPLAY${NC}\n"<br />

date<br />

if [ −x /usr/games/fortune ]; then<br />

/usr/games/fortune −s # makes our day a bit more fun.... :−)<br />

fi<br />

function _exit() # function to run upon exit of shell<br />

{<br />

echo −e "${RED}Hasta la vista, baby${NC}"<br />

}<br />

trap _exit EXIT<br />

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

# Shell Prompt<br />

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

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

if [[ "${DISPLAY#$HOST}" != ":0.0" && "${DISPLAY}" != ":0" ]]; then<br />

HILIT=${red} # remote machine: prompt will be partly red<br />

else<br />

HILIT=${cyan} # local machine: prompt will be partly cyan<br />

fi<br />

# −−> Replace instances of \W with \w in prompt functions below<br />

#+ −−> to get display of full path name.<br />

function fastprompt()<br />

{<br />

unset PROMPT_COMMAND<br />

case $TERM in<br />

*term | rxvt )<br />

PS1="${HILIT}[\h]$NC \W > \[\033]0;\${TERM} [\u@\h] \w\007\]" ;;<br />

linux )<br />

PS1="${HILIT}[\h]$NC \W > " ;;<br />

*)<br />

PS1="[\h] \W > " ;;<br />

esac<br />

}<br />

function powerprompt()<br />

{<br />

_powerprompt()<br />

{<br />

LOAD=$(uptime|sed −e "s/.*: \([^,]*\).*/\1/" −e "s/ //g")<br />

}<br />

}<br />

PROMPT_COMMAND=_powerprompt<br />

case $TERM in<br />

*term | rxvt )<br />

PS1="${HILIT}[\A \$LOAD]$NC\n[\h \#] \W > \[\033]0;\${TERM} [\u@\h] \w\007\]" ;;<br />

linux )<br />

PS1="${HILIT}[\A − \$LOAD]$NC\n[\h \#] \w > " ;;<br />

* )<br />

PS1="[\A − \$LOAD]\n[\h \#] \w > " ;;<br />

esac<br />

Appendix G. A Sample .bashrc File 420

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

Saved successfully!

Ooh no, something went wrong!