Four tweaks for .bashrc

Tweak #1

To enable arrow keys to search history for the ending of a half-typed line.

  bind '"\e[A": history-search-backward' bind '"\e[B": history-search-forward' 

Usage: Type something in terminal that you know is the beginning of a long command line that you occasionally need. Arrow keys up and down should complete it.

Tweak #2

Alert in OSD when a process ends.

alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

Usage: cmd; alert where ‘cmd’ is an arbitrary command that performs a process, e.g. wget.

Tweak #3

An archive extractor without installing another program.

ext () {   if [ -f $1 ] ; then     case $1 in       *.tar.bz2)   tar xjf $1   ;;       *.tar.gz)    tar xzf $1   ;;       *.bz2)       bunzip2 $1   ;;       *.rar)       unrar 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 ext()" ;;     esac   else     echo "'$1' is not a valid file"   fi } 

Usage: ext <file>

Tweak #4

Colors for man pages, Gentoo style.

  man() {         env \                 LESS_TERMCAP_mb=$(printf "\e[1;31m") \                 LESS_TERMCAP_md=$(printf "\e[1;31m") \                 LESS_TERMCAP_me=$(printf "\e[0m") \                 LESS_TERMCAP_se=$(printf "\e[0m") \                 LESS_TERMCAP_so=$(printf "\e[1;44;33m") \                 LESS_TERMCAP_ue=$(printf "\e[0m") \                 LESS_TERMCAP_us=$(printf "\e[1;32m") \                         man "$@" } 

Usage: Open a man page and notice the difference.

Leave a Reply

Your email address will not be published. Required fields are marked *