Sunday, December 9, 2012

Fedora 17 with ibam and ibamtray

I recently reinstalled Fedora 17 on my laptop and instead of using one of the default usual spins (Gnome, KDE, XFCE or LXDE) I wanted to try something different. A friend of mine who uses Arch mentioned he uses a combination of Openbox and fbpanel which he really enjoys. This sounded as good as any and noticing that the LXDE spin comes with Openbox, I installed that spin.

After everything was installed and I got fbpanel up and running, I tried to use the battery plugin that's built in but it didn't work. Assuming I figure that problem out, it will be the subject of a future post. In the mean time I installed ibam or Intelligent Battery Monitor. You can read about it at their sourceforge page. Initially it didn't work. I was getting an error 'No apm data available'. After some searching I found that the location for my battery information is:
/sys/class/power_supply/BAT0/ 
whereas ibam was looking in:
/sys/class/power_supply/BAT1/
That was a simple enough to fix. If you look in the ibam.inl file, you'll see this around line 962:
      acpi.close();
      apm = new acpi_status();
   } else {
      sysfs.open((sysfs_path+"/BAT1/charge_full").c_str());
      if(sysfs.is_open()) {
All that was needed was to change BAT1 to BAT0 and recompile, then I was good to go.

Next was to install ibamtry, a system tray frontend for ibam based on vubat found here. Unfortunately, that too was not working. Every time i would try to run ibamtray from the terminal, I would get this:

aerotachyon % ibamtray
Traceback (most recent call last):
  File "/bin/ibamtray", line 6, in <module>
    app.run ()
  File "/usr/lib/python2.7/site-packages/ibamtray.py", line 96, in run
    self.update_status ()
  File "/usr/lib/python2.7/site-packages/ibamtray.py", line 145, in update_status
    n.show()
glib.GError: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files
Everything I could find relating to the last line of the output had something to do with notification-daemon. I tried testing it by running:
notify-send "hello"
which failed produce a notification. I figured I should try running the daemon explicitly, but wasn't sure where it was in the filesystem to run it. Issuing the following command:
aerotachyon % whereis notification-daemon
notification-daemon: /usr/libexec/notification-daemon
gave me the location of what I needed to run. Once it was started, I tried sending a notification again with notify-send and it worked. From there I just needed to add the following lines to my Openbox autostart file to start the daemon and ibamtray upon starting Openbox:
/usr/libexec/notification-daemon &
ibamtray &
Now I have a nice battery monitor in the tray with notifications. In hindsight I'm glad the fbpanel battery plugin didn't work because ibam seems to be much more accurate at predicting discharge and charge times along with having better tray icons.

Monday, February 20, 2012

Vim Key Map For Fortran 77 Continue Line Character

I started learning Fortran because the code I would be working with in a research project was written in Fortran 77. As a result, the Fortran I learned was a fixed column format Fortran based on punch cards. The punch cards had 80 columns with the following format:

1-5: For statement labels, essentially line referencing.
6: For a continuation character to continue a previous  line (this is what we're interested in)
7-72: For statements, basically the actual code
73-80: Ignored by the compiler.

Since this was how I  learned Fortran, it is how I continue to use it. Eventually I got tired of manually adding the ampersand in column 6 of a line that is a continuation, so I set out to make the task much quicker.

I identified 2 different cases in which I would need to add the continuation character. The first was if I was typing a line that reached column 72. In this case I would be in insert mode and would like to press the key(s) I have the shortcut mapped to, and have the ampersand in the correct place on the next line with my cursor following it in insert mode to allow me to continue typing the line. To do this I used a key mapping as it would be quicker that the abbreviation I described here.

Key mappings in Vim are very easy to implement. The syntax is as follows:
:map key_with_mapping sequence_of_keystrokes_to_be_mapped
A simple example would be:
:map <C-g> o<esc> 
This will, when Ctrl-g is pressed, press 'o' and then 'Esc' which would open the next line in insert mode and the exit insert mode.

For my case, this is what I used:
 imap <C-a> <esc>o<home><space><space><space><space><space>&
Since I put it in my .gvimrc, I didn't need the leading colon. The imap just means that it only works in insert mode, whereas a vmap would work in visual mode. So, when I press Ctrl-a in insert mode it escapes to visual mode, opens the next line in insert mode, moves to the first column of the line, enters 5 spaces, then the ampersand. I'm left with the ampersand in the correct place with the cursor in column 7 in insert mode ready to continue my line of code.

More information on Vim key mappings can be found if you type:
:help key-mapping
while in visual mode in Vim.

I'll add my second case for adding the continue line quickly in the near future.

Tuesday, February 7, 2012

Commenting Multiple Lines in Vim

I do a bit of programming in Fortran and periodically I find myself wanting to comment out a block of code for whatever reason. In Vim this is relatively easy. Just highlight the lines you would like to comment and type:
:s/^/\!
The s is for subtitute, the ^ character designates the front of each line, and the exclamation (which has to be escaped with the \ character) is the comment character for Fortran. This can be replaced by any comment character the language you may use requires, but not all characters will need to be escaped like the exclamation does. Similarly to uncomment selected lines:
:s/^/\!/
 Now, I find this tedious and frustrating to type in and/or remember. To streamline the commenting and uncommenting process, I make use of abbreviations. Essentially, you define an abbreviation and what should be substituted for that abbreviation. When you type the abbreviation, Vim will automatically substitute it for you. The syntax is as follows:
:ab <abbreviation> <unabbreviated substitution>
where ':ab' is the command  (you type this in the Vim window), <abbreviation> is what you type, and <unabbreviated substitution> in what replaces the abbreviation. Also note that spaces in the unabbreviated substitution are acceptable. You also do not inclue the '<>' characters.

Here is how it would work with commenting multiple lines:
:ab com s/^/\!
:ab ucom s/^/\!/
Now, all you need to type in once the lines are selected is,
:com
:ucom
to comment or uncomment those lines.

This method will only work for the particular instance of Vim that you are working in, meaning you would need to type this at the start of each session. An easier method would be to place the commands in your .vimrc or .gvimrc file, without the leading colon, and they will be defined every time you start up Vim.

Monday, January 23, 2012

Hopefully, A Beginning And Not The End

For the most part, I am a inexperienced Linux user. This requires extensive use of google, hoping any problems I have are common enough that I can find solutions rather quickly. Every now and again I run into that dreaded thread, depicted in this xkcd comic: http://xkcd.com/979/. The purpose of this blog is to document all problems and solutions I come across in my Linux endeavors for the reference of others (hence the name of the blog), and for myself.

Most of what I have learned has been from trying to understand the commands I am told to run, as opposed to posting output and waiting for the next command. As a result, my goal is to explain everything clearly enough that something is learned from reading a post, in addition to fixing the problem.

There is no set schedule for posts. I simply will post solutions to problems as I come across them, assuming I have the time. A friend of mine will also help with contributions on the same basis. Hopefully, at some point, we'll help someone.