console.systems

Expanding wildcards with qmake

Tuesday, March 26, 2013

I was always wondering why doing something like this never worked

SOURCES += *.cpp
SOURCES -= excluded.cpp

excluded.cpp always stayed in SOURCES. The thing is that when you add a new value to the list, it’s just a string. Thus using wildcard in files names is nothing more but an asteriks character. And therefore using -= operator will only remove exact strings. But today I found another undocumented function I’ve been looking for years!

$$files(glob) — Returns a list of files which match the specified glob pattern.

So now I can do

SOURCES += $$files(*.cpp)
SOURCES -= excluded.cpp

and it actually works.

Enable icons in menus and buttons for Qt apps in Ubuntu 12.04.2

Wednesday, March 20, 2013

Way too many things broken in recent Ubuntu releases, should have stayed on 10.04 forever perhaps. Anyways, there is a fix:

$ gconftool-2 --type boolean --set /desktop/gnome/interface/buttons_have_icons true
$ gconftool-2 --type boolean --set /desktop/gnome/interface/menus_have_icons true

Shortcut to show folders first in Nautilus

Saturday, November 24, 2012

I really miss a menu shortcut in Nautilus to toggle “Show folders before files” option. Going to preferences every time is too much hassle.

But there is other way to toggle it using dconf or gconftool. For Ubuntu 12.04 or newer I suggest using dconf, install it if you don’t have it yet.

Create a script with the following content:

#!/bin/bash

# Version: Sun Sep 8 2013

OLD_VALUE=
LSB_RELEASE=$(lsb_release -sr)

if [ $LSB_RELEASE \< '12.04' ]; then
    OLD_VALUE=$(gconftool --get /apps/nautilus/preferences/sort_directories_first)
else
    OLD_VALUE=$(dconf read /org/gnome/nautilus/preferences/sort-directories-first)
fi

NEW_VALUE='false'
if [ $OLD_VALUE == 'false' ]; then
    NEW_VALUE='true'
fi

if [ $LSB_RELEASE \< '12.04' ]; then
    gconftool --type Boolean --set /apps/nautilus/preferences/sort_directories_first $NEW_VALUE
else
    dconf write /org/gnome/nautilus/preferences/sort-directories-first $NEW_VALUE
fi

If you have older Ubuntu, dconf maybe not available. Uncomment gconftool lines and comment dconf ones.

UPDATE 2013: the new version of the script works across all versions of Ubuntu.

Save the script somewhere, I prefer to keep mine in ~/.bin. Also give it execute permissions.

The next step may vary depending on Gnome version, I will describe it as it’s in Ubuntu 12.04. Go to keyboard shortcut setting and add a new custom shortcut. The command field set to path to the script we just created, in my case it’s ~/.bin/nautilus-folders-first.sh. You may also try to set full path if relative doesn’t work. Right click on the shortcut and set an actual hotkey combination. Choose something that doesn’t interferer with any other application, the shortcut is going to be system global. Ctrl+Alt+[some key] is good choice, I prefer Ctrl+Alt+F.

Now open Nautilus and browse where you have both files and folders, test the shortcut. If it doesn’t work, try the script in terminal and see if there are any errors.

Using Focusrite Scarlett 18i6 in Linux

Saturday, September 8, 2012

With the current 1.0.25 ALSA release you need to do some hacking to get Scarlett working. But the hack is as simple as it can be.

Download the tarball ftp://ftp.alsa-project.org/pub/driver/alsa-driver-1.0.25.tar.bz2 and comment the call to snd_usb_create_mixer() on the line 517 in alsa-kernel/usb/card.c so it would look like:

if (err > 0) {
    /* create normal USB audio interfaces */
    if (snd_usb_create_streams(chip, ifnum) < 0 /*||
        snd_usb_create_mixer(chip, ifnum, ignore_ctl_error) < 0*/) {
        goto __error;
    }
}

Build and install:

$ ./configue
$ make
$ sudo make install

Considering a bad practice to use sudo make install, in our case you don’t need to worry. Just reboot and select Scarlett as a default device in Sound Settings. Voila!

To restore Scarlett after reconnecting it from the USB port use:

$ sudo alsa force-reload
$ alsactl restore 0

Bash auto-completion trick

Tuesday, July 31, 2012

zhs has a nice feature. If a program supports --help then zsh can do auto-completion of its arguments. The trick is that zsh silently runs the program with --help argument, parses the output and use it for auto-completion. I wish bash could do that. Well, not exactly but it can. Bash has auto-completions too using templates. But if you want to add auto-completion to your program you would need to write a new template and either put it to /etc/bash_completion.d/ or source in .bashrc or .profile.

But you don’t have to do any of it if you can re-use bash templates as is. For example the template for configure scripts does almost the same what zsh does for all programs. It simply parses the output from ./configure --help. Unfortunately it works only for arguments that prefixed with double dash. Better than nothing anyways.

<- Newer Posts Older Posts ->