bashrc coolness
calendar Dec. 23, 2015   category  bash   comments  comments


Here's a few things I have in my ~/.bashrc that make my life easier:

Bash completion for screen sessions, so you can do 'screen -r <tab>'

complete -C "perl -e '@w=split(/ /,\$ENV{COMP_LINE},-1);\$w=pop(@w);for(qx(screen -ls)){print qq/\$1\n/ if (/^\s*\$w/&&/(\d+\.\w+)/||/\d+\.(\$w\w*)/)}'" screen

Google from the commandline:

google() {
    search=""
    echo "Googling: $@"
    for term in $@; do
        search="$search%20$term"
    done
    xdg-open "http://www.google.com/search?q=$search"
    echo
}

Use ^F to search forward in your history (opposite of ^R)

bind '"\C-f": forward-search-history'

Show git status in prompt when inside a git directory:

export PS1='\[\033[01;32m\]\h\[\033[01;34m\] \W\[\033[01;30m\]$(declare -F __git_ps1 &>/dev/null && __git_ps1 " (%s)")\[\033[01;34m\] \$\[\033[00m\] '

Set bash history timestamps:

export HISTTIMEFORMAT="[%F %T] "
export HISTSIZE=10000
export HISTCONTROL=erasedups
shopt -s histappend

 



Share: