The first thing I discovered is that when you go to install iTerm2’s shell integration it checks to see what shell you are using by reading the variable $SHELL, which is your accounts default shell, not necessarily the shell you are running.
Since my corporate Active Directory account sets my default shell to
/bin/ksh (don’t ask, just don’t ask) this caused me a problem. In iTerm my default profile is set to run the command
/bin/bash rather than my default shell. So to get shell integration installing properly I now set
SHELL='/bin/bash' at the bottom of my bash profile.
So I’m now using Ulysses for writing. Not coding, for that I’m still with BBEdit, but writing text of any sort. It seems quite an attractive editor, it supports MarkDown and things seem to work well.
I’m writing this as a test of it as a blogging platform. Of course the first thing to do is see what text looks like when I export it to WordPress from within Ulysses. Here, for example is some emphasised texrt and here is some strong test Let’s try a list
- We have the first item in an unordered list
- Now we have the second
That was the whole list.
- An ordered list
- So can you pick up items and reorder them
- We will see
If you delete or reorder it doesn’t update the numbers in your document but it is correct on export.
So how about we throw in
I don't like Ulysses needs a marker at the beginning of every code line.
My daughter, Jessica was born the Thursday before Father’s Day in 1992, the 3rd of September. That means this year her birthday occurs on Father’s Day.
That begs the question, what other years will this occur? Here’s some Python code that answers the question.
# Find all the years when my daughter's
# birthday and Father's day coincide
# from the year of her birth till 2100
for i in range(1992, 2100):
dt = "3 09 " + str(i)
tt = time.strptime(dt, "%d %m %Y")
if tt.tm_wday == 6:
I love you, Jessica. My favourite Father’s Day gift ever, always.
This is more in the way of a note to myself. I was just starting to write a bash completion script for Pandoc when I came upon this in the Pandoc documentation:
Generate a bash completion script. To enable bash completion with pandoc, add this to your
eval "$(pandoc --bash-completion)"
So no need for me to write one. Neat trick, generate your own bash completion script. John McFarlane really is a god. Oh, and the completion is top quality, it knows when you’ve typed an option that takes an input or output format and completes on those and other little tricks. I may end up using some of his tricks for my completions.
Last night I went to Lights For The Wild at Taronga Zoo. As usual, I took a lot of photos with my DSLR camera, over 200, though a lot of that number are quite similar as I often take two or three to increase the chances of getting the right shot, sometimes I vary the speed so that one is better exposed.
The camera saves both a RAW file and a JPEG so I end up with over 400 images. Looking through them in QuickLook in the Finder can be painful as the RAW images take quite a while to load, then you get the problem that when you have decided which of the three shots you want to keep you also have to delete the matching JPEG or RAW file.
The easiest solution to both of these is to only go through the JPEG files and then delete the matching NEF file (which is what the Mac calls the RAW file).
So I open the folder and sort by ‘Kind’ which puts the JPEGs at the top. I then open the first in QuickLook by hitting space and using the up and down arrow keys to move through the list command–delete deletes a file and displays the next. Easy.
Now I have 80 JPEG files from the original 240. How to get rid of the NEF files that match the JPEG files I have deleted? A little
bash programming to the rescue.
for i in *.NEF ; do
if [ ! -e `basename $i NEF`JPG ]; then
The secret to this is the
basename utility. It’s a neat little tool. Pass it a full file path such as
/Users/tonyw/Documents/UselessRamblings.txt and it will return just
the file name without the path,
UselessRamblings.txt. It has a matching tool,
dirname which returns just the path portion. As you can see from my code basename has another trick, it will happily strip the suffix from the filename if you tell it what to strip.
I’m working on more bash completions. This time for some of the command line tools Apple provides for sysadmins.
I decided there had to be a way to get a list of the options from the
man page for a tool. After all they are all in there.
So I built a command line piece by piece. As an example let’s get a list of the options (with some caveats) for the tool
pkgbuild. We start with
man pkgbuild | col -b , the
col -b step takes out the special characters
man uses to show bold on screen. Now find all lines containing
grep, I liked
grep -e '--'. If you have a look at the output of that we are getting close.
Next I decided to use
sed to do a find and replace for the option itself. After some playing around I ended up with
sed -e 's#.*\(--[a-zA-Z-]*\).*$#\1#' An important note for young players, it did take some time and a few tries to get that substitution just right. Don’t be afraid and remember Google (and Stack Exchange) are your friends.
First, I should point out an old Unix hand’s trick. Most of the time you see
sed substitution commands using
/ as the separator but sed can use anything but
\ or newline – it uses the first character it sees after the ‘s’. I usually use
# as it makes the
\ used for special characters easier to spot and the string easier to read.
I’m on a roll. I’ve written the bash completions for Munki.
(tl;dr The completions are on Github )
It’s getting easier to write them. There was one little trick I used that I didn’t
mention in my last post that I thought I’d share. How to use find and replace with
regular expressions to generate some of your code.
For this I use
Find... in BBEdit. I started with a list of the commands, one on each
line. Continue reading