Difference between revisions of "Bashrc helpers"

From ArchWiki
Jump to: navigation, search
(Created page with "Category:Dotfiles (English) a little note taker note () { #if file doesn't exist, create it [ -f $HOME/.notes ] || touch $HOME/.notes #no arguments...")
 
Line 1: Line 1:
 
[[Category:Dotfiles (English)]]
 
[[Category:Dotfiles (English)]]
 
+
inspired by a note taker, little todo script
 +
todo() {
 +
    test -f $HOME/.todo || touch $HOME/.todo
 +
    if test $# = 0
 +
    then
 +
            cat $HOME/.todo
 +
    elif test $1 = -l
 +
    then
 +
            cat -n $HOME/.todo
 +
    elif test $1 = -c
 +
    then
 +
            > $HOME/.todo
 +
    elif test $1 = -r
 +
    then
 +
            cat -n $HOME/.todo
 +
            echo -ne "----------------------------\nType a number to remove: "
 +
            read NUMBER
 +
            sed -ie ${NUMBER}d $HOME/.todo
 +
    else
 +
            echo $@ >> $HOME/.todo
 +
    fi
 +
}
 
a little note taker
 
a little note taker
 
  note ()
 
  note ()

Revision as of 17:43, 12 September 2010

inspired by a note taker, little todo script

todo() {
   test -f $HOME/.todo || touch $HOME/.todo
   if test $# = 0
   then 
           cat $HOME/.todo
   elif test $1 = -l
   then
           cat -n $HOME/.todo
   elif test $1 = -c
   then
           > $HOME/.todo
   elif test $1 = -r
   then
           cat -n $HOME/.todo
           echo -ne "----------------------------\nType a number to remove: "
           read NUMBER
           sed -ie ${NUMBER}d $HOME/.todo
   else
           echo $@ >> $HOME/.todo
   fi
}

a little note taker

note ()
{
       #if file doesn't exist, create it
       [ -f $HOME/.notes ] || touch $HOME/.notes
       #no arguments, print file
       if [ $# = 0 ]
       then
               cat $HOME/.notes
       #clear file
       elif [ $1 = -c ]
       then
               > $HOME/.notes
       #add all arguments to file
       else
               echo "$@" >> $HOME/.notes
       fi
}


extract() {
 local e=0 i c
 for i; do
   if  -f $i && -r $i ; then
       c=
       case $i in
         *.t@(gz|lz|xz|b@(2|z?(2))|a@(z|r?(.@(Z|bz?(2)|gz|lzma|xz)))))
                c='bsdtar xvf' ;;
         *.7z)  c='7z x'       ;;
         *.Z)   c='uncompress' ;;
         *.bz2) c='bunzip2'    ;;
         *.exe) c='cabextract' ;;
         *.gz)  c='gunzip'     ;;
         *.rar) c='unrar x'    ;;
         *.xz)  c='unxz'       ;;
         *.zip) c='unzip'      ;;
         *)     echo "$0: cannot extract \`$i': Unrecognized file extension" >&2; e=1 ;;
       esac
        $c  && command $c "$i"
   else
       echo "$0: cannot extract \`$i': File is unreadable" >&2; e=2
   fi
 done
 return $e
}


docview ()
{
  if [ -f $1 ] ; then
      case $1 in
          *.pdf)       xpdf $1    ;;
          *.ps)        oowriter $1    ;;
          *.odt)       oowriter $1     ;;
          *.txt)       leafpad $1       ;;
          *.doc)       oowriter $1      ;;
          *)           echo "don't know how to extract '$1'..." ;;
      esac
  else
      echo "'$1' is not a valid file!"
  fi
}
calc() { echo "scale=3;$@" | bc -l ; }