Wednesday, March 30, 2011

MacOS: bash command line editing

This will let you use emacs or vi capabilities in the command line

set -o vi # for vi mode
set -o emacs # for emacs mode

Emacs command line editing cheat-sheet:

Tuesday, March 29, 2011

MacOS: How to change terminal directory to finder

To open the current directory in a graphical user window (finder) on Mac, from a terminal you simply use the command "open ."  (replace '.' with whatever directory name or file you want).   Mac will then use the default program (the finder) to open the target.  [Note: in windows, you can do a similar thing from the command shell,  cmd, with "explorer ."]

But how do you do the complementary operation - change directories of your terminal to the finder location?

Put this in your ~/.bash_login  file, and then you can  use "cdf" to change terminal directory to the last finder which had focus:

# cdf: cd's to frontmost window of Finder
cdf ()
    currFolderPath=$( /usr/bin/osascript <<"    EOT"
        tell application "Finder"
                set currFolder to (folder of the front window as alias)
            on error
                set currFolder to (path to desktop folder as alias)
            end try
            POSIX path of currFolder
        end tell
    # ignore the cd if it's my desktop
    if [ "$currFolderPath" != "$HOME/Desktop/" ]
        echo "cd to \"$currFolderPath\""
        cd "$currFolderPath"
        echo "no finder path to cd to..."

One final piece to round this out:   to open a terminal in the current window, you can add "Go2Shell" to your finder - see for more info.

Thursday, March 24, 2011

R: how to plot histogram with normal density

histnorm = function(xx,...)
  h<-hist(xx, ...)
  yfit <- yfit*diff(h$mids[1:2])*length(xx)
  lines(xfit, yfit, col="blue", lwd=2)

Subscribe via email

Enter your email address:

Delivered by FeedBurner