Dreamhost .bashrc/.bash_profile/.bash_logout

Like everyone else in the universe, I have my own preferred bash setup. Discussed here is the setup I use with DreamHost.

UPDATE: See 1st comment below.

I'll start with the .bash_profile file as it simply references the .bashrc file:

# ~/.bash_profile: executed by bash(1) for login shells.

if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

(I've always done it this way -- never having a different config for login/non-login shells.  YMMV.)

Now for the .bashrc file:

01: # ~/.bashrc: executed by bash(1) for non-login shells.
02:
03: umask 002
04:
05: export EDITOR=vi
06:
07: # The base drupal install location
08: if [ -e ~/webroot/drupal ]; then
09:         export DRUPAL_INSTALL_ROOT=~/webroot/drupal
10: fi
11:
12: # changes to a drupal install site dir
13: dcd() { cd "`drupalReport.sh sitedir "$1"`"; }
14:
15: # pushd to a drupal install site dir
16: dpushd() { pushd "`drupalReport.sh sitedir "$1"`"; }
17:
18: # mysql into a drupal site db
19: dmysql() { mysql `drupalReport.sh dbconn "$1"`; }
20:
21: # Prompt
22: PS1="[\u@toddgee.com \W]\$ "
23:
24: alias cp='cp -i'
25: alias h='history'
26: alias ho='hostname'
27: alias j='jobs'
28: alias l='less'
29: alias l.='ls -d .* --color=auto'
30: alias ll='ls -lF --color=auto'
31: alias lll='ls -alF --color=auto'
32: alias ls='ls -F --color=auto'
33: alias m='more'
34: alias mc='. /usr/share/mc/bin/mc-wrapper.sh'
35: alias mv='mv -i'
36: alias rm='rm -i'
37:
38: export PATH=$PATH`find -L ${HOME}/bin -type d | grep -v .svn | while read dir; do echo -n ":${dir}"; done; echo ""`
39:
40: # Call the drupal scripts library's 'bash_completion' file
41: DRUPAL_SCRIPT_DIR="`dirname "\`which drupalCVSDeploy.sh\`"`"
42: if [ -n "${DRUPAL_SCRIPT_DIR}" ] && [ -f "${DRUPAL_SCRIPT_DIR}/bash_completion" ]; then
43:         . "${DRUPAL_SCRIPT_DIR}/bash_completion"
44: fi
45: unset DRUPAL_SCRIPT_DIR 46:
47: # Does local file exist?
48: if [ -f ~/.bashrc.local ]; then
49:         . ~/.bashrc.local
50: fi

some notes about particular lines:

  • Lines 7-10: This is to support my Drupal script library.  The environment variable DRUPAL_INSTALL_ROOT is the location of all my Drupal installations.  I set it to ~/webroot/drupal (assuming it exists, which is should).
  • Lines 12-19: Sets up a few shell procedures that leverage the script drupalReport.sh from my Drupal script library.  These are described in that script's help output (run w/ no parameters to see).  In order, these functions: cd to an installation's 'sites' dir; ditto except with pushd; and runs the mysql shell connected to the database for a site.
  • Line 22: Sets the prompt.  If you reuse this, change it from 'toddgee.com' to your own domain, 'eh?   :^)
  • Lines 24-36: My personal set of aliases.  I use 'l' for 'less' all the time...
  • Line 38: Appends my ~/bin directory and any subdirectory of ~/bin to the PATH.  It's nice to keep scripts in groups under bin.
  • Lines 40-45: Calls the drupal scripts bash_completion file if it exists.  This provides neato drupal installation site completion for scripts in the drupal script library.
  • Lines 47-50: Because this script is possibly shared among other (slave) users (more on this in another post), I add in this hook to extend the .bashrc script.  If a script '.bashrc.local' exists, it will be called by these lines.

I also have a .bash_logout file that just kills any ssh_agent I may have running:

# ~/.bash_logout: executed by bash(1) upon exit.

# Kill ssh_agent if it's running
if [ -n "${SSH_AGENT_PID}" ]; then
        kill "${SSH_AGENT_PID}"
fi

 

Free Tag:

Comments

Note, this script and the rest of my DreamHost scripts are now available as part of my DreamHost Script Library