You are not logged in.

#1 2007-02-20 23:04:35

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

Cool Functions for your .bashrc file

These were originally functions I originally designed as bbot modules for the bash bot (http://bashscripts.org/ - bottom of page if your interested)  but I decided that they would work fine for your .bashrc file as well..... and they do wink   

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]$



# <--------- 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"`)
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
}

Offline

#2 2007-02-21 00:13:45

hacosta
Member
From: Mexico
Registered: 2006-10-22
Posts: 423

Re: Cool Functions for your .bashrc file

couple of useful ones..

#got it somewhere in the forums
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
}

#copy and go to dir
cpg (){
  if [ -d "$2" ];then
    cp $1 $2 && cd $2
  else
    cp $1 $2
  fi
}

#move and go to dir
mvg (){
  if [ -d "$2" ];then
    mv $1 $2 && cd $2
  else
    mv $1 $2
  fi
}

quiet (){
  nohup $1 &>/dev/null &
}
complete -A command quiet

Last edited by hacosta (2007-02-21 01:21:40)

Offline

#3 2007-02-21 00:34:24

zeus
Member
From: Korolev / Russia
Registered: 2006-09-19
Posts: 117
Website

Re: Cool Functions for your .bashrc file

1) useless - see "unp" package

Offline

#4 2007-02-21 02:35:23

hacosta
Member
From: Mexico
Registered: 2006-10-22
Posts: 423

Re: Cool Functions for your .bashrc file

@zeus
cant see how a package can make a function useless.

Offline

#5 2007-02-21 05:14:07

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

Re: Cool Functions for your .bashrc file

benefit of that function in a .bashrc file........... you don't have to be root to install it, doesn't need perl to work, and is 10+ k smaller in size  wink

Last edited by crouse (2007-02-21 05:23:40)

Offline

#6 2007-02-24 08:29:57

3nd3r
Member
From: /dev/null
Registered: 2002-12-08
Posts: 301
Website

Re: Cool Functions for your .bashrc file

I thought I would share my .bashrc with you guys, you might like it smile
BASHRC

alias ls='/bin/ls --color=auto -CFX'
alias pg='/bin/ps aux | grep'
alias gvim='gvim -fn 6x10'
alias bc='/usr/bin/bc -ql'
alias eqb='equery b'
alias la='/bin/ls -alshX' 
alias psall='/bin/ps aux'
alias psu='/bin/ps uxU $1'
alias psg='/bin/ps aux | grep $1'
alias lscrn='/usr/bin/screen -ls'
alias nscrn='/usr/bin/screen -S $1'
alias ascrn='/usr/bin/screen -D -R $1'
alias kill9='/bin/kill -9 $1'
alias df='/bin/df -kHl' ## I'm sick of appending -h.
alias emerge='/usr/bin/emerge' 
alias traceroute='traceroute -I'
alias cp='cp -p'
alias cls='clear'

umask 022                                       
set -o emacs                                    
bind 'C-u:kill-whole-line'                      
bind 'set bell-style visible'                           
bind 'set show-all-if-ambiguous on'             
bind 'set visible-stats on'                     



if [  ! $ENV_DONE ]; then
   export ENV_DONE=TRUE
fi

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
    INPUTRC=/etc/inputrc
fi



if [[ $- != *i* ]]; then
        # Shell is non-interactive.  Be done now
        return
fi

