iTerm2: Add Keystroke to move between words

On a Mac, I use iTerm2 as my default terminal due to the added features, such as auto-copy and the ability to split multiple terminals. One nuance was not having the ability to move between words (like in vim); however, I found the below how-to on Stack Overflow — where else? 🙂

  1. Go to Preferences, Profile, Keys.
  2. Set your left ? key to act as an escape character.
  3. Locate the current shortcut for ? ? or create a new one, with the following settings:
    • Keyboard Shortcut: ??
    • Action: Send Escape Sequence
    • Esc+: b
  4. repeat for the ?? keyboard shortcut with the following settings:
    • Keyboard Shortcut: ??
    • Action: Send Escape Sequence
    • Esc+: f

From this point, you can use Option + [left/right arrow keys]. Yass, productivity skill level increase! Later.

My custom bash prompt

I wanted more information in my bash prompt, such as date/time and the directory I was in.  Here’s what it looks like:

bash_prompt

And this is what I added in my ~/.bash_profile:


PS1='${debian_chroot:+($debian_chroot)}\d \T > \[$(tput sgr0)\]\[\033[01;32m\]\u@\h\[\033[00m\] : \[\033[01;34m\]\w\[\033[00m\]\n\$ '

Run source ~/.bash_profile and enjoy. 🙂

BTW, there’s also a website that you can use to create your own: http://bashrcgenerator.com/.

IntelliJ IDEA: Create JUnit Test method code snippet shortcut

I’ve been using IntelliJ over Eclipse for a while now, mainly because it feels newer and more tuned to develop with Maven-based projects. This is just me. Anyway, if you do TDD, you’ll want to take advantage of IntelliJ’s Live Templates.

In this post, I’m writing about adding JUnit test code snippets, like so:


@Test
public void testSalutationMessage() {
    System.out.println("Inside testSalutationMessage()");
    message = "Hi," + "Anton" + "!";
    assertEquals(message, util.salutationMessage());
}

You could copy-and-paste an existing method and modify it, type it manually each time, or just type “test” and hit the Tab key and, voila, it’s there! I bet you’d choose the latter…to do this in IntelliJ:

1. Go to Preferences -> Live Templates
2. Click the ‘+’ sign on the right (close to Reset)
3. Add the following:


Abbreviation: 
test

Description: 
JUnit Test Method (or whatever you like)

Template Text:
@Test
public void test$NAME$() throws Exception {
    $BODY$
}

4. Leave “Shorten FQ names” checked
5. Click on “Change” and check “Java”
6. Apply and try it out (i.e. typing “test” and hitting the Tab key should add your code snippet)

Hope this helps! Till the next. 🙂