Tuesday, August 12, 2014

Very useful bash $PS1 setting

My ~/.bashrc settings have a killer setting for how my shell prompt looks:

case $- in
   *i*)
export PS1="\[$(tput bold)\]\[$(tput setaf 6)\]\t \[$(tput setaf 2)\][\[$(tput setaf 4)\]\u\[$(tput setaf 1)\]@\[$(tput setaf 4)\]\H \w \[$(tput setaf 6)\]\[$(tput setaf 2)\]]\[$(tput setaf 4)\] \$? \\$ \[$(tput sgr0)\]" ;;

     *)  return ;;
esac


The result:

22:19:43 [myuser@myserver.example.com ~ ] 0 $

This shows the current system time, username@server FQDN, pwd, exit code of last command, and regular user or root prompt.

This works in both interactive and non-interactive shells (hence the case statement).  Enjoy.  Additional info can be found here:

Bash $PS1 generator
10 Bash $PS1 examples
Bashrc generator

Wednesday, July 9, 2014

Ruby Regex

Just wanted to pass along two very useful sites for regular expressions with Ruby

Ruby regex calculator:

http://rubular.com/

Ruby regex documentation:

http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm