I have previously wrote about ways of identifying directories that take up most space using command line. There are a number of ways you can pipe commands to find out directories large directories. Today, however, I’d like to discuss a useful little program with an ncurses frontend, ncdu. Not only does it display directories in your chosen order (ascending/descending, by size/name), but also lets you interactively browse (and be careful: delete) them. To make sure you don’t delete something by accident, you can run the program in the read-only mode calling it with the -r flag. Apart from ordering the files/directories by size or name, there are also a number of interesting display options like showing percentage or graph, showing/hiding hidden or excluded files and directories (you can exclude certain directories or files if you want.) Although it is not part of the stock Slackware, it can be easily installed from slackbuilds.org (it does not have any additional dependencies.)
A new release of i3 window manager
Monday, 7 May 2012
Last week the i3 development team released version 4.2 of their superb tiling window manager. Among a number of new features, there was one that particularly caught my attention, a scratchpad command. The command creates a scratchpad container where any of your windows can be placed and displayed on demand. The scratchpad container gets displayed in the centre of a window in a floating mode. It’s a convenient place for windows that you do not want displayed all the time. Personally, I can think of the following uses of the scratchpad container: ncmpcpp, mc, bash prompt, email, REPL, or simply, as the name suggests, a scratchpad with emacs inside. Yes, you can have more than one scratchpad container.
How to use the scratchpad
First you need to edit your i3 config file (~/.i3/config)
# Make the currently focused window a scratchpad
bindsym $mod+o move scratchpad
# Show the first scratchpad window
bindsym $mod+i scratchpad show
First you move a currently focused window to a scratchpad with Alt+o, then you can toggle show/hide with Alt+i to see how it works. You can move another window to a It you work on a dual-monitor setup, you can move the scratchpad between the screens with the standard move command as well as bring a window back to a normal tiling flow by disabling a tiling mode on it.
Slackware – check installed packages with Python
Monday, 7 May 2012
Querying installed package is something I do every now and then. It’s usually needed to find out if all the necessary dependencies of a package have been met. On Slackware it is usually accomplished with a simple:
ls /var/log/packages | grep -i package
For example:
$ ls /var/log/packages | grep -i gconf
GConf-2.32.1-x86_64-1
perl-extutils-pkgconfig-1.12-x86_64-1_SBo
As a way of practising programming, I decided to simulate the above command in Python 3. Here’s what I’ve coded:
#!/usr/bin/env python3
import os
import fnmatch
import sys
if (len(sys.argv) != 2):
'''Check if the user provided the required argument'''
print('The {0} command takes exactly 1 argument!'.format(sys.argv[0]))
else:
packages_directory = '/var/log/packages/'
package = sys.argv[1].lower()
os.chdir(packages_directory)
for files in os.listdir(packages_directory):
if fnmatch.fnmatch(files.lower(), '*' + package + '*'):
print(files)
It might be slightly slower than using Bash but it does the job. As I’m not a seasoned Python programmer, there’ll probably be ways of optimising the code, which I obviously welcome. Feel free to provide feedback.
Slacker, grab your towel and don’t panic!
Wednesday, 18 April 2012
Over the last few days there has been some unnecessary drama around Slackware. Some Slackware users (including myself) might have slightly overreacted to Eric’s comment. This, together with some poor journalling practices of a certain individual have opened a debate, not necessarily about Slackware’s future – because it doesn’t seem endangered in any way, but about Slackware website. Despite its negative aspects, the situation has shown how dedicated to Slackware its users are with their donations. I’m sure Pat will put these extra few dollars to a good use. I have learned so much using Slackware that it’d be inappropriate not to donate money.
Thank you Pat and the rest of the Slackware crew.
Python 3 shell in Emacs
Tuesday, 3 April 2012
If you’d like to run a Python 3 shell within Emacs you could issue the following command:
C-u M-x run-python
It’ll then prompt you to confirm which Python version you’d want to run. You can just type 3 and click Enter again. If you use it a lot, however, it’s not going to be the most convenient of the solutions. You could automate the whole process by adding the following 2 lines to your ~/.emacs file:
(defun run-python3 () (interactive) (run-python "python3"))
(global-set-key [f5] 'run-python3)
The second line assigns a keybinding to the command. In the example above it is the F5 key.
NTS#2
Saturday, 10 December 2011
“Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.”
Greenspun’s tenth rule of programming
Brother HL 2270DW on Slackware
Thursday, 3 November 2011
I have recently purchased Brother HL-2270DW monochrome laser printer. It works fine both through USB and wirelessly. It can also supports duplex printing (printing on both sides of a page).
Although the Linux drivers are available for download, they only ship as .deb or .rpm packages. That’s not a big problem as I used the deb2tgz tool to convert it to a more Slackware-friendly wrapper. Despite the fact that Slackware ships with the rpm2t?z tool, I had more luck with deb2tgz. Please note that one of the requirements for the driver to work on Slackware64 is multilib support.
1. First you need to start CUPS on your system:
# chmod +x /etc/rc.d/rc.cups
# /etc/rc.d/rc.cups start
Connect the printer via a USB cable.
2. Download the drivers from the following place (both .deb packages).
3. Convert them to .tgz
deb2tgz hl2270dwlpr-2.1.0-1.i386.deb
deb2tgz cupswrapperHL2270DW-2.0.4-2.i386.deb
4. Install the packages:
# installpkg hl2270dwlpr-2.1.0-1.i386.tgz
# installpkg cupswrapperHL2270DW-2.0.4-2.i386.tgz
5. Check if the printer has been recognised by accessing http://localhost:631/printers and you can print the test page to see if it works.
6. If you want to access it wirelessly, you need to visit http://localhost:631 and then follow the steps below:
Adding Printers and Classes
Add Printer (You’ll be asked for root’s password)
Other Network Printers: LPD/LPR Host or Printer
Connection: lpd://your_printers_IP_address/binary_p1 (You could find out the printer’s IP address with nmap)
Add the name and description you your choice
Choose Make: Brother
Choose Model: HL2270DW for Cups
You should be ready to go. There’s only one slight problem. For some reason, the drivers don’t work properly with some applications. Certain applications spit out countless pages of some code. I’ve tested it on two computers and these are my findings:
Applications/tools that print flawlessly:
Emacs / Firefox / Thunderbird / Okular / Epdfview / lpr / SoftMaker Office
Applications that print some “gibberish”:
Evince / Libre Office
Libre Office is not an issue for me as I have been using SoftMaker Office anyway, but PDF document printing is somewhat problematic as I’m not a big fan of KDE and its applications (Okular) and I can’t seem to find a duplex option in Epdfview.
Duplex printing in Emacs
Wednesday, 2 November 2011
In order to turn on a duplex printing mode you need to issue the following:
M-x pr-toggle-duplex
If you want to switch the mode off, you need to issue the same command.
Remember the last regular expression in Sed
Friday, 28 October 2011
One of Sed’s nifty features that often tends to be overlooked is its ability to remember the last regular expression in a script. The advantage of it is that the code gets shorter and more concise, even at the cost of being more cryptic.
<tag>345464245</tag>
<tag>24524524</tag>
<tag>24524524</tag>
<div>2424662</div>
<tag>24524524</tag>
<div>2462424624</div>
<tag>46246246</tag>
<div>4624642464</div>
<tag>24623462346423</tag>
<div>462462642646</div>
<tag>462462466264</tag>
<div>24646464</div>
<tag>2466246246</tag>
<div>24665457524</div>
<tag>53456575435</tag>
<div>35655</div>
<tag>565</tag>
<tag>457537753</tag>
<tag>48334</tag>
Imagine that we want to extract only the numbers on the “div” lines without the “div” tags.
We could do it using Grep and then piping the output to Sed:
grep div file | sed 's/<\/*div>//g'
Actually, we wouldn’t even need Grep to do it:
sed -n '/div/ s/<\/*div>//gp' file
It turns out, however, that here we can take advantage of Sed’s ability to remember the last regular expression:
sed -n '/<\/*div>/ s///gp' file
So what’s happening here? The -n flag suppresses automatic printing of the lines that don’t contain “div” tags. The “p” option then prints only the files that have been modified.
/<\/*div>/
The above address matches lines containing either <div> or </div>. Remember that the asterisk (*) means zero or more occurrences of the previous character. As we used / as the delimiter, we also had to use \ to escape /. Then we have the ‘s’ (=substitute) command with 2 empty spaces separated by 3 forward slashes (///). The first blank space (regexp) remembers the last regular expression from the address space. The second empty space just tells Sed to replace whatever was matched with nothing (ie. get rid of it). As the default Sed behaviour would be to match only the first occurrence of the matched pattern, we need to pass the ‘g’ (=global) command.
Midnight Commander – colour scheme
Sunday, 23 October 2011
Having switched from Thunar to Midnight Commander, I decided that it’s high time to do something with this terrible gray/cyan combo that MC ships with.
Here’s a screenshot of MC run in rxvt-unicode in i3wm (right-click to view a better resolution version of the picture):

I have attached the [Color] section of ~/.mc/ini and ~/.Xresources (I have customised rxvt-unicode colours.)
Files:
mc.ini
Xresources
Enjoy!