Category Archives: Mac

#Java version switching on #OS X

If you have to deal with several projects that are based on different versions of Java here is how I’m solving this.

Recently I found out built-in OS X capabilities to switch between different version of Java installed on your system. After some period of time using it I come up with aliases to easily switch between Java versions installed on my machine, here are they:

alias j6='export JAVA_HOME="`/usr/libexec/java_home -v 1.6`"'
alias j7='export JAVA_HOME="`/usr/libexec/java_home -v 1.7`"'
alias j8='export JAVA_HOME="`/usr/libexec/java_home -v 1.8`"'
alias j9='export JAVA_HOME="`/usr/libexec/java_home -v 1.9`"'

Laptop from scratch with #boxen and #puppet under the hood

I believe you already heard about DevOps and Infrastructure as a Code ideas. This concept stuck into my mind some time ago for development purposes and  to manage project related infrastructure, I even gave a talk at JEEConf this year (20013), here is a link BTW Избавьтесь от рутины конфигурации окружений JEE проектов с помощью Vagrant (talk is in russian).

Well this note is something a bit different but quite closed. Recently I’ve got an idea to throw everything out of my MBP and have every software/app I need to be installed in controlled way e.g. using Boxen (source code @github). If to say in 2 words Boxen is an automation of configuration of development environments for OS X (currently there is just OS X support, Puppet that is used under the hood supports other OSs as well though).

So it took some of my spare time to back up everything I had on my laptop before, then erase hard drive and reinstall OS X from scratch. After that I cloned https://github.com/boxen/our-boxen and started my journey. There is my Boxen‘s repo https://github.com/webdizz/my-boxen with some things I have right now built and configured with it. I said some things because it’s an incremental way and it takes some time to automate parts of infrastructure I have on my laptop. Currently there are all applications, software like Git, Ruby, Java, OS preferences and configuration of apps like Emacs, Vim, Terminal (iTerm2 I’m tasting it right now). I really like a concept of dotfiles, my is here https://github.com/webdizz/dotfiles, and Boxen has quite straight forward support of it.

Additionally there is a way to amend your working space configuration with private dotfiles. For example, your SSH configuration, aliases for intranet servers etc. could be added into private dotfiles repository and easily managed with Boxen.

There are useful links to get started with Boxen:

  • http://boxen.github.com/
  • http://garylarizza.com/blog/2013/02/15/puppet-plus-github-equals-laptop-love/

Enjoy to control your laptop build process incrementally and repeatable way.

Tmux with teamocil

Several days ago I was suggested to check usage of Screen to not to switch between open tabs in Terminal.

Several words about Screen fo those who do not know what is it. There is an excerpt from Screen home page:

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. Each virtual terminal provides the functions of the DEC VT100 terminal and, in addition, several control functions from the ANSI X3.64 (ISO 6429) and ISO 2022 standards (e.g., insert/delete line and support for multiple character sets). There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows the user to move text regions between windows. When screen is called, it creates a single window with a shell in it (or the specified command) and then gets out of your way so that you can use the program as you normally would. Then, at any time, you can create new (full-screen) windows with other programs in them (including more shells), kill the current window, view a list of the active windows, turn output logging on and off, copy text between windows, view the scrollback history, switch between windows, etc. All windows run their programs completely independent of each other. Programs continue to run when their window is currently not visible and even when the whole screen session is detached from the users terminal.

But I have something more useful for me then Screen this is tmux. BTW I have a post regarding it “Tmux cheat sheet“. But here I’d like to describe what I’ve found more regarding tmux. There is a nice ruby gem teamocil for session/pane configuration with simple YAML file.

Now I have several configuration files to support my console activities on several projects at once without constant reconfiguring windows.

Here is a simple sample what can be done with teamocil.

windows:
  - name: "local"
    clear: true
    options:
      synchronize-panes: false
    root: "~/dev/projects/tasil"
    filters:
      before:
        - "source ~/.bash_profile"
    splits:
      - cmd: ["ssh tasil@vm.tasil"]
  - name: "remote"
    clear: true
    options:
      synchronize-panes: false
    root: "~/dev/projects/tasil"
    filters:
      before:
        - "source ~/.bash_profile"
    splits:
      - cmd: ["ssh tasil@some_remote_host"]

Configuration of my MacBook Pro was done using steps from this gist https://gist.github.com/4545794

 

Mac OS X command-line bash keyboard shortcuts

Recently found out list of useful keyboard shortcuts for bash at Mac OS X.

There is a list of the bash default keyboard editting shortcuts configured on a Mac OS X.

CTRL+a – move cursor to beginning of the line. (I think of this as anchoring my cursor to the start.);
CTRL+e – move cursor to the end of the line;
CTRL+k – delete everything from under the cursor to the end of the line. (I think of this as killing the rest of my line.);
CTRL+f – move forward one character. Identical to →;
CTRL+b – move backward one character. Identical to ←;
ESC+f – move forward one word;
ESC+b – move backward one word;
CTRL+u – delete everything from under the cursor the beginning of the line;
CTRL+w – delete from under the cursor to the beginning of the word;
CTRL+r – recall previous commands by searching for them;
CTRL+t – transpose (swap) the two characters before the cursor with one another;
ESC+t – transpose (swap) the two words before the cursor with one another;
CTRL+y – paste the most previously-deleted string. Basically a sort of command-line editting “undo”;
CTRL+z – stop the current process and send it to the background;
CTRL+c – send an SIG_HUP to the current process. The net effect of doing this on the command line is that you cancel your current command and are presented with a blank new line;
CTRL+d – send an end-of-file special character to the current process. Doing this at the command line is identical to closing your terminal window;
CTRL+p – recall previous command executed. Identical to ↑;
CTRL+d – forward delete;
CTRL+h – backspace;
CTRL+j – carriage return. Identical to hitting the return key;
CTRL+m – newline. Identical to return;
CTRL+l – repaint screen. This is useful if a program’s output is overwriting some text on your terminal. The effect of doing this on a command line is that you clear the screen. Note than in Apple’s Terminal.app, you can also press +K to clear the screen;
CTRL-x + CTRL-x – mark current location in line and jump to beginning of line or second mark if defined. Repeat to jump to between both marks;
ESC+c – capitolize word under cursor and move to next word;
ESC+u – uppercase word under cursor and move to next word;
ESC+l – lowercase word under cursor and move to next word;
ESC+. – insert last word from previous command after cursor;
TAB – Auto-completes file, folder, and program names;
ESC-? – list the possible completions;
CTRL-x / – list the possible filename completions;
ESC-/ – attempt filename completion;
CTRL-x ~ – list the possible variable completions;
ESC- ~ – attempt username completion;
CTRL-x $ – list the possible variable completions;
ESC-$ – attempt variable completion;
CTRL-x @ – list the possible hostname completion;
ESC-@ – attempt hostname completion;
CTRL-x ! – list the possible command completions;
ESC-! – attempt command completion;
ESC-TAB – attempt completion from previous commands in the history list;

Enjoy.

Git auto-complete for Mac

If you faced with problem that out-of-the-box Git under Mac has no auto-complete functionality you can go this way:

curl https://github.com/git/git/raw/master/contrib/completion/git-completion.bash -OL

Copy it to, for example,

cp git-completion.bash ~/.git-completion.bash

Then open your ~/.bash_profile or ~/.profile and append next string

source ~/.git-completion.bash

Thats’s it 🙂