Monday, February 24, 2014

md()

So...I kind of lied in my first post. It was a little white lie. I didn't actually do a mkdir and then a cd.

In my configuration files for bash I have a function defined that can do this for me.

$ type md
md is a function
md ()
{
    /bin/mkdir -p "$1" && builtin cd "$1"
}

Breaking this down is pretty easy.

Use the mkdir command with the -p option for two reasons:
  1. intermediate directories will be created if I specify a long path
  2. errors will not pollute the terminal in almost all cases
$1 is a positional parameter specifying an item passed after calling the script or function. In this case it will be the directory I want to create and change into.

&& is a control operator that ensures that the cd will only execute if the mkdir exited successfully.

Specifying the builtin cd is only really necessary because I have made a function for my own cd which I might cover in another post sometime. It also has the side benefit of ensuring we use the builtin instead of /usr/bin/cd which will be quite a bit faster.

So what does all this mean? I can do the following at the command line instead of the two separate commands at beginning of my first post.

$ md src
$ pwd
/Users/ryan/src

Blog Refinement

I took a look at this last night and I realized two things:

The title looked dumb on my iPhone so I am expanding Mac to Macintosh. :)


I need to make another post about mkdir.

Friday, February 21, 2014

Compiling MTR on Mavericks

MTR is a really cool tool for viewing where in a series of network hops you might be having problems. Here is how you can get it on OS X.

mkdir ~/src
cd ~/src

curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
tar xf autoconf-latest.tar.gz
cd autoconf-2.69
./configure --prefix=/usr/local

NOTE: you may get a pop-up at this point asking you to 'Get Xcode' or 'Install'. Clicking the Install button will download from Apple the software you need to compile source from the command line without waiting for all of Xcode. Once the installation is complete run configure again.
make
sudo make install
cd ..

curl -OL http://ftpmirror.gnu.org/automake/automake-1.14.1.tar.xz
tar xf automake-1.14.1.tar.xz
cd automake-1.14.1
./configure --prefix=/usr/local
make
sudo make install
cd ..

git clone https://github.com/traviscross/mtr.git
cd mtr
./bootstrap.sh
./configure --without-gtk
make
sudo make install



EDIT 2014-04-29: removed z from tar options. Fixed directory name for automake. Added note for Xcode pop-up.