Setting up better shell and terminal environment for OSX Lion

Free (wannabe-pro) tips of the week for those who develop Javascript and Python on OSX.

1. Macports install poem

After fresh OSX Lion install,  install Macports to bring all the goodies of open source software to your computer. This will help get things running in shell and set up smooth Python development environment

sudo port install python32 python27 subversion perl5 nodejs npm \
  rsync sqlite3 wget curl py32-virtualenv py27-virtualenv \
  wget unrar zsh bzr bzip2 openssl jpeg libpng libxml2 libxslt \
  git-core git-extras coreutils lesspipe findutils highlight grep +with_default_names

(Macports 2.0.4. If you are upgrading Macports or OSX or XCode please see these migration notes and Lion / XCode 4.3 specific issues.)

2. GNU Userland

Then enable Macports GNU userland commads put the following into your shell .rc file:

export PATH=/opt/local/libexec/gnubin:/opt/local/bin:/opt/local/sbin:$PATH
export CLICOLOR=1
export LESSOPEN='| /opt/local/bin/lesspipe.sh %s'

This will give you nice colours in ls, etc. improvements over barebone BSD userland commands.

3. Sane text editor

Use your favorite non-terminal text editor from command line. Here is an example for Sublime Text 2 which is one of software developer text editors seeing active development under OSX

# Use Sublime Edit 2 as text editor inst
export EDITOR="'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl'"
alias subl="$EDITOR"
# Open file in a real text editor,
# if you happen to type nano from your muscle memory
alias nano="subl"

4. zsh

ZSH is a popular shell among power users with all kinds of plug-ins available. They will help you to deal with Git repositories, virtualenvs, and so on…

To change your shell to Macports‘ /opt/local/bin/zsh in System Preferences > User & Groups: right click on your user after unlockingthe dialog window.

I am also working with some friends with a zsh installer Ztanesh which comes with more powerful default settings for OSX and Linux.

5. Terminal

iTerm 2 is a better replacement for the default Terminal. (Terminal has some serious problems).

6. Disable Spotlight

Disable Spotlight indexing for better performance. Who uses Spotlight search anyway when you have grep?

sudo mdutil -i off /

Disable it also for your Legacy Filevault volume if you have one:

sudo mdutil -i off /Users/moo

7. Sync your configuration files

Some files you might want to save to your Dropbox etc. cloud storing service to share between your computers

8. Kill alt + spacebar character

Pressing alt+spacebar accidentally creates an invisible character which causes most source code go hayware. Disable this behavior.

9. All Python versions

They can be built with collective.buildout.python recipe. In the case you need to deal with ancient codebases (*cough* Plone 3 *cough*).

10. Still some open questions….

All hints and pointers welcome for the following

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+

JSLint integration for Sublime Text 2

Web developers are editing more and more Javascript. Because Javascript is very flexible language and has some bad parts from the past, you want to enforce linting software to validate your Javascript code against the good known best practices and avoid bad parts like global variables. One of such tools to enforce good practices is Douglas Crockford’s jslint.

Also note that Crockford’s best practices and style is not what everyone want and there is more flexible community maintained replacement called jshint available.

Sublime Text is a popular source code text editor among the web programmers. Below are instructions how to integrate jslint with Sublime Text.

sublime-jslint is available on GitHub.

1. Steps to install (OSX)

Install Sublime Package Control using console magic paste. You can open Console from View -> Show Console. (Wow it’s Python inside!)

Restart Subclipse.

CMD-Shift-P opens Package Control dialog (OSX).

Choose command Install package by start typing it.

In package list, type in jslint and it’s there.

In status bar you now see indicator Installing package…

Now turn on Run JSLint on Save. Go to Preferences > Package Settings > JSLint > Settings > User. This is the most convenient way to lint through your Javascript code piles.

Paste in:

{

    // Don't agree with Crockford about whitespace usage
    "jslint_options": "--white",

    // run jslint on save.
    "run_on_save": true,

    // debug flag.
    "debug": true
}

Save.

Restart Sublime.

Now when you save a .js file you see some output at the bottom of the screen:

2. Options

To see jslint4java options run

java -jar "/Users/moo/Library/Application Support/Sublime Text 2/Packages/sublime-jslint/jslint4java-2.0.1.jar

There is some room to configure it for your taste.

At least –white for sloppy whitespace usage is preferred, as one might not agree how Crockford wants to put his spaces.

3. Troubleshooting

Enable Sublime console to see what’s happening on the background. JSLint is being run with this kind of command:

java -jar "/Users/moo/Library/Application Support/Sublime Text 2/Packages/sublime-jslint/jslint4java-2.0.1.jar"  "/Users/moo/code/xxx/src/eric.cartman/eric/cartman/static/cartman.js"

Warning: For some reason Sublime execution or manual execution of this command didn’t give any output on my OSX first. Then it started magically working. I don’t know what happened.

4. Aptana Studio vs. Sublime Text

I did not find Sublime Text 2 productive Javascript editor for large scale projects as  Aptana Studio 3.0 I have been using before. Naturally Aptana Studio is much more heavy weight tool, but here are some highlights it does really well

  • The lack of smart comment new line behavior was a show stopper for a person like me who actually wants to comment his code – typing in every * is cumbersome and there is no support in copy-pasting text into comments
  • JSLint is run on background all the time in Aptana Studio (no need to save files)
  • JSLint warnings are highlighted in the code view and scrollbar
  • Aptana has Outline class browser
  • Aptana can highlight recently edited parts of file (though not specific to JSLint integration)

You can survive without the above features, but after used to them they will boost your productivity. I did not yet check jshint integration options for Sublime Text and if someone knows it can address some of the issues above please let me know.

 

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+