Showing posts with label OSX. Show all posts
Showing posts with label OSX. Show all posts

Sunday, May 10, 2026

Alacritty with Terminus On MacOS

Getting Alacritty to render Terminus font nicely along with having those nice nerd font symbols on MacOS  turned out to be much more of a hassle then I ever expected it to be.  With iTerm2, it was simply a matter of installing the Terminess Nerd Font and disable anti-aliasing, but with Alacritty there's a lot more steps involved.

Installing Terminus


Installing Terminus on MacOS can be done through Brew for both Terminus TTF and Terminess (the Nerd Font equivalent).  Make sure to do the following:
  1. Go to Font Book and check that the fonts are all activated.
  2. Make sure you have the right family name and style as Alacritty is case sensitive and both needs to be entered into the config exactly or Alacritty will give you a misleading error message.

Disabling Anti-Aliasing


Terminus is a font that might look worse with anti-aliasing.  Both the Terminus TTF and Terminess did not look as clear and as sharp compared to what I'm used to.  iTerm has a checkbox to turn it off but Alacritty requires you to do this from the OS:
defaults write org.alacritty AppleFontSmoothing -int 0
To turn it back on:  
defaults delete org.alacritty AppleFontSmoothing

Installing a Better Terminus


Alacritty couldn't render either of the above fonts very clearly.  On programmingfonts.org, I found another Terminus font that looked nice on the browser called Consoleet Terminus. 



I installed it on to MacOS but getting Alacritty to recognize it had me pulling out my hair.

[font]
size = 18.0
normal = { family = "Consoleet Terminus-18", style = "medium" }
bold = { family = "Consoleet Terminus-18", style = "bold" }
Notice what's unusual about the configuration that finally worked in Alacritty?  Some Terminus fonts don't have "Regular" styles and only define it as "Medium".  In the case of Consoleet Terminus, the styles are all lowercase.  If it is capitalized (e.g. "Medium" instead of "medium") then there will be an error.

I finally got the same nice looking terminal except it doesn't have those Nerd Font symbols.

 Installing Nerd Font Symbols


On Linux, it is easy to tell it that if a font doesn't have a symbol to go to a fallback font that does have it and use that one.  MacOS doesn't allow that so I had to merge a font that has it into Consoleet Terminus.  The problem is that most fonts with the symbols are scalable while classic version of Terminus fonts (like Consoleet) are not.   That's why you'll see individual font files for specific sizes.  In my case, the Consoleet em size is 36 units (ascent 30, descent 6) while Terminess will be 2048 — so the symbols are coming in roughly 56× too large.

The following script got me the right numbers to use to figure out what size I need to extract:
#!/usr/local/bin/bash
SYMBOL_REGULAR="$HOME/Library/Fonts/TerminessNerdFont-Regular.ttf"
SYMBOL_BOLD="$HOME/Library/Fonts/TerminessNerdFont-Bold.ttf"
mkdir -p ~/merged-fonts

declare -A SYMBOL_MAP=(
  [/Library/Fonts/consoleet_ter18nr.otf]="$SYMBOL_REGULAR|medium"
  [/Library/Fonts/consoleet_ter18br.otf]="$SYMBOL_BOLD|bold"
)

for f in "${!SYMBOL_MAP[@]}"; do
  IFS='|' read -r symbol style <<< "${SYMBOL_MAP[$f]}"
  name=$(basename "$f" .otf)
  family="Consoleet Terminus-18 Nerd"
  psname="ConsoleetTerminus18Nerd-${style}"
  fullname="${family} ${style}"

  cat > /tmp/merge.pe <<EOF
Open("$f")
Print("Destination em: " + \$em)
Print("Destination ascent: " + \$ascent + " descent: " + \$descent)
\$dst_em = \$em
\$dst_ascent = \$ascent
\$dst_descent = \$descent

Open("$symbol")
Print("Source em (before): " + \$em)
ScaleToEm(\$dst_ascent, \$dst_descent)
Print("Source em (after): " + \$em)
Generate("/tmp/scaled_symbol.ttf")
Close()

MergeFonts("/tmp/scaled_symbol.ttf")
SetFontNames("$psname", "$family", "$fullname", "$style")
Generate("$HOME/merged-fonts/${name}-merged.otf")
EOF
  fontforge -script /tmp/merge.pe
Then with the results, update the script to create the merged fonts:
#!/usr/local/bin/bash
SYMBOL_REGULAR="$HOME/Library/Fonts/TerminessNerdFont-Regular.ttf"
SYMBOL_BOLD="$HOME/Library/Fonts/TerminessNerdFont-Bold.ttf"
mkdir -p ~/merged-fonts

declare -A SYMBOL_MAP=(
  [/Library/Fonts/consoleet_ter18nr.otf]="$SYMBOL_REGULAR|medium"
  [/Library/Fonts/consoleet_ter18br.otf]="$SYMBOL_BOLD|bold"
)

for f in "${!SYMBOL_MAP[@]}"; do
  IFS='|' read -r symbol style <<< "${SYMBOL_MAP[$f]}"
  name=$(basename "$f" .otf)
  family="Consoleet Terminus-18 Nerd"
  psname="ConsoleetTerminus18Nerd-${style}"
  fullname="${family} ${style}"

  cat > /tmp/merge.pe <<EOF
Open("$f")
dst_ascent = \$ascent
dst_descent = \$descent
Print("Destination em: " + \$em + " ascent: " + dst_ascent + " descent: " + dst_descent)

Open("$symbol")
Print("Source em (before): " + \$em)
ScaleToEm(dst_ascent, dst_descent)
Print("Source em (after): " + \$em)
Generate("/tmp/scaled_symbol.ttf")
Close()

Open("$f")
MergeFonts("/tmp/scaled_symbol.ttf")
SetFontNames("$psname", "$family", "$fullname", "$style")
Generate("$HOME/merged-fonts/${name}-merged.otf")
EOF
  fontforge -script /tmp/merge.pe
