Difference between revisions of "Bashrc helpers"

From ArchWiki
Jump to: navigation, search
m (rm extract: already in Bash#Functions)
m (changed merge target)
Line 1: Line 1:
 
[[Category:Dotfiles]]
 
[[Category:Dotfiles]]
 
[[zh-CN:Bashrc helpers]]
 
[[zh-CN:Bashrc helpers]]
{{Merge|Core Utilities}}
+
{{Merge|Bash#Functions}}
  
 
inspired by the note taker, little todo script
 
inspired by the note taker, little todo script

Revision as of 19:10, 1 September 2013

Merge-arrows-2.pngThis article or section is a candidate for merging with Bash#Functions.Merge-arrows-2.png

Notes: please use the second argument of the template to provide more detailed indications. (Discuss in Talk:Bashrc helpers#)

inspired by the 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
}


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
}


calculator

calc() { echo "scale=3;$@" | bc -l ; }


Kingbash - menu driven auto-completion (see https://bbs.archlinux.org/viewtopic.php?id=101010)

install kingbash from aur then insert following in your .bashrc

function kingbash.fn() {
  echo -n "KingBash> $READLINE_LINE" #Where "KingBash> " looks best if it resembles your PS1, at least in length.
  OUTPUT=`/usr/bin/kingbash "$(compgen -ab -A function)"`
  READLINE_POINT=`echo "$OUTPUT" | tail -n 1`
  READLINE_LINE=`echo "$OUTPUT" | head -n -1`
  echo -ne "\r\e[2K"; }
bind -x '"\t":kingbash.fn'