Tag Archives: osx

Docker Kitematic (Beta) and iTerm2 3.0 Beta

I guess using everything in beta can cause issues, but whatever.

Kitematic has an ‘Exec’ option for containers which opens a terminal connected to that container. If you have iTerm2 v3.0 beta installed, you’ve probably noticed this opens in Terminal.app instead of iTerm2.

The button in Kitematic executes a bash script at

/Applications/Docker/Kitematic (Beta).app/Contents/Resources/resources/terminal

. The bash script executes AppleScript, and the AppleScript syntax for iTerm2 in 3.0 has changed.

Here’s a replacement for that terminal bash script, with the new iTerm2 syntax (minus extra error handling).

#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CMD="clear && $*"

ITERM_EXISTS=`osascript <<EOF
set doesExist to false
try
    do shell script "osascript -e 'exists application \"iTerm2\"'"
    set doesExist to true
end try
return doesExist
EOF`

function open_iterm () {
  osascript > /dev/null <<EOF
  tell application "iTerm2"
    activate
    set newWindow to (create window with default profile)
    select first window

    tell current window
      tell current session
        write text "bash -c \"$CMD\""
      end tell
    end tell
  end tell
EOF
}

function open_terminal () {
  osascript > /dev/null <<EOF
  tell application "Terminal" to activate
  delay 0.4
  tell application "System Events" to keystroke "t" using command down
  tell application "Terminal"
    do script "bash -c \"$CMD\"" in window 1
  end tell
EOF
}

if [ "$ITERM_EXISTS" == "true" ]; then
  open_iterm "$@" || open_terminal "$@"
else
  open_terminal "$@"
fi

This may not be 100% correct, but it works.

Flattr this!

Hard link in OS X

Under linux, I used mount --bind olddir newdir to link a source code directory from a git repository in my Dropbox folder to another public git repository. I did this to avoid using git submodules and, for whatever reason, git had trouble following hard links under Ubuntu.

I recently purchased a Macbook Pro, and I was trying to use the same bound mount point. The mount provided with OS X doesn’t offer --bind. A main suggestion I found online is to use bindfs. bindfs didn’t work for my needs, and I didn’t want to manually compile a link/unlink application as others suggested.

I found that the homebrew package coreutils provides the gnu version of ln. To install:

brew install coreutils

This package doesn’t overwrite OS X default packages unless you run the above command with the --default-names switch, otherwise all utilities are prefixed with a g. Using the gnu ln program, I was able to hard-link successfully:

gln -d src target

I don’t know what the difference is between Ubuntu and OS X (both running git 1.8.4), but I can now work properly under git with hard links as expected.

Installing more gnu utilities

You can go one step further and install more gnu utilities (found on StackExchange):

brew install coreutils findutils gnu-tar gnu-sed gawk gnutls gnu-indent gnu-getopt

Then, add the following to your .bashrc:

PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"

Thanks to the Apple StackExchange user lri for the excellent post.

Flattr this!