Software

23 articles

Hide Vimperator bottom bar

Vimperator bottom bar

Copy the following snippet in your Vimperator configuration file (mine is ~/.vimperatorrc):

map <silent> <C-F8> :js toggle_bottombar()<CR>

:js << EOF
function toggle_bottombar() {
  var bb = document.getElementById('liberator-bottombar');
  if (!bb)
    return;
  bb.style.height = (bb.style.height == '') ? '0px' : '';
  bb.style.overflow = (bb.style.height == '') ? '' : 'hidden';
}
EOF

Restart Firefox, then type ctrl+F8 to hide/show the bottom bar. As the author warns, you must first make the bar visible in order to execute commands.

This is useful to me when watching a video in fullscreen because the bar is always on top.

Source

GNU/Linux: read-only file system error when accessing FAT/FAT32 drive

Sometimes and for no obvious reason, I suddenly cannot write or delete a file located on a removable USB drive using a FAT file system. Having no knowledge about all the magic going on under file system operations, I can just observe that some actions previously done successfully on some drives are no longer possible!

$ rm -r /path/to/some/obsolete/data/*
rm: cannot remove '/path/to/some/obsolete/data/data1': Read-only file system

It happened a few times in the previous years and I think it always involved FAT, but this is maybe not limited to that file system. We can easily solve this issue by running fsck, in this case in the form of its vfat variant:

$ sudo fsck.vfat -a /dev/sdc1

Replace /dev/sdc1 with your rebellious partition. The -a flag tells fsck to automatically repair the file system. The man page warns to use this feature with caution. You may prefer the -r flag which makes fsck asking you confirmation.

Note that fsck comes with lot of flavors, such as fsck.ext2|3|4, fsck.msdos, fsck.nfs... You may have to install some of them depending on your GNU/Linux distribution.

Arch Linux upgrade fails because some file exists in filesystem

From time to time, pacman refuses to upgrade because of a file conflict. Since it does not want to take the responsibility of overwriting an existing file which might be used by another package, it displays the following error:

error: failed to commit transaction (conflicting files)
freeimage: /usr/lib/libfreeimageplus.so.3 exists in filesystem
Errors occurred, no packages were upgraded.

In this case, pacman tries to install the package freeimage, which contains a file named libfreeimageplus.so.3, but detects that a file with the same name exists at the same location.

To solve this conflict, we first need to verify that this file is currently not owned by another package:

$ pacman -Qo /usr/lib/libfreeimageplus.so.3
error: No package owns /usr/lib/libfreeimageplus.so.3

The above message means we can safely (re)move this file. Since we are cautious people:

$ sudo mv /usr/lib/libfreeimageplus.so.3 /usr/lib/libfreeimageplus.so.3.back

We repeat this procedure each time we see this error, then the next pacman -Syu should go smoothly. If pacman -Qo should return something like this:

$ pacman -Qo /usr/lib/libfreeimageplus.so.3
/usr/lib/libfreeimageplus.so.3 is owned by freeimage 3.16.0-2

Then it is probably a bug!

Source

Insert text from a file recursively using sed

To add some context, my goal here was to insert a copyright statement at the start of each PHP file present in my working directory. I knew how to replace the content of a file with the sed utility, so I first started to look for a way to read input from a file.

It appears that the GNU version of sed can do it by using the r option, which stands for "read". So to make sed insert the content of a file named header after the first line of the PHP file source.php:

$ sed '1r header' source.php > source.php.temp

The use of redirections force us to create a temporary file. Redirecting directly to source.php would give us an empty file! Fortunately, there is a utility called sponge, from a collection of tools called moreutils1, which allows us to redirect the modified content to the same source.php file:

$ sed '1r header' source.php | sponge source.php

Now, all there is left to do is executing that command on each PHP file present in the main directory and all its subfolders. For that, I just wrote a for loop in a bash script but I learned how to select all the files recursively using the following glob pattern: **/*.php

This is available from bash v4 and to use it in a script, just add the following line before:

shopt -s globstar

1 The moreutils package is available on Arch Linux in the community repository.

Source

Linux: display images type and size in command line

Front-end developers probably often need to verify the properties of some images like their type or their dimensions. To avoid firing Gimp or similar software just for a quick look, GNU/Linux distributions1 offer as usual handy tools like identify, coming from the ImageMagick suite.

$ identify /home/didier/images/myimage.jpg
/home/didier/images/myimage.jpg JPEG 502x482 502x482+0+0 8-bit sRGB 31.7KB 0.000u 0:00.000

You can of course use glob patterns to display several images at once:

$ identify /home/didier/images/gnulinuxrocks*
/home/didier/images/gnulinuxrocks.png PNG 54x84 54x84+0+0 8-bit sRGB 190c 1.6KB 0.000u 0:00.000
/home/didier/images/gnulinuxrocks-even-more.png[1] PNG 42x84 42x84+0+0 8-bit sRGB 187c 1.5KB 0.000u 0:00.000
/home/didier/images/gnulinuxrocks-arch-logo.jpg[2] JPEG 396x140 396x140+0+0 8-bit sRGB 7.14KB 0.000u 0:00.000

Don't forget to check the manual for many more options.

$ man identify

1 I know, ImageMagick is available on other operating systems but I prefer trolling... though installing it on a GNU/Linux distribution with a package manager is way simpler and safer!