Saturday, June 23, 2012

The Power of Ctrl-Z

When working in the Linux shell I have often erroneously hit the ctrl-z "panic" button in a feeble attempt to undo a mistake I've made.  However, this habit comes from years of using GUI applications and in Linux takes on an entirely different meaning.  Instead of happily seeing my mistake fixed, I usually end up back at the prompt with some text as follows:
[1]+ Stopped                 vi back-end/upload.php
Most times I would utter a curse under my breath, and reopen whatever application I was working in (often VIM).
Today, I learned that in pressing Ctrl-Z, I have backgrounded the application I was using.  This would be equivalent dropping back to the desktop in the GUI world.  Essentially, the prompt is your desktop, after pressing Ctrl-Z you are sent back to the prompt and you are given the job number of the application you were working in (the number inside the square brackets).  To reopen an application, you call the foregrounding program, fg, with the job number as a parameter.  This site is where I learned this info.

Super useful!

Friday, June 22, 2012

Configuring a text editor for GIT on Windows

This one is pretty simple, but the syntax is maybe not so helpful.  Here's the story:

I am getting ready to lead a walkthrough for my company on how to use GIT (we make instruments, so software management is not at the forefront of most people's minds).  In thinking about how to deploy this walkthrough I realized that my affinity for VIM is probably not shared throughout the company.  The solution can be found in the command:
git config --global core.editor <editor_path>
The trick comes in setting the editor path.  When I set the editor path to the location on the file system using:
"c:/Program Files (x86)/Notepad++/Notepad++.exe"
I received the following errors:
$ git commit c:/Program Files (x86)/Notepad++/notepad++.exe: -c: line 0: syntax error near unexpected token `(' c:/Program Files (x86)/Notepad++/notepad++.exe: -c: line 0: `c:/Program Files (x86)/Notepad++/notepad++.exe \$@\' error: There was a problem with the editor 'c:/Program Files (x86)/Notepad++/notepad++.exe'. Please supply the message using either -m or -F option.
I think the trouble is due to how git is parsing the path of the editor, namely that it is seeing the spaces as argument separators. The problem can be fixed by placing an extra set of quotes around the editor path like so:
'"c:/Program Files (x86)/Notepad++/Notepad++.exe"'
Git will now see the editor path as one parameter.

One extra note, Notepad++ has lots of extra features that are nice when working on a project, but these can be a nuisance when editing your commit messages. The biggest offender is that by default Notepad++ will restore your session and open the commit message in a new tab. To prevent this default behavior some extra command line parameters are required. My final statement to configure the git editor is:
$ git config --global core.editor '"c:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*"'
Note: the "$*" argument tells bash where to place the arguments from GIT. More on special bash arguments here.

Happy GITing!

Motivate!

This blog has been on my list of things to tackle for a while.  In essence, I am thinking that this blog will be half notebook half informational walk-throughs.  As I venture down the road of new (to me) technologies, I'm sure I will encounter a number of obstacles along the way.  My plan is to record these obstacles here, as well as the solutions to surmount those obstacles.  Perhaps others will find this information useful, but if not I will certainly be happy to have it to look back on.  Off to my first post!