Done

Once the script is run, validate it first:
fc-scan --format "%{family}\n%{fullname}\n%{postscriptname}\n%{style}\n" ~/merged-fonts/consoleet_ter18nr-merged.otf
fc-scan --format "%{family}\n%{fullname}\n%{postscriptname}\n%{style}\n" ~/merged-fonts/consoleet_ter18br-merged.otf
If there are no errors then install and validate:
cp ~/merged-fonts/consoleet_ter18*-merged.otf ~/Library/Fonts/
fc-match "Consoleet Terminus\-18 Nerd"
fc-match "Consoleet Terminus\-18 Nerd:style=bold"
Your final alacritty.conf file will be:
[font]
size = 18.0
normal = { family = "Consoleet Terminus-18 Nerd", style = "medium" }
bold = { family = "Consoleet Terminus-18 Nerd", style = "bold" }
Restart Alacritty.

 

Tuesday, April 7, 2026

Aerospace, Sketchybar, Jankyborders to Make OSX Workable

I've been using a combination of a Linux and ChromeOS as my work laptops, but my current job now has me using a Macbook Pro which I haven't touched in over 10 years.  A combination of the way OSX behaves and the workflow necessary for my particular work environment (Slack, Outlook, Claude Code, etc.) made me realize that I really needed to configure it if I expect to have a half decent work experience.

Aerospace Windows Manager

With the sheer number of different windows (apps and many browser windows), I couldn't function with a floating windows manager.  OSX's spaces/Mission Control was not effective in taming the chaos so I decided to use Aerospace, a tiling windows manager influenced by i3wm.  With Aerospace, having one application per workspace is much more intuitive and natural because of how well it's shortcuts are integrated with it.  It was almost instinctive to have my browser windows in the B workspace because the shortcut to it is simply Alt-B and Aerospace allowed you to configure so that whenever a browser window is opened that it can automatically put in the B workspace.  Along with not having all the gazillions windows overlapping each other was enough for me to use it, but the additional features, programmability and keyboard friendliness made it even more worth while for me to adopt it.

SketchyBar

SketchyBar is a nice complement to Aerospace.  It's a programmable OSX menu replacement, but I have it running vertically exclusively for Aerospace where it shows the Aerospace workspaces and what is running in each workspace.

JankyBorders

When there are multiple windows in one workspace, sometimes it wasn't obvious which was the active window.  JankyBorders is an utility program that draws a more visible border around the active window to make it more easily identifiable.

Integrating Aerospace, SketchyBar and JankyBorders

AeroSpace and JankyBoarder complements each other and doesn't exactly require integration but since Aerospace can be configured to run external programs as part of its startup it is simple to simply have Aerospace launch JankyBorder.

Integrating Aerospace and SketchyBar took a little more effort but the basic steps are:

  1. [Aerospace] Have Aerospace start SketchyBar.
  2. [Aerospace] Tell Aerospace that whenever there is a chance to a workspace that it should call SketchyBar to tell it of an event change and pass along the workspace that is in focus.
  3. [SketchyBar] Set its config file (~/config/sketchybar/sketchybarrc) to call Aerospace's command line app to get the active workspaces and apps in each workspace to be added to the SketchyBar menu.

My ~/.aerospace.toml and ~/.config/sketchybar/[sketchybarrc | aerospace.sh] can be found on Github.

Wednesday, April 8, 2020

BASH startup file loading order

The loading order of Bash startup files is first dependent on the type of shell that Bash think it is in.
A login shell is when the user logs in from tty (not through a GUI) or logs in remotely (e.g. through ssh).
A non-login shell is started in other ways such as gnome-terminal which is started by Gnome (it is a login shell that launched Gnome).
Note: The exception is OSX's Terminal.app which is treated as a login shell.
For non-login shells (e.g. gnome-terminal) the order is:

   /etc/bash.bashrc
   ~/.bashrc
For login-shells (including Terminal.app) the order is: /etc/profile and then first of:

   /etc/profile
Followed by the first of the following:

     ~/.bash_profile
     ~/.bash_login
     ~/.profile

Tuesday, July 3, 2018

Windows As a Developer Machine with Windows Subsystem for Linux (WSL)

Windows Subsystem for Linux allows running Linux binaries on Windows 10.   To overly simplify it, this means that Windows 10 can run a Linux shell based on a number of Linux distributions.  

Although Linux is my primary OS, I also have a Macbook Pro to address the rare occasions where I need to use an app that isn't available to Linux (e.g. Sketchup) and when I need a portable UNIX machine (OSX is based on Darwin, a BSD variant).  It used to be that to have an UNIX-like environment on Windows meant having to run something like Cygwin which I always felt to be somewhat clunky.  Getting Linux software to work was never as smooth or simple as using Linux itself (obviously) or OSX.  

WSL changes that completely and I've been using it for a couple of months writing Go programs with VIM in a Ubuntu shell running through WSL.  So far it has worked very well!  Things does run slower on WSL such as when I'm compiling and writing to the file system, but as my secondary machine that isn't as big a deal.  It's really nice that WSL mounts the Windows file system as a mount point that can easily be accessed.

The ever declining quality of Apple's laptops and OSX and its rising cost gives even more weight to Windows being a better buy for developers needing a portable Linux solution or needing both Windows and Linux.

Saturday, April 1, 2017

Accessing Github Through SSH As Different Users

To set up access to Github using different accounts, start by creating ssh keys for each account.

$ cd ~/.ssh
$ ssh-keygen -t rsa -C "github-acct1" -f "github-acct1"
Then add the ssh key to the Github account.

Next, create ~/.ssh/config to tell ssh when to use which account (set permission to be 600):

# Github account #1                                              
Host github.com-acct1                                                                 
   HostName github.com                                                          
   User git                                                                     
   IdentityFile ~/.ssh/github-acct1
   IdentitiesOnly yes                         
                                                                                
# Github account #2                                                         
Host github.com-acct2                                                        
   HostName github.com                                                          
   User git                                                                     
   IdentityFile ~/.ssh/github-acct2
   IdentitiesOnly yes

Check out a repo as the user to use by matching to the Host value in ~/.ssh/config:

$ git clone git@github.com-acct1:repo
Change to the repo directory and set the name and email to use for commits if needed.

$ cd repo
$ git config user.name "Acct1"
$ git config user.email acct1@example.com

To avoid accidentally using the wrong account (e.g. default):

$ git config --global --unset user.name
$ git config --global --unset user.email
$ git config --global user.useConfigOnly true
If you get an error message about the user (or the wrong user) not having the right permission to access the repo:

$ eval "$(ssh-agent -s)"
$ ssh-add


Thursday, July 21, 2016

Updating VIM for Go (Golang) Development

Since my last post, setting up Vim for Go development is not only easier but also makes developing with VIM much more powerful.  Just a single plugin, vim-go, is all that is needed for the Go-specific stuff and a host of new tools is now available to handle things like refactoring, linting, error checking, and more.

Go Tools

Make sure that you have Go installed and then get the various Go tools.

goimports

Go provides a lot of use packages that can be imported but it doesn't like it when you import a package and not use it.  Goimports will automatically insert the right imports for you by looking at your code and will remove unused imports from your source.  It's a great time saver!

go get golang.org/x/tools/cmd/goimports
godef

Godef lets you jump to the location where a symbol is defined.

go get -v code.google.com/p/rog-go/exp/cmd/godef
go install -v code.google.com/p/rog-go/exp/cmd/godef
golint

Golint will lint your source and warns you of potential issues.
go get github.com/golang/lint/golint
gorename

Gorename helps to refactor Go code.

go get golang.org/x/tools/cmd/gorename
errcheck

Errcheck checks your code for actual errors that isn't just lint issues.

go get github.com/kisielk/errcheck
gocode

Gocode provides autocomplete of your Go code.  When combined with vim-go and YouCompleteMe plugins, it allows autocomplete to appear as you're typing.


go get -u github.com/nsf/gocode (-u flag for "update")
It's a bit different for Windows so follow the instruction from the link for more details.

gotags

Gotags generate tags for Go code.  Combined with Tagbar, it will provide a pretty display of the tags in your code.

go get -u github.com/jstemmer/gotags
Guru

Guru is a tool that integrates with editors to help it understand Go code.

go get golang.org/x/tools/cmd/guru
go build golang.org/x/tools/cmd/guru

Oracle (Deprecated and replaced by Guru)

Oracle is a source analysis tool for Go program.


go get code.google.com/p/go.tools/cmd/oracle

Vim Plugins

It used to be that you would manually install a vim plugin for each of the various Go tools as well as using the the plugins that comes with Go itself.  Now, everything has been consolidated into a single Vim plugin, vim-go, and that's all you really need when it comes to Go-specific plugins.  A few other plug-ins such as Tagbar and YouCompleteMe are useful to complement your development environment, though.  I highly recommend that you use Vundle to manage your plugins.

vim-go

Vim-go brings together all the various plug-ins and feature for Go development in VIM including autocomplete, snippet support, improved syntax highlighting, go toolchain commands, etc. in a single package.

YouCompleteMe

YCM is a fast code completion engine for VIM that works as you type.  YCM requires VIM 7.3.584 or above and CMake (you'll need to compile the extension after it's downloaded).

Tagbar

A great way to view the tags in your code.  This requires that you have Exuberant Ctags and gotags installed.

Bufexplorer

My favorite plugin for navigating between VIM buffers.

.vimrc


" Go Specific Stuff
                                                             
au BufRead,BufNewFile *.go set filetype=go                                     
autocmd FileType go setlocal softtabstop=4
autocmd FileType go setlocal shiftwidth=4
autocmd FileType go setlocal tabstop=4

" go-def settings
let g:godef_split=2
let g:godef_same_file_in_same_window=1

" go-vim settings
let g:go_fmt_command = "goimports"
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1

" tagbar settings                                                                  
let g:tagbar_type_go = {
    \ 'ctagstype' : 'go',
    \ 'kinds'     : [
        \ 'p:package',
        \ 'i:imports:1',
        \ 'c:constants',
        \ 'v:variables',
        \ 't:types',
        \ 'n:interfaces',
        \ 'w:fields',
        \ 'e:embedded',
        \ 'm:methods',
        \ 'r:constructor',
        \ 'f:functions'
    \ ],
    \ 'sro' : '.',
    \ 'kind2scope' : {
        \ 't' : 'ctype',
        \ 'n' : 'ntype'
    \ },
    \ 'scope2kind' : {
        \ 'ctype' : 't',
        \ 'ntype' : 'n'
    \ },
    \ 'ctagsbin'  : 'gotags',
    \ 'ctagsargs' : '-sort -silent'
\ } 

Friday, July 24, 2015

Use VIM-like HJKL Instead Of Arrow Keys in Linux and OSX

Okay, I admit it...  I move around the file even while in the insert mode of Vim instead of going back to normal mode.  I don't always stay in insert mode, but if I'm typing and notices a typo a few characters back I will go back to the typo without leaving insert mode.  I do this by mapping the CTRL-[HJKL] to left, down, up, right so at least my fingers stays on the home row and not move to the arrows (I have disabled arrow keys in normal mode when I was training myself on Vim and never re-enabled it).

I found that after spending time in VIM if  I switch to other apps I will start using HJKL for navigation.  Of course that usually doesn't work and I end up using the arrow keys (e.g. when moving down menu options in the browser).  Naturally if I'm using those apps a lot more then when I go back into Vim I'll get lazy and start trying to use the arrow keys.  I decided what I want is to use HJKL even when I'm not in Vim and I wanted it to be consistent across Linux and OSX.

On OSX, this is easy to do.  Simply install Karabiner and select the option to use VI mode using the control key.  Then, in any app, simply use CTRL-[HJLK] for the equivalent behavior as using the arrow keys.  To add more consistency between OSX and Linux, I remapped Caps-Lock to the CTRL key (which is also easier to type on a mabook pro).

On Linux, it's a little more work.  I use Caps_Lock as the Switch_mode (SM) key and then defined that SM-[HJLK] combination to be like the arrow keys.  To do this:

xmodmap - pke > ~/.Xmodmap

Add this line to the top of the .Xmodmap file to disable the Caps_Lock key:

clear Lock

Then set the Caps-Lock key to be the Switch-mode key:

keycode 66 = Mode_switch Caps_Lock

This means to set the caps_lock to be the mode_switch key (and caps-lock when it is Shift-Caps_Lock)

Next, add the Left/Down/Up/Right to the third column of the key code record that maps to the letters, HJKL.

keycode 43 = h H Left
keycode 44 = j J Down
keycode 45 = k K Up
keycode 46 = l L Right

This means that for key 45, print "k" when the key is pressed, "K" when it is SHIFT-k and Up when CapsLock-k is pressed (since CapsLock is now the mode_switch key).

Once you save the file, load it with

xmodmap .Xmodmap

Most current desktops will load .Xmodmap when logging in.
You can find out what keycodes maps to what by using xev.

Monday, May 4, 2015

Installing Waypoint Map Mods for Minecraft 1.8 for Windows, Linux and OSX (Yosemite)

Once you set up Minecraft for your family, you'll inevitably be asked to install mods to further enhance the game play.

Installing mods is both simple and annoying for a few reasons:

  • Mods aren't officially supported by Minecraft so there is no single way to install mods. 
  • This means that a mod built for version A might not work for version B.
  • Different mods might require different mod loaders and they might be in conflict with each other.
  • Just like apps on your mobile phone, some mods might not do what it claims to do and can be potentially harmful.
  • Many mods are served from sites that also tries to sneak in adware and malware on your machine when you try to download even if the mods themselves are okay.
  • Minecraft is built on Java and given the security issues a lot of OSs no longer comes with Java so you'll have to install it yourself.
  • If you install the official Java from Oracle (whether OSX or Windows), they try to sneak in adware on your machine as well!
I have been avoiding using mods but when the family demands it what can one do but to get it done?  So, after spending an afternoon learning about Minecraft mods, I thought I share with folks how I installed the VoxelMap mod for Minecraft version 1.8.x. on Linux, Windows and OSX.

