Register
It is currently Fri Oct 31, 2014 7:33 am

Cool Functions for your .bashrc file.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 9 posts ] 
Author Message
 PostPosted: Tue Feb 13, 2007 10:23 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
These were originally designed as bbot modules for the bash bot, but I decided that they would
work fine for your .bashrc file as well..... and they do ;) Sorry for the REALLY wide post.....but wanted
to make sure that if you cut-n-paste the code would work. The line starting WEATHERARRAY is REALLY long
and the next line starts with echo ${WEATHERARRAY[@]} .

weather ()
stock ()
translate ()
define ()

Probably these are self explanatory but just in case they are not......

weather
Weather by us zip code - Can be called two ways # weather 50315 # weather
"Des Moines"

[14:33:09 crouse]$ weather 50317
Weather for Pleasant Hill, IA 19F Light Snow Wind: N at 16 mph Humidity: 80%
[~]
[14:39:35 crouse]$ weather "Des Moines"
Weather for Des Moines, IA 19F Blowing Snow Wind: N at 21 mph Humidity: 74%
[~]
[14:40:03 crouse]$

-----------------------

stock
Stock prices - can be called two ways. # stock novl (this shows stock
pricing) #stock "novell" (this way shows stock symbol for novell)

[14:39:25 crouse]$ stock "novell"
NOVL NOVELL INC NasdaqGS Security Software & Services
[~]
[14:39:32 crouse]$ stock novl
NOVELL INC (NasdaqGS:NOVL) - delayed quote.
Last Trade: 7.10 Change: 0.00 (0.00%) 52wk Range: 5.70 - 9.83
[~]
[14:39:35 crouse]$

-----------------------

translate
Translate a Word - USAGE: translate house spanish # See dictionary.com
for available languages (there are many).

[~]
[14:40:03 crouse]$ translate house spanish
"house" in Spanish: casa
[~]
[14:40:52 crouse]$ translate house german
"house" in German: das Haus
[~]
[14:40:59 crouse]$ translate house french
"house" in French: maison
[~]
[14:41:06 crouse]$

-----------------------

define
Define a word - USAGE: define dog

[~]
[14:41:06 crouse]$ define dog
* a member of the genus Canis (probably descended from the common
* frump: a dull unattractive unpleasant girl or woman
* informal term for a man
[~]
[14:41:47 crouse]$ define canine
* of or relating to a pointed conical tooth
* one of the four pointed conical teeth (two in each jaw) located
* any of various fissiped mammals with nonretractile claws and
[~]
[14:41:54 crouse]$


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
# <--------- Cool Functions by Crouse-------->
# Cool Functions for your .bashrc file.

# Weather by us zip code - Can be called two ways # weather 50315 # weather "Des Moines"
weather ()
{
declare -a WEATHERARRAY
WEATHERARRAY=( `lynx -dump "http://www.google.com/search?hl=en&lr=&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=weather+${1}&btnG=Search" | grep -A 5 -m 1 "Weather for" | grep -v "Add to "`)
echo ${WEATHERARRAY[@]}
}

# Stock prices - can be called two ways. # stock novl  (this shows stock pricing)  #stock "novell"  (this way shows stock symbol for novell)
stock ()
{
stockname=`lynx -dump http://finance.yahoo.com/q?s=${1} | grep -i ":${1})" | sed -e 's/Delayed.*$//'`
stockadvise="${stockname} - delayed quote."
declare -a STOCKINFO
STOCKINFO=(` lynx -dump http://finance.yahoo.com/q?s=${1} | egrep -i "Last Trade:|Change:|52wk Range:"`)
stockdata=`echo ${STOCKINFO[@]}`
   if [[ ${#stockname} != 0 ]] ;then
      echo "${stockadvise}"
      echo "${stockdata}"
         else
         stockname2=${1}
         lookupsymbol=`lynx -dump -nolist http://finance.yahoo.com/lookup?s="${1}" | grep -A 1 -m 1 "Portfolio" | grep -v "Portfolio" | sed 's/\(.*\)Add/\1 /'`
            if [[ ${#lookupsymbol} != 0 ]] ;then
            echo "${lookupsymbol}"
               else
               echo "Sorry $USER, I can not find ${1}."
            fi
   fi
}

#Translate a Word  - USAGE: translate house spanish  # See dictionary.com for available languages (there are many).
translate ()
{
TRANSLATED=`lynx -dump "http://dictionary.reference.com/browse/${1}" | grep -i -m 1 -w "${2}:" | sed 's/^[ \t]*//;s/[ \t]*$//'`
if [[ ${#TRANSLATED} != 0 ]] ;then
   echo "\"${1}\" in ${TRANSLATED}"
   else
   echo "Sorry, I can not translate \"${1}\" to ${2}"
fi
}

# Define a word - USAGE: define dog
define ()
{
lynx -dump "http://www.google.com/search?hl=en&q=define%3A+${1}&btnG=Google+Search" | grep -m 3 -w "*"  | sed 's/;/ -/g' | cut -d- -f1 > /tmp/templookup.txt
         if [[ -s  /tmp/templookup.txt ]] ;then   
            until ! read response
               do
               echo "${response}"
               done < /tmp/templookup.txt
            else
               echo "Sorry $USER, I can't find the term \"${1} \""            
         fi   
rm -f /tmp/templookup.txt
}


Last edited by crouse on Wed Jan 09, 2008 2:44 am, edited 1 time in total.

Top
 Profile WWW  
 PostPosted: Fri May 04, 2007 2:48 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code:
# Weather by us zip code - Can be called two ways # weather 50315 # weather "Des Moines"
weather ()
{
declare -a WEATHERARRAY
WEATHERARRAY=( `lynx -dump "http://www.google.com/search?hl=en&lr=&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=weather+${1}&btnG=Search" | grep -A 5 -m 1 "Weather for" | grep -v "Add to my"`)
echo ${WEATHERARRAY[@]}
}



Top
 Profile WWW  
 PostPosted: Tue May 08, 2007 11:27 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
A few more just for fun......... ;)

Code:
#dirsize - finds directory sizes and lists them for the current directory
dirsize ()
{
du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
egrep '^ *[0-9.]*M' /tmp/list
egrep '^ *[0-9.]*G' /tmp/list
rm /tmp/list
}

#myip - finds your current IP if your connected to the internet
myip ()
{
lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | awk '{ print $4 }' | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g'
}

#clock - A bash clock that can run in your terminal window.
clock ()
{
while true;do clear;echo "===========";date +"%r";echo "===========";sleep 1;done
}

#netinfo - shows network information for your system
netinfo ()
{
echo "--------------- Network Information ---------------"
/sbin/ifconfig | awk /'inet addr/ {print $2}'
/sbin/ifconfig | awk /'Bcast/ {print $3}'
/sbin/ifconfig | awk /'inet addr/ {print $4}'
/sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
myip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' `
echo "${myip}"
echo "---------------------------------------------------"
}

#shot - takes a screenshot of your current window
shot ()
{
import -frame -strip -quality 75 "$HOME/$(date +%s).png"
}

#bu - Back Up a file. Usage "bu filename.txt"
bu () { cp $1 ${1}-`date +%Y%m%d%H%M`.backup ; }

#extract - extract most common compression types
extract () {
     if [ -f $1 ] ; then
         case $1 in
             *.tar.bz2)   tar xjf $1        ;;
             *.tar.gz)    tar xzf $1     ;;
             *.bz2)       bunzip2 $1       ;;
             *.rar)       rar x $1     ;;
             *.gz)        gunzip $1     ;;
             *.tar)       tar xf $1        ;;
             *.tbz2)      tar xjf $1      ;;
             *.tgz)       tar xzf $1       ;;
             *.zip)       unzip $1     ;;
             *.Z)         uncompress $1  ;;
             *.7z)        7z x $1    ;;
             *)           echo "'$1' cannot be extracted via extract()" ;;
         esac
     else
         echo "'$1' is not a valid file"
     fi
}

#:h gets you to the vim help menu or directly to :help wordname
:h() {  vim --cmd ":silent help $@" --cmd "only"; }


Top
 Profile WWW  
 PostPosted: Wed Jun 06, 2007 6:21 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
Tired of converting permissions in my head........wanted to be able to see the numerical permissions of files............ thanks nukes for reminding me of the stat command :D

Code:
alias perm='stat --printf "%a %n \n "'


Top
 Profile WWW  
 PostPosted: Tue Jan 01, 2008 7:44 pm   

Joined: Tue Jan 01, 2008 7:40 pm
Posts: 2
Code:
$ weather 85044
Weather for Phoenix, AZ 85044 [24]Add to iGoogle + 64°F Mostly Cloudy Wind: E at 18 mph Humidity: 10%


Any chance to modify the script to remove that "[24]Add to iGoogle" output?


Top
 Profile  
 PostPosted: Wed Jan 09, 2008 2:46 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
McQueen wrote:
Code:
$ weather 85044
Weather for Phoenix, AZ 85044 [24]Add to iGoogle + 64°F Mostly Cloudy Wind: E at 18 mph Humidity: 10%


Any chance to modify the script to remove that "[24]Add to iGoogle" output?


Done ;)


Top
 Profile WWW  
 PostPosted: Tue Jan 15, 2008 11:02 pm   

Joined: Tue Jan 01, 2008 7:40 pm
Posts: 2
Thank you much! Perfect now. :)


Top
 Profile  
 PostPosted: Fri Feb 08, 2008 2:09 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
lol... glad I could help :D


Top
 Profile WWW  
 PostPosted: Fri Apr 04, 2008 1:58 pm   

Joined: Tue Apr 01, 2008 10:19 am
Posts: 49
A more streamlined weather()

Code:
lynx -dump http://google.com/search?q=weather+$1 | grep -A 5 '^ *Weather for' | grep -v 'Add to'


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP