colori(s|z)ed ls output on macos

As is often the case, the nix defaults for ls are spartan. I finally got around to wrestling my ls color settings into submission. On macos/zsh, gdircolors gave inconsistent results, so I set the LS_COLORS environment var directly.

Snips:

install gls

brew install coreutils

.zshrc

if [[ "$(uname)" = "Darwin" ]]; then # macos uses a different 'ls'
  export CLICOLOR=1
  source "$XDG_CONFIG_HOME/zsh/.dir_colors"
  alias l="gls -ahF --group-directories-first --color=always"
else
  alias l="ls -ah --color --group-directories-first"
fi

~/.config/zsh/.dir_colors

# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
export LS_COLORS='rs=0:di=00;34:ln=00;37:mh=00:pi=40;33:so=00;35:do=00;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=00;33:*.tar=01;31:*.tgz=01;31:'

The full goodies:

byobu and tmux plugin manager (tpm)

It seems that byobu triggers a known bug with tpm which then fails to load any plugins. Fortunately there is a simple fix, in byobu’s .tmux.conf change your plugin formatting like so:

set -g @tpm_plugins ' \
 tmux-plugins/tpm \
 nhdaly/tmux-better-mouse-mode \
 tmux-plugins/tmux-resurrect \
 '

If using the XDG directory convention, this line is also needed in .tmux.conf:

set-environment -g TMUX_PLUGIN_MANAGER_PATH "~/.config/byobu/plugins/"

 

neovim: macos tmux and netrw/vinegar clipboard errors

So it looks like MacOS Sierra broke pbcopy/pbpaste for tmux. This manifests as clipboard errors when using netrw/vinegar in neovim under tmux. (Dunno why netrw is writing to the clipboard but anyways).

The solution is to use Homebrew to reinstall a patched version of reattach-to-user-namespace:

brew uninstall reattach-to-user-namespace
brew install reattach-to-user-namespace --with-wrap-pbcopy-and-pbpaste

Although this was annoying, it did lead to running brew cleanup which reclaimed 3.8GB of disk space. Jinkies!

vim: render plantuml

When using the plugin plantuml-syntax, add the following one-liner in .vimrc to render a PNG in the current directory when ‹leader›b is pressed:

autocmd FileType plantuml nnoremap <buffer> <leader>b :!java -jar ~/bin/plantuml.jar -o %:p:h %<cr>

This assumes Linux and that plantuml.jar lives in ~/bin. If working from a Dropbox directory, the image can then easily be viewed in a web browser.

what time is it in that city?

My iOS app needs to know what hour of the day it is in a particular city.

NSDate *date = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
[calendar setTimeZone:[NSTimeZone timeZoneWithName:@"Australia/Canberra"]];

NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:date];
NSInteger hour = [dateComponents hour];

if (hour > 2 && hour < 12) { // app is only available between midday and 2am

// tell the user to come back later

}

To see a list of available timezone names, launch Terminal on OSX and type:

ls /usr/share/zoneinfo/