OSX sed: Match Bash Variable, and then Delete or Append Bash Variable

Bash: GNU bash, version 4.3.33(1)-release (x86_64-apple-darwin14.1.0)

Working with Neo4j, I wanted to simplify turning on/ off debugging via the Neo4j properties file, so I decided to use sed to do this. This code is just the sed lines to do this.

This has the infamous OS X -i ‘’ argument to do the substitution in place.

# This is the line I either want - to don’t want - in my neo4j-wrapper.conf file:
DEBUG_CONFIG="wrapper.java.additional=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y"

sed -i '' "/\(^${DEBUG_CONFIG}$\)"'/d' ./neo4j-wrapper.conf

# This is the line after which I will add my debug config line
MATCH_LINE="wrapper.java.additional=-XX:-OmitStackTraceInFastThrow"

# After the match line, append the Debug configuration.
sed -i '' "/\(^${MATCH_LINE}$\)"'/a\'$'\n'"${DEBUG_CONFIG}"  ./neo4j-wrapper.conf

Thanks to jw013’s answer at http://unix.stackexchange.com/a/52141/118244 I was able to sort out the $’\n’ syntax to encourage bash to pass the newline to sed.

See also: http://unix.stackexchange.com/questions/52131/sed-on-osx-insert-at-a-certain-line

Bash 4.x Script to Show/ Hide Hidden Files in OSX

Tested on Yosemite with bash 4.3.33 (which was installed via homebrew, (http://johndjameson.com/blog/updating-your-shell-with-homebrew/).



#!/usr/bin/env bash
# A Bash 4.x Script to Show Hidden Files in OSX
#
function show_help() {
    >&2 echo "Please specify what I should do with hidden files:"
    >&2 echo -e "\tyes (show)"
    >&2 echo -e "\tno (don't show)"
}

if [[ $# < 1 ]] ; then
    show_help
    exit 1
fi
yes_or_no="${1^^}"
echo $yes_or_no
if [[ "${yes_or_no}" != @(YES|NO) ]]; then
    >&2 echo "Invalid argument '$1'"
    show_help
    exit 2
fi
defaults write com.apple.finder AppleShowAllFiles $yes_or_no
killall Finder

OSX Yosemite and Cisco AnyConnect tcp timeout can’t connect to Docker

Found the answer here: http://stackoverflow.com/a/27804765/1518121 THANK YOU!

The scenario is you’ll see error like this one trying to work with a docker container:

FATA[0000] Get http:///var/run/docker.sock/v1.16/containers/json: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?

I am using OSX Yosemite and Cisco Anyconnect (which are apparently a bad combo for using boot2docker) and the following finally worked for me (thanks to the linked GitHub issue comment):

These steps will add a port forwarding rule and modify your environment to have docker point to 127.0.0.1 (instead of 192.168.59.103 or other NATed IP).

First – boot2docker needs to be installed but not running.

If it is currently running – stop it now:

boot2docker down
Add a rule to forward traffic from 127.0.0.1:2376 to port 2376 on the boot2docker vm:

vboxmanage modifyvm “boot2docker-vm” –natpf1 “docker,tcp,127.0.0.1,2376,,2376″
Start boot2docker:

boot2docker up
Set default DOCKER environment variables:

$(boot2docker shellinit)
Override the DOCKER_HOST variable to point to 127.0.0.1:

export DOCKER_HOST=tcp://127.0.0.1:2376
Now you should be able to run docker commands:

docker version

Mac OSX Writing Markdown and Taking Screenshots

Background

I’m doing a lot of documentation for our current iteration. Since we’re in github quite a bit, and want to keep documentation there (and transform it later if necessary), we’re in the Markdown world.

Writing Markdown

Please not another editor. Too bad. But anyway, I’ve been using Mou – Markdown Editor for Web Developers for a few days now, and it’s just about perfect for my needs. It has a split screen view so you can see what you’re doing. No more or less than I need.

Untitled_and_RetailOrderManagementTroubleshootingFAQ_md

Screen Capture

For screen captures, I just discovered Skitch.  This is a terrific little tool that makes capturing – and subsequently naming, or dragging and dropping, or marking up images – comically simple.

The image of Mou above was captured with Skitch. As was the image below – which was captured, marked up, and simply dragged and dropped right into this post. Complete with nifty arrows and a sweet little sticky with an ‘X’ on it.  You can also change formats, crop, and pixelate, among other things.

Add_New_Post_‹_MXWest_westwideweb_com_—_WordPress

Resizing a Skitch Note

This was a little tricky for me to find. You have to first select the crop tool, and then toggle to resize mode. Although it seems the one thing I couldn’t capture with Skitch was Skitch itself (as it hides itself while you’re taking a screen capture), we can do a regular Mac screen capture, and then just open the file in Skitch. So here’s where you find resize:

Screen_Shot_2014-06-12_at_3_04_06_PM

 

Changing Mac’s Default Screenshot Save Folder

Kind of moot since I’m using the above tools, but Adam on Lifehacker describes How to Change OS X’s Default Screenshot Format and Location.

To change the default destination folder, from the command line:

defaults write com.apple.screencapture location /some/new/location

To load this new setting, from the command line:

killall SystemUIServer