shopt -s checkwinsize
safe_term=${TERM//[^[:alnum:]]/.}       # sanitize TERM

if [[ -f /etc/DIR_COLORS ]]; then
        grep -q "^TERM ${safe_term}" /etc/DIR_COLORS && use_color=true
elif dircolors --print-database | grep -q "^TERM ${safe_term}"; then
        use_color=true
fi


if [[ -f /etc/profile.d/bash-completion ]]; then     ## For this to work ya must have a /etc/profile.d/bash-completion.  If your on gentoo emerge app-shells/bash-completion and 
    source /etc/profile.d/bash-completion            ## app-shells/gentoo-bashcomp.If not, fucks knows.
fi 

findgrep () {           # find | grep
        if [ $# -eq 0 ]; then
                echo "findgrep: No arguments entered."; return 1
        else
                # "{.[a-zA-Z],}*" instead of "." makes the output cleaner
                find {.[a-zA-Z],}* -type f | xargs grep -n $* /dev/null \
                                2> /dev/null
        fi
}

swap () {               # swap 2 filenames around
        if [ $# -ne 2 ]; then
                echo "swap: 2 arguments needed"; return 1
        fi
        if [ ! -e $1 ]; then
                echo "swap: $1 does not exist"; return 1
        fi
        if [ ! -e $2 ]; then
                echo "swap: $2 does not exist"; return 1
        fi
        local TMPFILE=tmp.$$ ; mv $1 $TMPFILE ; mv $2 $1 ; mv $TMPFILE $2
}

rot13 () {              # For some reason, rot13 pops up everywhere
        if [ $# -eq 0 ]; then
                tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]'
        else
                echo $* | tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]'
        fi
}

function scour() {
find / -iname '*'$1'*';
}

dirsize () {
 TotalBytes=0
 for Bytes in $(ls -l | grep "^-" | awk '{ print $5 }')
 do
 let TotalBytes=$TotalBytes+$Bytes
 done
 TotalMeg=$(echo -e "scale=3 \n$TotalBytes/1048576 \nquit" | bc)
 echo -n "$TotalMeg"
}

PS1='\[\033[1;30m\][\[\033[0;37m\]${PIPESTATUS}\[\033[1;30m\]:\[\033[0;37m\]${SHLVL}\[\033[1;30m\]:\[\033[0;37m\]\j\[\033[1;30m\]][\[\033[1;34m\]\u\[\033[0;34m\]@\[\033[1;34m\]\h\[\033[1;30m\]:\[\033[0;37m\]`tty | sed s/\\\\\/dev\\\\\/\//g`\[\033[1;30m\]]\[\033[0;37m\][\[\033[1;37m\]\W\[\033[0;37m\]]\[\033[1;30m\] \$\[\033[00m\] ' export PS1
complete -cf sudo

and here is the .Xdefaults

Xft.dpi: 96
#*font: *-gelly-*
*faceName:Bitstream Vera Sans Mono:pixelsize=11

!---------------!
!-> Terminals <-!
!---------------!
!---!! urxvt !!---!
urxvt*termName: rxvt
urxvt*loginShell:true
urxvt*inheritPixmap: true
urxvt*tintColor: gray40
urxvt*foreground: White
urxvt*internalBorder: 0
urxvt*background: Black
urxvt*scrollBar: false
urxvt*saveLines: 30000
urxvt*font: xft:Bitstream Vera Sans Mono:pixelsize=11
! Black text color
urxvt*color0:  #000000
urxvt*color8:  #000000
! Red text color
urxvt*color1:  #a35757
urxvt*color9:  #a35757
! Green text color
urxvt*color2:  #7ac470
urxvt*color10: #7ac470
! Yellow text color
urxvt*color3:  #dfe14e
urxvt*color11: #dfe14e
! Blue text color
urxvt*color4:  #5083b2
urxvt*color12: #6494c1
! Magenta text color
urxvt*color5:  #b781ac
urxvt*color13: #c866b4
! Cyan text color
urxvt*color6:  #8787a0
urxvt*color14: #8787a0
! White text color
urxvt*color7:  #f0f0f0
urxvt*color15: #ffffff
! Bold text color
urxvt*colorBD: #ffffff
! Underlined text color
urxvt*colorUL: #fff796

!---!! Aterm !!---!
atermloginShell:true
aterm*transparent:true
aterm*shading:60
aterm*background:Black
aterm*foreground:White
aterm*scrollBar:false
!!aterm*scrollBar_left:true
aterm*saveLines:30000
!!aterm*transpscrollbar:true
aterm*font:-*-Bright-*
!! Black text color
aterm*color0:  #000000
aterm*color8:  #000000
!! Red text color
aterm*color1:  #a35757
aterm*color9:  #a35757
!! Green text color
aterm*color2:  #7ac470
aterm*color10: #7ac470
!! Yellow text color
aterm*color3:  #dfe14e
aterm*color11: #dfe14e
!! Blue text color
aterm*color4:  #5083b2
aterm*color12: #6494c1
!! Magenta text color
aterm*color5:  #b781ac
aterm*color13: #c866b4
!! Cyan text color
aterm*color6:  #8787a0
aterm*color14: #8787a0
!! White text color
aterm*color7:  #f0f0f0
aterm*color15: #ffffff
!! Bold text color
aterm*colorBD: #ffffff
!! Underlined text color
aterm*colorUL: #fff796

!---!! xterm !!---!
xtermloginShell:true
xterm*background:Black
xterm*foreground:White
xterm*scrollBar:false
!!xterm*scrollBar_left:true
xterm*saveLines:30000
!!xterm*transpscrollbar:true
xterm*faceName:Bitstream Vera Sans Mono:pixelsize=11
!! Black text color
xterm*color0:  #000000
xterm*color8:  #000000
!! Red text color
xterm*color1:  #a35757
xterm*color9:  #a35757
!! Green text color
xterm*color2:  #7ac470
xterm*color10: #7ac470
!! Yellow text color
xterm*color3:  #dfe14e
xterm*color11: #dfe14e
!! Blue text color
xterm*color4:  #5083b2
xterm*color12: #6494c1
!! Magenta text color
xterm*color5:  #b781ac
xterm*color13: #c866b4
!! Cyan text color
xterm*color6:  #8787a0
xterm*color14: #8787a0
!! White text color
xterm*color7:  #f0f0f0
xterm*color15: #ffffff
!! Bold text color
xterm*colorBD: #ffffff
!! Underlined text color
xterm*colorUL: #fff796

I hope that you like smile

Offline

#7 2007-05-15 18:08:31

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

Re: Cool Functions for your .bashrc file

A few more just for fun.........  wink

#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 ; }

Offline

#8 2008-01-01 11:35:19

Leigh
Member
From: USA
Registered: 2004-06-25
Posts: 533

Re: Cool Functions for your .bashrc file

pacman
yaourt
arch32 chroot
colour bash prompt

I came up with a bunch of alias' for my .bashrc that helps me with pacman and yaourt commands. Maybe somone else might find it useful.

For pacman and chroot sections, If you don't like to use sudo, you could use su -c like this..
alias arch32='su -c "chroot /opt/arch32"'

#simplify yaourt commands using lowercase.

alias y-syu='yaourt -Syu --aur' #sync refresh sys update + aur
alias y-sy='yaourt -Sy'         #sync refresh
alias y-s='yaourt -S'           #install
alias y-sb='yaourt -Sb'         #builds the targets from source
alias y-su='yaourt -Su --aur'   #upgrade all aur packages
alias y-r='yaourt -R'           #remove
alias y-rd='yaourt -Rd'         #remove omit dependencies
alias y-rs='yaourt -Rs'         #remove plus unused dependencies
alias y-sl='yaourt -Sl'         #list all packages in specified repository
alias y-si='yaourt -Si'         #view package / aur PKGBUILD info
alias y-u='yaourt -U'           #install local pkg
alias y-scc='yaourt -Scc'       #clean catch - all pkgs
alias y-sc='yaourt -Sc'         #clean catch - old pkgs only
alias y-ss='yaourt -Ss'         #query database
alias y-qs='yaourt -Qs'         #query installed only
alias y-qi='yaourt -Qi'         #pkg more info
alias y-qe='yaourt -Qe'         #look for installed orphans
alias y-ql='yaourt -Ql'         #find pkg file list
alias y-qo='yaourt -Qo'         #/path/to/file = find owner
alias y-sw='yaourt -Sw'         #download but don't install
alias y-sf='yaourt -Sf'         #reinstall - for dep problem "force"

#incase I need to type yaourt..
alias yoaurt='yaourt'
alias yuaort='yaourt'
alias youart='yaourt'
alias yauort='yaourt'
alias yuoart='yaourt'

#simplify pacman commands using lowercase.
#Need to install and configure sudo.

alias p-s='sudo pacman -S'      #install
alias p-sy='sudo pacman -Sy'    #sync refresh
alias p-syu='sudo pacman -Syu'  #sync refresh sys update
alias p-r='sudo pacman -R'      #remove
alias p-u='sudo pacman -U'      #install local pkg
alias p-rd='sudo pacman -Rd'    #remove omit dependencies
alias p-rs='sudo pacman -Rs'    #remove plus unused dependencies
alias p-scc='sudo pacman -Scc'  #clean catch - all pkgs
alias p-sc='sudo pacman -Sc'    #clean catch - old pkgs only
alias p-ss='sudo pacman -Ss'    #query database
alias p-qs='sudo pacman -Qs'    #query installed only
alias p-si='sudo pacman -Si'    #pkg info
alias p-qi='sudo pacman -Qi'    #pkg more info
alias p-qe='sudo pacman -Qe'    #look for installed orphans
alias p-ql='sudo pacman -Ql'    #find pkg file list
alias p-qo='sudo pacman -Qo'    #/path/to/file = find owner
alias p-sw='sudo pacman -Sw'    #download but don't install
alias p-sf='sudo pacman -Sf'    #reinstall - for dep problem
alias abs='sudo abs'            #update abs database
alias p-op='sudo pacman-optimize'

#arch32 chroot - simplify yaourt commands using lowercase.
#Need to build and install yaourt inside chroot.

alias ay-syu='sudo chroot /opt/arch32 yaourt -Syu --aur'
alias ay-sy='sudo chroot /opt/arch32 yaourt -Sy'
alias ay-s='sudo chroot /opt/arch32 yaourt -S'
alias ay-sb='sudo chroot /opt/arch32 yaourt -Sb'
alias ay-su='sudo chroot /opt/arch32 yaourt -Su --aur'
alias ay-r='sudo chroot /opt/arch32 yaourt -R'
alias ay-rd='sudo chroot /opt/arch32 yaourt -Rd'
alias ay-rs='sudo chroot /opt/arch32 yaourt -Rs'
alias ay-sl='sudo chroot /opt/arch32 yaourt -Sl'
alias ay-si='sudo chroot /opt/arch32 yaourt -Si'
alias ay-u='sudo chroot /opt/arch32 yaourt -U'
alias ay-scc='sudo chroot /opt/arch32 yaourt -Scc'
alias ay-sc='sudo chroot /opt/arch32 yaourt -Sc'
alias ay-ss='sudo chroot /opt/arch32 yaourt -Ss'
alias ay-qs='sudo chroot /opt/arch32 yaourt -Qs'
alias ay-qi='sudo chroot /opt/arch32 yaourt -Qi'
alias ay-qe='sudo chroot /opt/arch32 yaourt -Qe'
alias ay-ql='sudo chroot /opt/arch32 yaourt -Ql'
alias ay-qo='sudo chroot /opt/arch32 yaourt -Qo'
alias ay-sw='sudo chroot /opt/arch32 yaourt -Sw'
alias ay-sf='sudo chroot /opt/arch32 yaourt -Sf'

#arch32 chroot - simplify pacman commands using lowercase.

alias ap-s='sudo chroot /opt/arch32 pacman -S'
alias ap-sy='sudo chroot /opt/arch32 pacman -Sy'
alias ap-syu='sudo chroot /opt/arch32 pacman -Syu'
alias ap-r='sudo chroot /opt/arch32 pacman -R'
alias ap-u='sudo chroot /opt/arch32 pacman -U'
alias ap-rd='sudo chroot /opt/arch32 pacman -Rd'
alias ap-rs='sudo chroot /opt/arch32 pacman -Rs'
alias ap-scc='sudo chroot /opt/arch32 pacman -Scc'
alias ap-sc='sudo chroot /opt/arch32 pacman -Sc'
alias ap-qs='sudo chroot /opt/arch32 pacman -Qs'
alias ap-ss='sudo chroot /opt/arch32 pacman -Ss'
alias ap-qs='sudo chroot /opt/arch32 pacman -Qs'
alias ap-si='sudo chroot /opt/arch32 pacman -Si'
alias ap-qi='sudo chroot /opt/arch32 pacman -Qi'
alias ap-qe='sudo chroot /opt/arch32 pacman -Qe'
alias ap-ql='sudo chroot /opt/arch32 pacman -Ql'
alias ap-qo='sudo chroot /opt/arch32 pacman -Qo'
alias ap-sw='sudo chroot /opt/arch32 pacman -Sw'
alias ap-sf='sudo chroot /opt/arch32 pacman -Sf'
alias ap-op='sudo chroot /opt/arch32 pacman-optimize'
alias aabs='sudo chroot /opt/arch32 abs'

bash promt change for chroot directory..

To help me see that I was actually inside the chroot I altered my promt code in the chroot /root/.bashrc file. Original prompt code from darkarchon on another thread. I liked the message, because it irritates my roomate who uses my computer sometimes. She hates linux. I added sleep 1 and clear because it started irritating me too, seeing it pop up all the time. I think I'll change it to "welcome to Microsoft" just to confuse her!
I'm so mean sometimes! tongue

prompt for normal user .bashrc is the same as root .bashrc

PS1='\[\e[1;35m\]\u\[\e[m\] \[\e[1;36m\]\w\[\e[m\] \[\e[1;32m\]> \[\e[m\]\[\e[0;37m\]'
PS2='>'
echo -e "                ${C}Welcome ${r}to ${C}Linux"
sleep 1
clear

bash prompt for  /opt/arch32/root/.bashrc

PS1='\[\e[1;35m\]arch32 ch\u\[\e[m\] \[\e[1;36m\]\w\[\e[m\] \[\e[1;32m\]> \[\e[m\]\[\e[0;37m\]'
PS2='>'

added alias in normal user .bashrc file

alias arch32='su -c "chroot /opt/arch32"'

what it looks like...
snapshot2.png

my whole .bashrc is in another thread full of .bashrc stuff, but I'm always changing it....
http://bbs.archlinux.org/viewtopic.php?id=41331

Last edited by Leigh (2008-01-01 17:32:36)


-- archlinux 是一个极好的 linux

Offline

#9 2008-01-01 12:43:54

schivmeister
Developer/TU
From: Singapore
Registered: 2007-05-17
Posts: 971
Website

Re: Cool Functions for your .bashrc file

wow some of these are great and fun smile I have a humble setup as of now, it'll grow after I extract some stuff frm this thread big_smile

#BLUE=`tput setf 1`
#GREEN=`tput setf 2`
#CYAN=`tput setf 3`
#RED=`tput setf 4`
#MAGENTA=`tput setf 5`
#YELLOW=`tput setf 6`
#WHITE=`tput setf 7`
PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[m\] \[\e[1;32m\]\$ \[\e[m\]\[\e[1;37m\] '

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

psc() {
  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' )"
}

alias ls='ls --color=auto'
alias la='ls -a'
alias l1='ls -1'
alias l0='ls -1a'
alias lh='ls -lh'
alias gr='grep'
alias fn='find'
alias sf='sudo find'
alias sc='sudo find / | grep'
alias rm='rm -ir'
alias srm='sudo rm -ir'
alias nn='nano'
alias sn='sudo nano'
alias np='nano PKGBUILD'
alias paq='pacman -Q | grep'
alias pac='sudo pacman -S'
alias pacy='sudo pacman -Sy'
alias pacu='sudo pacman -Suy'
alias pau='sudo pacman -U'
alias par='sudo pacman -R'
alias prc='sudo pacman -Rc'
alias prs='sudo pacman -Rs'
alias prm='sudo pacman -Rsc'
alias prp='sudo pacman -Rn'
alias psp='sudo pacman -Rsn'
alias pcp='sudo pacman -Rcn'
alias pmp='sudo pacman -Rscn'
alias pcc='sudo pacman -Scc'
alias sd='sudo'
alias fin='for i in'
alias dn='done'
alias thn='then'
alias pkg='PKGBUILD'
alias mkp='makepkg'
alias md5='md5sum'
alias cdabs='cd /var/abs'
alias cdvar='cd /var/abs/local'
alias cdaur='cd /var/abs/local/AUR'
alias wg='wget'
alias utarz='tar zvxf'
alias utarj='tar jvxf'
alias tarz='tar cvfz'
alias tarj='tar cvfj'

Last edited by schivmeister (2008-01-01 12:46:33)


I need real, proper pen and paper for this.

Offline

#10 2008-01-01 16:32:56

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,914
Website

Re: Cool Functions for your .bashrc file

if [ -f ~/.bashrc ]; then
source ~/.ArchTerminalTweaks
fi

Simply create .ArchTerminalTweaks or whatever you want call it, another place to put all your bash goodness

/me loves this thread cool


Mr Green

Offline

#11 2008-01-01 17:27:02

Leigh
Member
From: USA
Registered: 2004-06-25
Posts: 533

Re: Cool Functions for your .bashrc file

wow, thanks Mr Green! Very cool tip! big_smile


-- archlinux 是一个极好的 linux

Offline

#12 2008-01-01 17:38:04

Shaika-Dzari
Member
From: Québec, Canada
Registered: 2006-04-14
Posts: 436
Website

Re: Cool Functions for your .bashrc file

Great post! big_smile

I add it to my .zshrc right now!

Offline

#13 2008-01-01 21:50:05

Gilneas
Member
From: Netherlands
Registered: 2006-10-22
Posts: 320

Re: Cool Functions for your .bashrc file

Look through man pages of a package, useful for a package like imagemagick:

select manpack in $(pacman -Ql $1 | awk '/\/usr\/man/ {print $2}' ); do man $manpack; done

EDIT
changed to match the new way pacman displays directories as well in -Ql.
It checks for a dot in the filename.

select manpack in $(pacman -Ql $1 | awk '/\/usr\/man.*\./ {print $2}' ); do man $manpack; done

EDIT
it didn't look in /usr/share/man!
This will: (it just looks for a '/man/' dir (and a dot as well))

select manpack in $(pacman -Ql $1 | awk '/\/man\/.*\./ {print $2}' ); do man $manpack; done

Last edited by Gilneas (2008-01-31 06:15:18)

Offline

#14 2008-01-03 02:42:37

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: Cool Functions for your .bashrc file

Thank you!

Offline

#15 2008-01-03 06:42:12

Gilneas
Member
From: Netherlands
Registered: 2006-10-22
Posts: 320

Re: Cool Functions for your .bashrc file

I was getting quite confused with all the feh themes that had --action#s. This will show all themes with --action looking neat with \n and \t. If you have feh options after the last one (maybe a default directory), or in between the actions, it will be pasted after the action.
Also, if you have a line break in the theme it probably won't work.

alias fehi="sed -ne '/action/ s#\(\w*\).*\(--action1.*$\)#Theme: \1 \2#; s#--action#\n\t#gp' $HOME/.fehrc"

Offline

#16 2008-01-03 20:27:09

Gilneas
Member
From: Netherlands
Registered: 2006-10-22
Posts: 320

Re: Cool Functions for your .bashrc file

And today I scratched another itch, the "in between" of head and less, which I like to call page.

Usage: page [number_of_current_screensizes_to_display] file

if [ -z $2 ]; then amount=1
else amount=$1; shift
fi
head -n $(stty size | awk '{print $1 * '"$amount"' -1}') $1

-Edit-
Actually, I found the lack of pipeablity annoying. And now I'm using

alias page="head -n $(stty size | awk '{print $1 -2}')"

'-2' for being able to see the previous prompt, which is nice verification. Also, I would have liked to see a 'fold' in there, but I guess this is alright.

Last edited by Gilneas (2008-01-03 20:55:50)

Offline

#17 2008-01-04 16:28:55

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,914
Website

Re: Cool Functions for your .bashrc file

http://albatross.dnsdojo.net/apache2-de … Bash_Tools

May have already been posted but.....


Mr Green

Offline

#18 2008-01-05 09:51:24

sabooky
Member
Registered: 2006-11-02
Posts: 89

Re: Cool Functions for your .bashrc file

mplayerwrap()
inhibit gnome-screensaver while playing video

function mplayerwrap {
        (gnome-screensaver-command -i -n "mplayer" -r "playing video" &
        pid=$!
        mplayer "$@"
        kill $pid
        )
}

alias mplayer="mplayerwrap"

Offline

#19 2008-01-05 13:23:52

jacko
Member
Registered: 2007-11-23
Posts: 840

Re: Cool Functions for your .bashrc file

#incase I need to type yaourt..
alias yoaurt='yaourt'
alias yuaort='yaourt'
alias youart='yaourt'
alias yauort='yaourt'
alias yuoart='yaourt'

smile, I like this, made me chuckle. Also, great thread. Very nice tips and tricks. Especially the extract function.

Offline

#20 2008-01-06 07:42:57

Gilneas
Member
From: Netherlands
Registered: 2006-10-22
Posts: 320

Re: Cool Functions for your .bashrc file

Another script. I'm on a roll aren't I. These little things have been bugging me for a while though.

This one is a dirty/bad non-array approach to performing a command on a list of files but giving you the chance to remove a few before doing so. (I say dirty/bad because an array approach would be nicer, I think... I don't know a lot about arrays)

#!/bin/bash
IFS="
"

files="break"
for file in "$@"; do files="$files
$file"; done

while [ -z $done ]; do
select file in $files; do
if [ -z $file ]; then continue; fi
if [ $file = break ]; then done="true"; break; fi
files=$(for change in $files; do if [ $change = $file ]; then continue; else echo "$change"; fi; done)
break
done
done
echo -n 'Command on selection
>> '
read comsel
echo -n 'Append something after:
'"$comsel \"file\" ...: "
read comapp
#uncomment next for verbose (couldn't decide whether to keep or delete it)
#for file in $files; do [ $file = break ] || echo EXEC:  $comsel \"$file\" $comapp; done
for file in $files; do [ $file = break ] || eval $comsel \"$file\" $comapp; done

It works fine with spaces in the filename.

Edit: added the ability to add something after the command (useful for mv).
Btw, putting quotes around $comapp in eval gives unwanted behaviour.

Last edited by Gilneas (2008-01-07 03:43:42)

Offline

#21 2008-01-06 16:30:45

jacko
Member
Registered: 2007-11-23
Posts: 840

Re: Cool Functions for your .bashrc file

did anyone realize we already have a thread like this? Maybe we should merge the two?

forums are getting pretty sloppy lately with all the new arch users showing up.

http://bbs.archlinux.org/viewtopic.php?id=41331

Offline

#22 2008-01-09 08:41:17

ibrahim
Member
Registered: 2006-02-18
Posts: 53

Re: Cool Functions for your .bashrc file

jacko wrote:

did anyone realize we already have a thread like this? Maybe we should merge the two?

forums are getting pretty sloppy lately with all the new arch users showing up.

http://bbs.archlinux.org/viewtopic.php?id=41331

yeah, I can imagine things must have changed an immense amount in the whole two months you've been here

Offline

#23 2008-01-09 09:15:43

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,914
Website

Re: Cool Functions for your .bashrc file

http://wiki.archlinux.org/index.php/Bashrc

Started a page just got add some cool stuff .....


Mr Green

Offline

#24 2008-01-09 13:46:33

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 681
Website

Re: Cool Functions for your .bashrc file

alias nano='vi'

I will learn how to use vim big_smile

Offline

#25 2008-01-12 12:48:38

Leigh
Member
From: USA
Registered: 2004-06-25
Posts: 533

Re: Cool Functions for your .bashrc file

arch64 with yaourt - arch32 chroot with yaourt.

I made up a function to do a complete system update +aur, including the chroot +aur, using just a "sys" command. I thought it would be a good idea to add a "y/n" at the beginning, giving me the option to abort or commit. I made the initial echo bold and cyan, and another echo before updating the chroot to match the yaourt/pacman echos, so I can follow the update easier.

Edit...
May want to change the echos from Chinese to English smile

# System update using yaourt
# Arch64 + AUR, Arch32 chroot + AUR
function syu()
{
echo -e '\e[0;36m完全系统升级 + AUR + chroot... 咱们进行吗? (y/n)\033[0m'
read ans
case $ans in
    Y|y) ;;
    [Yy][Ee][Ss]) ;;
     N|n) return ;;
    [Nn][Oo]) return ;;
    *) echo "Invalid Command"
    return ;;
esac
echo -e '\e[0;36m-------------------------------------\033[0m'
echo -e '\e[1;36m==> \e[0;36m现在开始 \e[1;36mArch64 \e[0;36m系统升级 \e[1;36m+ AUR\e[0;36m...\033[0m'
echo -e '\e[0;36m-------------------------------------\033[0m'
yaourt -Syu --aur
echo -e '\e[0;36m--------------------------------------------\033[0m'
echo -e '\e[1;36m==> \e[0;36m现在开始 \e[1;36mArch32 chroot \e[0;36m系统升级 \e[1;36m+ AUR\e[0;36m...\033[0m'
echo -e '\e[0;36m--------------------------------------------\033[0m'
sudo chroot /opt/arch32 yaourt -Syu --aur
}

Last edited by Leigh (2008-01-13 21:27:54)


-- archlinux 是一个极好的 linux

Offline

Board footer

Powered by FluxBB