here.

"> here.

"> here.

" />
Rafe Hart

Thoughts on security, privacy, and building software.

.bashrc

05 July 2015

Of all the configuration files, .bashrc is the one that will most affect the command line environment. The .bashrc file controls the configuration options for the bash shell, and for the most part it is the same as it would be in linux. My full .bashrc is here.

Colorizing man pages

One alternative to make man pages more readable is to install most and use it for viewing man pages by putting ‘export PAGER=”most”’ into your .bashrc. Alternately, you can colourize ‘less’ by inserting the following into your .bashrc to colorize man pages.

# Less Colors for Man Pages
export LESS_TERMCAP_mb=$'E[01;31m'        # begin blinking
export LESS_TERMCAP_md=$'E[00;34m'        # begin bold
export LESS_TERMCAP_me=$'E[0m'            # end mode
export LESS_TERMCAP_se=$'E[0m'            # end standout-mode
export LESS_TERMCAP_so=$'E[01;44;33m'     # begin standout-mode - info box
export LESS_TERMCAP_ue=$'E[0m'            # end underline
export LESS_TERMCAP_us=$'E[00;32m'        # begin underline</pre>

I can’t track down where that tip came from originally, but Gen2ly has a good example on his excellent site, so I’ll give the credit to him.

Aliases & Environment Variables

Next is the all important PATH variable, which controls where the computer looks for executable files. I always include the directory to the windows system executables, as there are commands in there that don’t have cygwin counterparts, like tracert.

# Path
PATH="$PATH:/usr/local/bin:/usr/local/sbin:/bin:/sbin"
PATH="$PATH:/usr/bin:/usr/sbin:/usr/ssl/bin"
PATH="$PATH:/cygdrive/c/Windows/SysWOW64"   # Windows Progs such as tracert
export PATH

The bash prompt is usually better when colourized. This is the one I use:

PS1='[e[1;36m][[e[0;36m]u[e[1;36m]@[e[0;36m]h[e[1;36m]] [[e[1;31m]w[e[1;36m]]$[e[0m] '

You can see how all the potential colours will look with this handy script:

#!/bin/bash
#
#   Daniel Crisman's ANSI color chart script from
#   The Bash Prompt HOWTO: 6.1. Colours
#   http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
#
#   This file echoes a bunch of color codes to the terminal to demonstrate what's available.  Each
#   line is the color code of one forground color, out of 17 (default + 16 escapes), followed by a
#   test use of that color on all nine background colors (default + 8 escapes).

T='gYw'   # The test text

echo -e "n                 40m     41m     42m     43m
     44m     45m     46m     47m";

     for FGs in '    m' '   1m' '  30m' '1;30m' '  31m' '1;31m' '  32m' 
                '1;32m' '  33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' 
                '  36m' '1;36m' '  37m' '1;37m';
     do FG=${FGs// /}
       echo -en " $FGs 33[$FG  $T  "
         for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
     do echo -en "$EINS 33[$FG33[$BG  $T  33[0m";
       done
       echo;
done
echo

Then add aliases to your individual taste. The ones I’d suggest would include the following:

# Aliases
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias rm='rm -i'
alias cp='cp -rfv'
alias ls='ls -hF --color=tty'
alias grep='grep --color'
alias du='du -h'
alias wget='wget -c'

# Commands to help in the windows environment
alias cd..='cd ..'
alias ifconfig="ipconfig"
alias traceroute="tracert"
alias path='echo -e ${PATH//:/\n}'

# Opens the windows keychain manager - very useful
alias keyring="rundll32.exe keymgr.dll KRShowKeyMgr"

# Cygwin includes a windows processes switch for the ps command
alias ps="ps -W"

# I type sudo all the time, and it doesn't exist on cygwin, so this stops errors
alias sudo=""

X Windows

If you use X, you’ll want this

export DISPLAY=localhost:0.0

Proxy Settings

If you have to access the internet via a proxy, you’ll need something like the following settings to pass that information to the other command line utilities. Some command line tools will still need to be configured separately.

export http_proxy=http://user:pass@host:port/

# or just for ssl
export https_proxy=https://user:pass@host:port/

Misc

And here are some generally useful settings that don’t fit under any other heading.

# Make bash append rather than overwrite the history on disk
shopt -s histappend
shopt -s checkwinsize

# When changing directory small typos can be ignored by bash
# for example, cd /vr/lgo/apaache would find /var/log/apache
shopt -s cdspell

# History Options
# Don't put duplicate lines in the history.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups

# Ignore some controlling instructions
# HISTIGNORE is a colon-delimited list of patterns which should be excluded.
# The '&' is a special pattern which suppresses duplicate entries.
export HISTIGNORE=$'[ t]*:&:[fb]g:exit'
export HISTIGNORE=$'[ t]*:&:[fb]g:exit:ls' # Ignore the ls command as well

And done! There are a few other aliases, etc that I use for pydf, nmap and other utilities, but I’ll cover those in their respective pages. Also useful is setting your own colour scheme, which I’ll cover next.