You are not logged in.

#26 2008-09-03 20:16:08

richs-lxh
Member
Registered: 2008-08-23
Posts: 76

Re: Share your bashrc!

Just some stuff i do from the terminal with my bashrc and lynx;

Translate words
Define words
Check the weather

# richs-lxh needs to find rude words in other languages, define new groovy  words that the kids use nowadays, and see if it's sunny ; D

# Weather by placename # weather "Barcelona"
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[@]} 
}

#Translate Spanish/English  - USAGE: translate lamer 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 groovy word - USAGE: define lamer
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
}

The examples look like this:

rslxh@arch$ weather barcelona
Weather for Barcelona - 25ºC Current:Cloudy 
Wind: SW at 8 km/h Humidity: 75%

rslxh@arch$ translate hacker spanish
"hacker" in Spanish: pirata informático

rslxh@arch$ define newbie
* A new Internet user. If you are reading this defintion, you
* An individual lacking the knowledge of application functions.
* A new writer.

Last edited by richs-lxh (2008-09-03 20:23:47)

Offline

#27 2008-09-03 23:14:17

Xappe
Member
Registered: 2008-05-17
Posts: 105

Re: Share your bashrc!

Those define and translate functions looks kinda neat!

Here's mine:

export PATH="$PATH:~/bin:~/script:/opt/texlive/bin"

alias ls='ls -lh --color=auto'

PS1='\[\e[1;33m\][\u@\h \W]\[\e[0;32m\]\$\[\e[00m\] '

if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

alias pacs="pacsearch"

pacsearch () {
       echo -e "$(pacman -Ss $@ | sed \
       -e 's#core/.*#\\033[1;31m&\\033[0;37m#g' \
       -e 's#extra/.*#\\033[0;32m&\\033[0;37m#g' \
       -e 's#community/.*#\\033[1;35m&\\033[0;37m#g' \
       -e 's#^.*/.* [0-9].*#\\033[0;36m&\\033[0;37m#g' )"
}

complete -cf sudo

#Get colored output of manpages
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

vanum est vobis ante lucem surgere

Offline

#28 2008-09-05 12:19:54

richs-lxh
Member
Registered: 2008-08-23
Posts: 76

Re: Share your bashrc!

Xappe wrote:

Those define and translate functions looks kinda neat!

Here's mine:

export PATH="$PATH:~/bin:~/script:/opt/texlive/bin"

alias ls='ls -lh --color=auto'

PS1='\[\e[1;33m\][\u@\h \W]\[\e[0;32m\]\$\[\e[00m\] '

if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

alias pacs="pacsearch"

pacsearch () {
       echo -e "$(pacman -Ss $@ | sed \
       -e 's#core/.*#\\033[1;31m&\\033[0;37m#g' \
       -e 's#extra/.*#\\033[0;32m&\\033[0;37m#g' \
       -e 's#community/.*#\\033[1;35m&\\033[0;37m#g' \
       -e 's#^.*/.* [0-9].*#\\033[0;36m&\\033[0;37m#g' )"
}

complete -cf sudo

#Get colored output of manpages
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'

And thank you for the pacsearch code. Very nice wink

richs-lxh

Offline

#29 2008-09-05 17:50:21

securitybreach
Member
From: In front of my computers
Registered: 2007-11-18
Posts: 416
Website

Re: Share your bashrc!

richs-lxh wrote:

Just some stuff i do from the terminal with my bashrc and lynx;

Translate words
Define words
Check the weather

That is simply amazing. I have been using nix for years and I had no clue you could do that in bash. Great job!!!!

I wonder what else can be accomplished using bash and lynx? Time for some researching.

Once again thanks for the ideals and the code.

Last edited by securitybreach (2008-09-05 18:07:17)


"Every normal man must be tempted at times to spit upon his hands, hoist the black flag, and begin slitting throats." -- H.L. Mencken
Website      Configs
Forum Admin: Bruno's All Things Linux   
securitybreach<a>archlinux.us

Offline

#30 2008-09-05 19:04:03

richs-lxh
Member
Registered: 2008-08-23
Posts: 76

Re: Share your bashrc!

I'd just like to add that the codes are just things i have found on the net over the years. I didn't write them.

I don't want to take any credit for other people's work. I just copied and pasted them.

richs-lxh

Offline

#31 2008-09-05 19:09:27

securitybreach
Member
From: In front of my computers
Registered: 2007-11-18
Posts: 416
Website

Re: Share your bashrc!

Yeah I copied yours too. Still thank you providing insight into what can be done with bash.

Thanks


"Every normal man must be tempted at times to spit upon his hands, hoist the black flag, and begin slitting throats." -- H.L. Mencken
Website      Configs
Forum Admin: Bruno's All Things Linux   
securitybreach<a>archlinux.us

Offline

#32 2008-09-05 19:17:17

richs-lxh
Member
Registered: 2008-08-23
Posts: 76

Re: Share your bashrc!

securitybreach wrote:

Yeah I copied yours too. Still thank you providing insight into what can be done with bash.

Thanks

Thanks, Google is your friend wink

Have you seen my sig? "jfgi", I copied that as well. big_smile

richs-lxh

Offline

#33 2008-09-06 14:29:24

securitybreach
Member
From: In front of my computers
Registered: 2007-11-18
Posts: 416
Website

Re: Share your bashrc!

Very weird. I woke up today and for some reason everything works but the translation part. Now it cannot find any word using any language.

[comhack@Venus ~]$ translate home german
Sorry, I can not translate "home" to german
[comhack@Venus ~]$ translate home spanish
Sorry, I can not translate "home" to spanish
[comhack@Venus ~]$ translate home italian
Sorry, I can not translate "home" to italian

I have not changed anything in the .bashrc either.

Any ideals?

Last edited by securitybreach (2008-09-06 14:41:34)


"Every normal man must be tempted at times to spit upon his hands, hoist the black flag, and begin slitting throats." -- H.L. Mencken
Website      Configs
Forum Admin: Bruno's All Things Linux   
securitybreach<a>archlinux.us

Offline

#34 2008-09-06 16:45:20

Tomi
Member
Registered: 2008-09-06
Posts: 9

Re: Share your bashrc!

export PS_FORMAT=pid,user,tname,start_time,args
[[ -f /usr/bin/nano ]] && export EDITOR=nano
export PS1='\[\e[1;35;40m\][\u@\h \w]\[\e[1;0m\]\$ '

alias ls='ls --color=auto -F'
alias l='ls -lhA'
alias grep='grep --color=auto'
alias m=less
alias du='du -h'
alias df='df -h'

# for Arch workstatins, automate sudo and pacman-color
[[ -d /var/lib/pacman ]] && pacman () {
  [[ $1 == -*Q* || $1 == -Ss ]] && { pacman-color "$@"; return; }
  sudo pacman-color "$@"
}

[[ -f /usr/bin/links ]] && google () {
  local arg="$*"
  links google.com/search?q="`ruby -e "require 'cgi';print CGI.escape ARGV[0]" "$arg"`"
}

# Bash won't get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when
# it regains control.  #65623
# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize

Just added the checkwinsize part :-) thanks ukognos!
Also, look up [[ ]] on bash manpage, it's much better than [ ]. Word splitting inside [[ ]] is disabled, so you don't have to quote variables, and you get pathname-like pattern matching in == and !=.

EDIT: fixed typo.

Last edited by Tomi (2008-09-06 18:10:15)

Offline

#35 2008-09-06 17:21:44

btartsa
Member
Registered: 2004-07-26
Posts: 222

Re: Share your bashrc!

Question on the weather code used above...

$weather portland
Weather for Portland, OR 56°F Current:Cloudy Wind: NW at 0 mph Humidity: 92%
$weather portland maine
Weather for Portland, OR 56°F Current:Cloudy Wind: NW at 0 mph Humidity: 92%
$weather portland/maine
Weather for Portland, ME 74°F Current:Cloudy Wind: SW at 2 mph Humidity: 88%

Certainly not an issue, but I'm wondering how to handle the whitespace just out of curiosity. Cool stuff guys!

Oh, as for myself I think the ONLY thing I have not ripped in my .bashrc is this:

#list running daemons
alias dlist='ls /var/run/daemons'

Offline

#36 2008-09-07 14:48:54

Renan Birck
Member
From: Brazil
Registered: 2007-11-11
Posts: 401
Website

