Pages

26 June, 2011

Using gedit's External Tools Plugin to Search in Files

IDEs for strongly typed languages allow you to press a hotkey (e.g., F3 in Eclipse) to look up a type or use features like "where used" to find all references of class, property, or method.

When hacking Javascript in gedit I also very often need to find all references of variables, object properties, and functions. But when coding with a weakly typed language like Javascript in gedit you do not have any shortcut to success. At least not by default.

Searching manually is not an option as soon as your projects grow larger. Firing up the gnome-search-tool is also not an option, since it would require further clicking in the dialog and cannot open gedit at the correct line.

Super Simple Search Script
Currently, the best option for me is to use this little script:
#!/bin/sh
args=$(xargs)
echo "searching for '$args'"
grep -nr $args * | sed 's/\(^[^\:]*:[0-9]*:\)/\1 /g' 
It simply looks up the current word in all files of the current document's directory and outputs "filename:line-number: matching line's text" in gedit's bottom pane. Output text using the "file:line:text" pattern is clickable in gedit and lets you jump to the line in the file immediately.


Installation
To use this script in gedit you need to enable the External Tools Plugin. Add a new entry in the plugin's configuration screen, name it, assign your hotkey, and select "Current word" as "Input". Finally copy the script code into the text area and check if everything is correct. Look at the first screenshot to check if everything is set up correctly.

Now you can finally test your new tool. Open a file and select a word. You can also set the cursor before any of the characters of the word. Now press your hotkey (F3 in my case) and the script should check your current file's directory for other files containing the word. Look at the second screenshot to see a sample result.

I hope you liked this article and that the script is useful for you.
Best wishes, Juve


20 June, 2011

Motorola Update Hell

Last week I tried to update my Motorola Defy mobile phone. It is an Android 2.1 device and the people in the US could simply update via WiFi or 3G to Android 2.2. Unfortunately Motorola decided to do a more complex scenario here in Europe.

And whoever decided this strategy is hopefully not longer working for that company. The process requires an external PC and is a big mess.

After many hours trying to update on several machines I finally got my Android 2.2. Here is what I went through.

The Painful Path
  1. I checked the Motorola site and several sources on the web how to update.
  2. According to some sources, I should have been notified of the update directly on the devices, which did not happen.
  3. Then I tried to update via the Android system settings: "No updates for you, sorry guy".
  4. Obviously European mobile network providers require a more complex update approach, even if I have a retail version of the phone, not tied to any provider.
  5. Checking the web again. OK, I need an update software from Motorola.
  6. I found it on their site and downloaded it. OMG, it is an exe-file! It was of course not working on WINE and there was no update software for Linux.
  7. I assumed that this exe-file neither runs on my friends Mac nor my collagues iPads.
  8. Dammit, I had to find a Windows PC, but who owns such old-fashioned devices anymore?
  9. Then I remembered my old Windows XP image, on one of my hard drives. Fortunately it was still there and also tied to the GRUB as last entry to be chainloaded. I fired it up and it still worked.
  10. Yeah! Let's start the funny exe-file: "Motorola requires Internet Explorer 5.5 or above." What the heck? Why does an mobile device update software require and antiquated web browser? For security reasons, I disabled this leaky browser before this Windows image was installed and I will not install it now. Nobody dictates me what to install and what not. That's why I use Ubuntu, my current(!) Linux of choice.
  11. OK, I had to find another Windows device. But where to search? I wont tell you where I finally found my Windows device - the owner was a bit ashamed of still owning it - but we got the update running. He still had the leaky Internet Explorer installed even if he never used it. The update also requires the .NET framework, which was luckly already installed.
  12. Then the update software went a bit amok forcing the notification icons going wild. The notifications told us vigorously about "new devices", "failed driver installations", and "ready devices". I don't know how many times the notification flashed but that I had to start the software a second time and again let it try to dig all its system-related components into the Windows machine. OMG! Fortunately that was not my machine. :)
  13. After all this fiddling it would finally recognize the device, download the update, and install it. Done!
"Luckily" the Defy will not get an Update to 2.3. ;)

Btw., did I tell you that I did not have to install anything when I plugged my phone into my Ubuntu Linux PC and I could start development for Android immediately?

I really don't know why Motorola has built such a complicated update for its European phones. But I hope that next time they will consider the growing number of users of Macs, iPads, Android-based Pads, and even Desktop Linux PCs. The Wintel era is coming to an end.

Update: A few days ago, I send a mail to Motorola's CEO again telling them about me not being happy with their update strategy. It was obviously read by their IT support. Thereafter, they replied on my former support ticket, telling me that they read this blog entry and congratulating me on my update success.
They promised to forward my valuable feedback to the responsible departments. Very nice!

Ciao,
Juve


19 June, 2011

Connect gedit to Firebug


Did you ever jump back and forth between Firebug and gedit or other text editors, searching for the line you were just debugging/editing? 
Stop doing this manually! Firebug provides you with an "external editors" feature and allows you to jump to the right line in your code in the editor.

Here are some screenshots to show you how it looks like. First, I right click a line (e.g., line 7) in Firebug and select "gedit". Firebug/Firefox then calls "gedit myfile.js +7" making gedit get focus and jump to line 7.

Setup
Setting up gedit or other tools as external editors is really easy. I wonder why I did not try this earlier. Open Firebug and the Firebug option menu. Select "Open with Editor > Configure Editors".
Now click "Add", give the editor a name, select an executable and edit the command line arguments. Firebug can forward the current %url, the local path to the %file, and the %line number via the command line.
In my case, man gedit revealed that both file and line can be forwarded to gedit with the simple pattern gedit filename +linenumber, and therefore, gedit's arguments string in Firebug would be %file +%line.


That's it, I hope you could learn something new.
Ciao,
Juve