Opening files in apps using terminal

Sometimes it’s so handy to open a certain, probably hidden, file with your favourite code editor or at least TextEdit or Notepad. Take that, nano!

The following command will help you out with that. Let’s open Homestead.yaml, located in ~/.homestead with good old Sublime Text:

open -a 'Sublime Text' ~/.homestead/Homestead.yaml

If the app name doesn’t contain spaces, you can lose the quotes.

Git commands

Improve your speed!*

git commit -am 'commit message'


git add -A
git commit -m 'commit message'

You be the judge.

* That works only if the file is already being tracked.

Busy ports

As it often happens, you need to run a local server on a certain port. Let’s pick port number 3000 for this particular example. Sometimes, for whatever reason, that port is busy. And sure enough you will get an error, like this NodeJS one:

Error: listen EADDRINUSE

This is easily resolved with two steps.

1. Find the PID (process ID) that’s using that port:

lsof -i :3000

You will see a table containing some information, where the 2nd column is the PID we’re looking for. It’s a number basically, like 36185

2. And kill the process:

kill -9 36185

Now you can start your server or use the port the way you intended.

There are a few discussion whether to use kill -9 or kill -15, since the -15 options “gives the target process a chance to clean up after itself.” However, often it doesn’t shut the process down and you end up using -9 anyway. You can read more about that issue here.

Switching CTRL to ALT in Ubuntu

Being an OS X user, the hardest thing about using Ubuntu is that Command (CTRL on Ubuntu) is not next to Space. What you find near the Space key is the ALT button.

After googling the shit out of this problem, I wasn’t able to find a solution that would fit my needs.

Many tutorials and articles advise that you have to edit the /usr/share/X11/xkb/symbols/pc configuration. That did the trick partially, but removed the Meta functionality of ALT. That basically messed up things like ALT+TAB or CTRL+ALT+T.

To fix that we need to edit a tiny include, which adds "altwin(meta_alt)" to the map.

Navigating to /usr/share/X11/xkb/symbols/altwin opens a configuration with various mix-ins. And our meta_alt guy is the first in that list. The final code should look like this in order to achieve the magic:

xkb_symbols "meta_alt" {
  key <LALT> { [ Control_L ] };
  key <LCTL> { [ Alt_L, Meta_L ] };
  key <RALT> { type[Group1] = "TWO_LEVEL",
               symbols[Group1] = [ Alt_R, Meta_R ] };
  modifier_map Mod1 { Alt_L, Alt_R, Meta_L, Meta_R };

After that, you should restart the X-session and it should be working as expected.

sudo service lighted restart

Note: I’m using Ubuntu 14.04.