Re: Share your bashrc!

Some stuff is in Portuguese.

# Basic variables.

export PATH=/bin:/sbin:/opt/kde3/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/games:/usr/lib/qt3/bin:/opt/applix:/home/renan/bin:/opt/kde/bin:/opt/metasploit3:/opt/plan9
export TITLEBAR='\[\033]0;\u@\h:\w\007\]'
export EDITOR=vim


# for the metar utility (available in AUR): code of your nearest airport.
export AEROPORTO=sbsm

#export MANPATH=$MANPATH:/usr/share/man

# My bash prompt.

function proml
{
local CINZA="\[\033[1;30m\]"
local CINZA_CLARO="\[\033[0;37m\]"
local AZUL_CEU="\[\033[0;36m\]"
local AZUL_CEU_CLARO="\[\033[1;36m\]"
local PRETO="\[\033[0;30m\]"
local AZUL="\[\033[0;34m\]"
local BRANCO="\[\033[1;37m\]"
local VERMELHO_CLARO="\[\033[1;31m\]"
local AMARELO="\[\033[1;33m\]"
local VERDE_CLARO="\[\033[1;36m\]"

case $TERM in
     xterm*)
         local TITLEBAR='\[\033]0;\u@\h:\w\007\]'
         ;;
     *)
             local TITLEBAR=''
             ;;
esac
PS1="${TITLEBAR} [\$(date +%H:%M:%S)] $CINZA_CLARO[$AZUL_CEU\h:$AMARELO\w$CINZA_CLARO]$ "
# PS1="${TITLEBAR} $(date +%H:%M:%S) (\u@\h:\w)$ "
PS2='> '
PS4='+ '
}


proml

umask 0037

# My aliases

alias temperatura='metar -d $AEROPORTO | grep Temperature | sed 's/ure/ura/g''
alias k='kill -9'
alias l=ls
alias ls='ls --color=auto'
alias ll='ls -la --color=auto'
alias lr='ls -lR'
alias c='cd $1'
alias cls='clear'
alias yow='fortune zippy'
alias zippy=yow
alias ..='cd ..'
alias d='df -h'
alias f='free -tm'
alias u='uptime'


# Compile-time flags.

export CFLAGS="-march=prescott -mtune=prescott -Os -pipe -fomit-frame-pointer -mmmx -msse -msse2 -finline-functions -DPIC -fPIC -msse3"
export CXXFLAGS="-march=prescott -mtune=prescott -O2 -pipe  -fomit-frame-pointer -mmmx -msse -msse2 -finline-functions -DPIC -fPIC -ffast-math -msse3"
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

# Sometimes VMware breaks my keyboard, so I use this alias to un-break it.

alias restaura="setxkbmap -model pc104 -layout br ; xmodmap ~/.Xmodmap"
alias uskeyb="setxkbmap -model pc104 -layout us"

# Listen to Air Traffic Control, used to be scripts.
alias GIG='mplayer http://rio.radioetvweb.com.br:8246'
alias GRU='mplayer http://rio.radioetvweb.com.br:8298'
alias POA='mplayer http://rio.radioetvweb.com.br:8282'
alias CGH='mplayer http://rio.radioetvweb.com.br:8300'

# Set for OpenOffice.
export OOO_FORCE_DESKTOP="gnome"

# Instalacao das Funcoes ZZ (www.funcoeszz.net)
source /home/renan/bin/funcoeszz
export ZZPATH=/home/renan/bin/funcoeszz

Offline

#37 2009-08-02 16:45:05

crouse
Arch Linux f@h Team Member
From: Iowa - USA
Registered: 2006-08-19
Posts: 907
Website

Re: Share your bashrc!

Ever feel like the net leads you to strange places and then back again ????????

I was searching google for something bash related... (how to list all the functions in your bash profile) ...ended up at a blog..... found my bash functions listed there as author unknown......and it linked back to this post on archlinux.....where i see incarnations of my bash functions....... which i had originally posted here http://bbs.archlinux.org/viewtopic.php?id=30155 ..... wierd........

The web is seriously twisted......... but pretty cool that all roads lead to Arch lol

Offline

Board footer

Powered by FluxBB