VoxelMap is a mod that provides you with a map of your Minecraft world and also allows you to set way points so you can easily teleport to specific locations.  There are a number of mods that do similar things which I actually tried to get first but they either made it too painful to safely download (Xaero's Minimap) or wasn't available for 1.8.4 (Rei's Minimap and Zan's Minimap).  VoxelMap is a bit fancy but it's used by Youtubers that my kids watch so there's a degree of familiarity with it.

VoxelMap requires a mod loader called Liteloader to run.  Because mods are not officially supported by Minecraft, the community have come up with various loaders that provides simpler APIs that modders can use to write mods more easily.  However, because each of these API might be different there is a degree of fragmentation and conflicts between the mods that use different mod loaders.  It seems like Minecraft Forge is emerging as the leader (quantity of mods, support, books/tutorial that teaches using it), but a number of popular mods are also built on Liteloader.  Fortunately, Liteloader is compatible with Forge and in this guide I'm going to install both.

A final note before we dive in.  As of this writing, support for 1.8 is still somewhat "beta" for both Forge, Liteload, and VoxelMap (and pretty much any mod) and also I'm only going to install "client" mods since VoxelMap is just for the players and not a "server" mod which is that the clients connect to when playing multiplayers games.  For the server, it's going to be just the vanilla Minecraft 1.8.4 server that is officially released by Mojane.

Microsoft Windows


To install VoxelMap mod for Windows, you'll need:
  1. Java 1.6+ (to run the installers for Forge, Liteloader, etc).
  2. Minecraft 1.8.x client launcher
  3. Minecraft Forge for 1.8 (see below to avoid getting mislead by the download links)
  4. Liteloader for 1.8
  5. VoxelMap for 1.8

Java 1.6+


It's possible that you don't have Java installed on your system (Microsoft suggests that unless you really need Java, don't install it for security reasons.)  You can download Java from Oracle for free, but if you're not careful you'll get stuck with crappy adware (shame on a corporation like Oracle to use such underhanded tactics).  Fortunately, Microsoft now bundles Java with Minecraft launcher and you can use that version of Java to run the Forge and Liteloader installers.

The path to the Minecraft Java is something like this:  
C:\Program Files (x86)\Minecraft\runtime\jre-x64\<version>\bin\javaw.exe
You can find this by looking at the default Minecraft profile from the launcher and see what the executable path value it has.  Then from the command prompt (Run > cmd):
set JAVA_HOME="<path to java minus the javaw.exe>"
set PATH=%PATH%;%JAVA_HOME%

Minecraft 1.8.x Client Launcher


Simply download from https://minecraft.net/download and install it.

Minecraft Forge for 1.8 


When downloading Forge, avoid the obvious download buttons as they lead to the file hosting sites that tries to get you to download a lot of crapware, malware, adware, etc.  Instead, select "All Downloads" and click on the "i" next to the Installer link (we're NOT going to use the windows installer since it won't know where Java is) and select "Direct Download".

Liteloader for 1.8


As of this writing, only the developmental builds supports 1.8 so you'll need to download the latest snapshot.  Again, you just want to download the *.jar file rather then the windows .exe file.

VoxelMap for 1.8


You can find the download link from the VoxelMap page.  Make sure you grab the 1.8 version from the "Recent files" section and not from the "Download" button which grabs the 1.7.x version.

Installing Everything


Now that you've downloaded everything, the installation for Windows is fairly simple:

  1. Click on the Minecraft installer you downloaded from minecraft.net.  This will install Minecraft.
  2. Click on the launcher that it installed to start Minecraft.
  3. Click "Edit Profile" and change the version of Minecraft from "latest" to "1.8" (this is just a one time thing because Forge needs you to have run that version at least once).
  4. Click "Play"
  5. You can quit once the game menu comes up and change the profile back to latest at this point.
  6. Quit Minecraft completely.
  7. At the command prompt, install Forge with:  java -jar <path to .jar file>.  Select "Install client" then OK.  Start up the client again, pick the "Forge" profile and make sure everything works.
  8. Quit Minecraft.
  9. At the command prompt, install Liteloader with: java -jar <path to .jar file>.
  10. From the menu's "extend to" option, pick the drop down that says Forge... and then install.
  11. Start up the client once again, select the "Liteloader 1.8 with Forge..." profile and make sure everything still works.
  12. Quit Minecraft
  13. At the command prompt, copy the VoxelMap mod to the Forge mod directory:  copy <path to VoxelMap's *.liteload file> %APPDATA%/mods/1.8
  14. You're done!  You should now be able to play Minecraft with the minimap on your screen.

Linux


Installing on Linux is the same steps as for Windows except for the following:
  • Linux might already have Java installed, but if not then use the package manager to install openjdk and you shouldn't have to do anything else beyond that for Java.
  • The path to copy the VoxelMap mod (step 13 above) is ~/.minecraft/mods/1.8 (instead of %APPDATA%/minecraft/mods/1.8).

OSX

Updated:  Sept. 27, 2015 

OSX is more of a pain to set up because it only have Java 1.6 (and not even that unless you manually install it on Yosemite).

First, go through steps 1 to 6 as described in the Windows section (You might get prompted to install Java -- see below).

Just like Windows, the Minecraft launcher for OSX also comes with Java 1.8 so it isn't necessary to download Java separately.  OSX only have Java 1.6 so you should use the version that comes with Minecraft then the default OSX Java.

Java 1.6+


To install Java 1.6, you'll get a prompt the first time you try to start the launcher to install Java if it can't find it.  Simply click "More Info" and follow the instructions to installing Java.  This is fine for playing Minecraft, but doesn't work for Liteloader's installer as it requires 1.7+.

Minecraft Forge for 1.8


You should be able to install Forge just by clicking the installer file or you can do it from the terminal just like it is described step 7 above.
java -jar forge-1.8-*-installer.jar
Then selecting "Install client".

Once installed, start up the client and pick the "Forge" profile.

Liteloader for 1.8


Liteloader is a problem because Java 1.6, which is what Apple installs, doesn't work with the installer.  You can download Java from Oracle but just like the Windows version, you have to be careful or adware will get installed.

Instead, we'll let Forge install Liteloader for us so instead of running the Liteloader installer:
  1. Right click on the installer jar file and select "Open With > Archive Utility".  This should create a folder with all the files from the jar file.
  2. Using the Terminal, go to the folder and copy the Liteloader jar files to the mod directory: cp liteloader-*.jar ~/Library/Application\ Support/minecraft/mods
  3. Now start up Minecraft but continue to use the Forge profile.
  4. If everything starts up fine and it Forge is running then quit Minecraft
Liteloader somes with an installer which you can launch by using:
java -jar <liteloader jar file>
Or you can copy the file to the mods directory and have Forge load it since they are compatible.
cp liteloader-*.jar ~/Library/Application\ Support/minecraft/mods

VoxelMap for 1.8


Just like for Windows and Linux, you just need to copy the VoxelMap mod file to the Forge mod directory:
cp <voxelmap mod file>  ~/Library/Application\ Support/minecraft/mods/1.8

You can now start up Minecraft and see that the VoxelMap mod is loaded.

You're Done!


Now you should be able to use the VoxelMap mod whether in your single player game or if you connect to the 1.8.x server.

Wednesday, March 4, 2015

Mounting Shared Drive on Linux and Headless Bittorent Daemon

There are a number of different ways to automate the download of bittorrent files.  Many bittorrent clients have the ability to "watch" a directory and if a torrent files get added there then the bittorrent will automatically begin to download.  Some even don't need to download the file as it can subscribe to a feed directly.

GUI Way

What I did before was to log into a machine, connect to a shared drive and then open Transmission which was configured to look at the shared drive for any new torrent files.  I even wrote a program that grab checked and downloaded new torrent files every 24 hours.  Setting this up was extremely simple.  As part of my login items on OSX, I had it connected to my shared drive.  Then I would start Transmission and have it point to the shared drive to automatically download the torrents.  I used watch to execute my torrent downloads:

watch -n 72000 <program to download torrents>
I didn't use cron or anything because this was originally on a OSX laptop.

When I switched to a Linux machine that is kept on, I did the exact same thing.  The problem with this is that you're expected to be logged in to the system and keeping the programs running.  If someone else need to use the computer then everything stops since you'd have to log out.

Terminal Way

This similar to the GUI way described above except you do it in a terminal running in a tmux session so that you can disconnect without loosing your transmission job.  To connect to the shared smb drive without the GUI by using transmission-cli tool.

tmux
dbus-launch bash
gvfs-mount smb://<user>@<host>/<path-to-shared-drive>
sudo yum install transmission-cli
transmission-cli
You'd put in your user name and password as it prompts you when you mount the shared drive.  You'll need to configure transmission.

Headless Way

This doesn't require any GUI or terminal and can automatically starts at each boot.

Install the transmission-daemon

sudo yum install transmission-daemon
sudo systemctl start transmission-daemon.service
sudo systemctl stop transmission-daemon.service
The service file is in /usr/lib/systemd/system/transmission-daemon.service.

I started and stopped the daemon because you need to configure it through the /var/lib/transmission/.config/transmission-daemon/settings.json and this gets created when you first start (for other locations of Transmission files click here).  This will also install the transmission user

Next you need to mount the shared drive in order for transmission to access and ONLY transmission:

sudo mount -t cifs -o -credential=<path-to-credential>,gid=`id -g transmission`,uid=`id -u transmission` <mount point>
The credential value points to a file that contains your username, password and domain for logging into the shared drive.  Make sure wherever you store it that it's not readable by others.

The gid and uid belongs to the user you want to be able to do read-and-writes to the shared drive otherwise it'll only be root that can do it.  For Fedora, the user is "transmission"

If it works and you can read-and-write, you can move this into /etc/fstab:

//<host>/<path-to-file> <mount-point> cifs credentials=<path-to-cred>,uid={user id},gid={group id}
and then reload fstab:

sudo mount -a
Once you configure the /var/lib/transmission/.config/transmission-daemon/settings.json to your liking then fire up:

sudo systemctl start transmission-daemon.service
sudo systemctl enable transmission-daemon.service
This starts up the service now and also at each machine reboot.  The one issue is that transmission-daemon might start before the drive is mounted and then it won't look for the changes.  It needs to be told to wait.

Systemd will look at /etc/fstab and automatically create an unit that can be added to the service file to tell it to wait.  Running the systemctl command will show you an unit that can be used (it'll be something with a .mount suffix).

Add that unit to the After line:

After=network.target <mount unit>

Finally, set up a cron job to regularly check for new torrents:

crontab -u <transmission user> -e
With the value being something like:

0 23 * * * <path-to-program-to-run> >> /var/lib/transmission/download.log 2>&1
which says to execute the program every night at 11pm and store the out put in /var/lib/transmission/download.log.

Since the transmission users is disabled for an interactive shell, to execute commands as the transmission user, use:

sudo -u <transmission user> <command>

Thursday, February 26, 2015

Compiling Synergy on OSX 10.9 Maverick (and 10.10 Yosemite)

Synergy is an open source software KVM that allows you to use one keyboard/mouse across multiple computers.  Although Synergy is open source, hosted on Github and under GPL, its main developer(s) decided sometime last year to put the binary of the latest version behind a pay-wall.  There is nothing in GPL that prevents them to do so and I don't necessarily object to developers charging a fee for providing a service such as hosting for downloads (I used to buy Linux install CDs from Walnut Creek without a second thought), but I'm just not a fan on the way they're doing it.

The Synergy website looks and feel like one of those spam sites where they try to trick you into buying or downloading something with big call to action buttons while the actual link to download is kind of hidden.  For example, they have a big "Get Synergy" button which is the one that ask you to pay while links to github and a link for free binary downloads (although not of the most recent version since that's the one they want you to pay for) are tiny and hidden way a bottom of the page.  I guess it's better then those sites with a big button that says "Download Here!" (which actually takes you to some spam page) while next to it as a small font link is the actual download link.  Plus, paying for it doesn't seem to get you additional support or anything other then being able to download a pre-compiled binary.  Basically, their execution of it is the turn-off and I had to check a few times to make sure the site is legit and not a spam company trying to appear legit.

Since this is open source anyone can just download the source and build it themselves, right?  Well, not exactly.  The instructions for how to compile is not great, but worst is that the code itself doesn't build if you just get it from Github.  I'm trying to build on OSX since most Linux distro will have it already in a package to install, but Synergy doesn't have a Homebrew formula and Macports has not maintainer.  So, for OSX, you'll need to compile yourself.

The latest source doesn't work yet (I tried to build it and it errors out on compile), so I thought I get the last stable version and build from that.  Nope.  If you try to build strictly from the command line it fails trying to create the right build files because of problems with the toolchain it uses.  If you try to build with Xcode, you'll need to code sign it.  In order to build it, you'll need to patch the toolchain.  I found that someone in Korea fixed the toolchain to allow him to build Synergy for Yosimite, but his solution is actually also needed to get it to build on 10.9 Maverick

So here goes:

xcode-select --install
brew install cmake
brew install qt
Next you'll need to download the source from http://github.com/synergy/synergy.

When I grabbed the latest and tried their instructions for compiling, it didn't work.  So your choice is to pull from an earlier stable release.  That means either 1.6.2 or 1.4.x.  Note that the 1.6.x client can't speak to 1.4.x and even 1.4.18 client isn't compatible with 1.4.10 server.  Fedora 21, for example, comes with 1.4.10 so if you grabbed the latest 1.4.18 release it wont' work.

To build 1.6.2 on OSX Maveric, you'll need to change ext/toolchain/command1.py


./hm.sh conf -g1 --mac-sdk 10.9 --mac-identity Maveric
./hm.sh build
To build 1.4.18, this is the replacement ext/toolchain/command1.py

I realized after building 1.4.18 client that it won't work with 1.4.10 server, I decided to have every system on 1.6.2 even if I can't use a package manager for it.

Don't just have Synergy client talk directly to the Synergy server directly.  There's a chance that someone can be listening on your communication.  Instead, use ssh tunneling so that the communication is secure.  I also suggest using autossh so that it knows to reconnect if your client gets disconnected (e.g. laptop went to sleep).  You can install autossh through Homebrew.

brew install autossh

Saturday, February 21, 2015

Thoughts Fedora 21

Even though my primary home desktop the past few years has been a Macbook Pro, my favorite Operating System is Linux.  It would be my primary OS if it wasn't for a few tasks that aren't as convenient on Linux such as photo management (which any father will know has to be good or Mother will bring down the hurt), so at home it's been Homebrew to fill the void.  Because of this I haven't kept up with all the changes with my favorite distribution, Fedora.



I have tried various distributions here and there, but Fedora has always felt the most comfortable to me.  A lot of it obviously due to familiarity as I've been using Fedora when it was first conceived as Fedora Core and Redhat Linux before it (and Slackware before that).  When the time came to put together a new machine for the family for things like Minecraft and playing videos I naturally was going to go with Linux and Fedora which is now at version 21.

In version 21, Fedora now offers 3 separate versions targeted at 3 different needs:  workstation (what most home and office users will use), server and cloud.  I suppose the idea is to make the installation process easier as each version is preconfigured with the software and settings that they feel meets the most likely needs of the target audience.  I'm not sure if I really agree with this approach.  I imagine that most people who are capable and willing to get and install their own OS will be configuring their environment and this just defers that to after the installation.   At the same time, the install process is very simple.  Just a few clicks and off it goes so if you don't mind claiming every bit of disk space maybe this is perfectly fine.

It's nice that the Live CD is used to start the install because it does make the disc more useful and provides a sanity check that everything works before installing to the hard drive.  What I do miss is at install time it doesn't give you the option of adding other repos (how many Fedora users don't add RPMFusion?).  Instead, you finish installing Fedora and then install RPMFusion and then add the packages from it such as VLC.

I admit that I was a bit caught off guard by the default desktop environment: Gnome Shell.  It is simplified and familiar especially if you come from OSX with the way the settings dialog is laid out and the application dock, but might be an oversimplification for developers.  I suppose if the workstation version is targeted at the enterprise office space that it makes sense from that perspective.  Whether or not that is the right direction, I'll leave that for the market to decide.  It is telling that if you search online that one of the first things people recommend after getting Fedora installed is to add the gnome-tweak-tool to customize Fedora.

Fortunately, Fedora makes it very simple to change to another of the other popular desktop environments such as Mate, Cinnamon, Xcfe, etc.

Fedora comes with Firefox and Yahoo as the default search engine.  I have no objections to Firefox or its choice of Yahoo, but the browser is so fundamental now to anyone using a computer that offering more choices here would be best for the user.  Given that Fedora is very much about open source software, I can understand if Chrome is not a choice but Chrominum can be.

These are all very minor complaints and Fedora is still awesome.   

Saturday, January 3, 2015

Powerline compatible Terminus Font for OSX

My preferred programming font (and what I set for my terminals whether it's on Linux or OSX) is Terminus.  While it's not on most Linux distribution by default, it's usually available through the distribution's package management system (yum, apt-get, etc.).

On OSX, it's a little more troublesome.  A search on Google will turn up three different versions in the first three results.  In the past, I've used the one here. However, if you use something like powerline or vim-airline it doesn't have all the symbols so for some things it will just use the characters like '>>' and '>'.

To have those nice symbols, you generally need a 'patched' version of the font that has those symbols (this just means they added the characters to the font collection).  You can find versions of many popular programming fonts here.

You'll notice that Terminus is part of the collection except that the format that is included isn't compatible with OSX.  Thus, I have always had to live with the characters above.  The latest version of Terminus TTF from here now includes the powerline symbols and so I was able to install it and now my status bar looks like all those other pretty ones out there!

Thursday, January 1, 2015

OSX load order of your bashrc

If you run bash, OSX doesn't loading your .bashrc file.  The first looks for /etc/profile and then it looks in the following for the first available one:

  1. ~/.bash_profile
  2. ~/.bash_login
  3. ~/.profile
If you keep your file in a .bashrc file then probably the best way is to source it from .bash_profile.

Thursday, December 18, 2014

Building Protobuf on OSX

I wanted to play with protocol buffers on my local OSX machine but set up isn't so straight forward so I thought that I'd document the steps.

Step 1:  Get the build tools.

If you have all the build tools installed then skip ahead, but on the particular machine that I was using it didn't.   So I had to do the following:

Install Xcode command line tools

xcode-select --install

Install the GNU build tools (autoconf, automake, libtool):

curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
tar -xzf autoconf-latest.tar.gz 
cd autoconf-2.69./configure && make && sudo make install 
curl -OL http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz
tar -xzf libtool-2.4.2.tar.gz 
cd libtool-2.4.2./configure && make && sudo make install 
curl -OL http://ftpmirror.gnu.org/automake/automake-1.14.tar.gz
tar -xzf automake-1.14.tar.gz
cd automake-1.14 
./configure && make && sudo make install

Alternatively you can use Homebrew or MacPorts to get the packages.

Step 2: Get the Protocol Buffer Compiler and Build It

git clone git://github.com/google/protobuf 
cd protobuf 
./autogen.sh
configure
make 
sudo make install

Since I wanted to use protocol buffer in Go, I have to install the Go plugin for the compiler:

go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go 

The system can now compile your proto files to let you use it in your code:

protoc --go_out=. 

Saturday, August 17, 2013

Setting up Vim for Go

A more updated post on setting up VIM is here.

I've been playing around with the Go programming language recently and so I wanted to configure VIM to work better with it.  The Go package comes with vim plugins for syntax highlighting, indentation and helper functions which is a good start, but I wanted to have some of the nice things that I set up previously for other languages that used more frequently such as being able to jump to functions, auto completions, etc.  The Go community have made this dead simple and will only take a few minutes.

Auto-Completion

While I'm not a big fan of IDEs, one feature I always do want is context aware auto-completion (e.g. type in a partial function name and get a list of possibilities).  I remember using a Norton tool as far as the DOS days since I'm terrible at remembering the exact spelling of function names/variables, members, etc.

Gocode is a daemon that will provide this functionality.  It is a daemon that is editor-agnostic so it can be used by VIM, Emacs, Sublime Text, etc.  Setup is a one-liner:
go get -u github.com/nsf/gocode
Then use the vundle VIM plugin by adding this to your .vimrc:
bundle Blackrush/vim-gocode  
The plugin will automatically start the daemon if it is not already running or you can start/stop it manually.

I use the SuperTab plugin so that when I hit "Tab" that it brings up the autocomplete menu so I set this in my .vimrc:
 let g:SuperTabDefaultCompletionType = "context"
There you go!  Auto-completion for Go in VIM.

CTags/Tagbar

I use ctags to to let VIM know how to jump to declarations (e.g. cursor on a function name and jump to the function definition).  To add Go support to CTags, use the gotags package.
go get -u github.com/jstemmer/gotags
The README.md even has the VIM configuration for using with the Tagbar plugin!

Misc

I also added this to my .vimrc:
    au FileType go au BufWritePre <buffer> Fmt
    autocmd FileType go setlocal tabstop=4
The first line will run the Go code formatter whenever the file is saved.  The second line shows a tab as 4 spaces instead of 8 spaces that is the default for Go.

Friday, August 24, 2012

Shuttle XH61

The trend at our house has been to move away from having large desktop machines to smaller specialized devices (e.g. having a NAS instead of a server with big drives).  My wife's primary machine, which she used mostly as a desktop replacement, was an older Thinkpad x300 that started to show its age especially when it came to watching HD videos.  I decided to upgrade her machine but it must meet her criteria that it be small enough to fit into her desk drawer (don't want clutter) and at the same time powerful enough to run her apps (including Photoshop, Picasa, etc.), and watch videos. It also needs to be able to access all the various peripherals such as the printers and scanners that we currently have.

For portability we already have the Android tablet and a Google Chromebook (CR48) so portability was not as crucial as when we bought the Thinkpad.  At that time, mini PCs were non-existent or a joke of a machine.  Now, there are small powerful options that can do everything short of playing super high-end games.  My first thought was get a Chromebox.  I really like the ease and convenience of ChromeOS.  It's small, fast and does the majority of the things that people use their computers for these days (browsing the web and using web applications).  Another benefit is that it really have zero to low maintenance.  However, the one shortcoming of the Chromebox is its peripheral support.  I don't think it's able to use my network printer and scanner directly so I reluctantly gave up on the little beauty.

The next obvious option is the mac mini, but after mulling it over it feels underpowered for the price.  The starting price is not too bad, but the memory upgrade is expensive, there is no optical drive and I've been disappointed with Lion and Mountain Lion.  I also worry about the direction that Apple is going which seem to be to put a lot of restrictions on a general purpose PC to make it not general purpose.

After searching around for the mini-desktop PC, I finally decided to buy the Shuttle XH61 barebones system and put together a machine myself.  Along with the kit, I had to buy a CPU (Intel Core i7 2600S), memory (8GB), bluetooth adaptor, solid state drive and an optical drive.  The i7 comes with an integrated GPU so I don't need to buy a separate video card unless I plan to do highend gaming, but this is not the rig for that.  For the OS, I ended up going with Windows 7 instead of Linux simply for the ease of running my wife's apps.

Putting the system together was surprising easy.  Putting all the components (CPU, memory and SSD) in took about 30 minutes and it had no problems recognizing the external USB DVD drive on boot-up.  The machine is super quiet and the i7 is a speedy little sucker.  Installing Windows 7 was fast on the SSD, memory and network so her new machine was up in less then an hour.

Some shortcomings of the system include it doesn't come with any video cables for this video output (VGA or HDMI).  It doesn't have DVI (just analog VGA and HDMI), but fortunately I had a spare HDMI cable lying around.  It doesn't come with  bluetooth (needed for keyboard) or WIFI support (does have gigabit ethernet which is what I'll be using anyway).

All-in-all, it is a fine little system that runs super quiet and makes my wife happy.

Monday, February 20, 2012

Vundle to manage my VIM plugins.

To avoid getting too dependent on a VIM plugin that might not be available on the different machines I access, I've avoided having too many of them.  I mainly look for plugins that will make writing code faster since I do most of my development on just 2-3 machines.  Recently, a project required me to get back into Java programming.  Java projects are one of those that really seems to benefit from using some form of IDE especially for navigating through the code, but after trying Eclipse (which is pretty nice) I still felt that writing code is faster in VIM for me.

That lead me to Eclim which is an Eclipse and VIM plugin combo that allowed VIM to access Eclipse's functionality.  This is pretty cool as it allowed me to do most of my work in VIM and switch to Eclipse when I needed to.  While this solution works, I started getting the itch to see how VIM can handle some of the tasks I was depending on Eclipse for so I started looking at various VIM plugins which led me to research how to manage plug-ins in general.

Initially all the info I found talked about Pathogen which allowed each plug-in to be stored in its own directory and address the big problem of having all of your plugins clumped together in the .vim directories.  However, you still had to manually download and install each plugin.  Most users of Pathogen went the path of using Git to manage the plugins pulling each plugin from Git as a submodule.  I was about to give Pathogen a try when I came across Vundle.  Vundle take Pathogen and take it one step further by integrating the downloading and installation of your plugins.

Essentially, you install the Vundle plugin and then in your .vimrc list the plugins you want to use.  Start up VIM and do a ":BundleInstall" and it will download the plugins to their own directory and install/upgrade each one.  It's all very clean.

set nocompatiblefiletype offset rtp+=~/.vim/bundle/vundlecall vundle#rc()
Bundle 'gmarik/vundle'
Bundle "bufexplorer.zip"Bundle "snipMate"Bundle "SuperTab-continued."Bundle "taglist.vim"
Bundle "bufkill.vim"Bundle "Command-T"
 Having this at the top of your .vimrc and you can immediately see what kind plugins to use (remove one and Vundle will uninstall it for you as well).  If you share your .vimrc across multiple machine (i.e. through github) you don't have worry about keeping copies or download the plugins yourself since vundle handles all of that.

Saturday, February 18, 2012

Uninstalling MySQL on OSX

If you use the package installer to install MySQL (as opposed to building from source, from macports, etc.) then do the following when you want to remove MySQL:

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql*
rm -rf ~/Library/PreferencePanes/My*

Remove the line "MYSQLCOM=-YES-" from /etc/hostconfig
Remove entries in /Library/Receipts/InstallHistory.plist

Wednesday, March 23, 2011

Find out which app is using a port.

I always forget and have to do a search, but to find out the process using a port the following can be used:

lsof -i :<port>

or

netstat -p

Friday, January 15, 2010

Chrome OSX with Bookmark Manager

The latest dev channel build of Google Chrome now have a basic bookmark manager and cookie manager.

With a bookmark manager, even though it is very basic, Chrome for OS X has the basic set of features that I feel makes up a browser and might can make Chrome my default browser on OS X soon.