Archive for the 'Terminal' Category

Making xpdf usable on HiDPI with .Xresources

Friday, May 1st, 2020

I now have a 4K-screen, and immediately some programs became unusable. Everything KDE just worked. URxvt and XTerm just needed an OpenType font specified instead of the old “fixed” one.

Like this:

xterm*faceName: Monospace
xterm*faceSize: 10

and this

URxvt.font:     xft:bitstream vera sans mono:size=14:antialias=true
URxvt.boldFont: xft:bitstream vera sans mono:bold:size=14:antialias=true

But some were more elusive, most notably, because they’re badly documented on the net, and information is difficult to find because the motif-toolkit is very ancient. One of them is xpdf. Whose UI sported tiny fonts.

But I managed to produce a somewhat decent .Xresources (either put them into .Xdefaults; or put them into .Xresources and merge in via xrdb -merge .Xresouces).

The font really needs to be specified in the old fontList way, and I couldn’t find out how to make it use a modern OpenType font.

The rest is mostly to turn off superfluous borders and heavy shadows.

Xpdf*fontList: -*-lucida-medium-r-*-*-20-*-*-*-*-*-*-*
Xpdf*XmText.background: #ffffff
Xpdf*XmTextField.background: #ffffff
Xpdf*XmList.background: #ffffff
Xpdf*GraphEdit.background: #ffffff
Xpdf*shadowThickness: 1
Xpdf*borderThickness: 0
Xpdf*?*arg*shadowThickness: 1
Xpdf*?*arg*borderThickness: 0
Xpdf*?*buttons*shadowThickness: 1
Xpdf*?*buttons*borderThickness: 0
Xpdf*XmToggleButton*shadowThickness: 0
Xpdf*XmToggleButton*borderThickness: 0
Xpdf*menubar.shadowThickness: 0
Xpdf*menubar.borderThickness: 0
Xpdf*XmMenuShell*XmTearOffButton*ShadowThickness: 2
Xpdf*main_window.?.borderThickness: 0
Xpdf*main_window.shadowThickness: 0
Xpdf*cutCopyPasteBindings: KDE
Xpdf*selectAllBindings: KDE
Xpdf*buttonColorKey: c
Xpdf*FlatButtons: on

And you especially want it to start in a decent size. You can set this in .pdfrc, but this replaces it:

Xpdf*initialZoom: 200

hostapd with psk-file

Tuesday, January 26th, 2010

I tried to make hostapd use a separate psk-file, with a different PSK per MAC-address. On Debian the file is called /etc/hostapd/wpa_psk and according to /etc/hostapd/hostapd.conf:

# Optionally, WPA PSKs can be read from a separate text file (containing list
# of (PSK,MAC address) pairs. This allows more than one PSK to be configured.

This is fucking WRONG. The file-format is not documented anywhere else, and the above is utter bogus. The file has to look like this:
00:00:00:00:00:00 somepskstring

The 00:00:00:00:00:00 of course would have to be replaced by a real MAC-address. The MAC-address all zeroed out might signify a wildcard, but then, this isn’t documented either.

By the way, if you do not want it bloody bridged, you need to set up the interface just like normal in /etc/network/interfaces, and take care that it’s served by dhcp and has appropriate firewall-rules.

Unix Console & X11 Tips & Configs

Sunday, September 13th, 2009

Initially, I started with the premise to change my Console/Terminals to UTF-8. However, as it turned out, they behave rather weird, some things don’t work right, characters are sometimes not visible, they tend to make a mess in displaying special chars (as used in mc), some control-commands don’t work anymore and so on. My light-weight-terminal aterm does not support UTF8 (but JIS and whatnot, what the heck?) So I postponed this to some later date, when there’s at least a fixed mlterm available.

However, there are some interesting things to mention, in regard to the console:

mc clogs up the history
If Midnight Commander writes funny things like cd "`printf "%b" '\0057'`" into the shell-history, then HISTIGNORE is not set, or does not contain a space.

export HISTIGNORE="&:[ ]*:exit"

Umlauts appear as ? when doing an ls
This is due to the really relevant variable regarding the charset: LC_CTYPE. Set it to something other than “C”:

export LC_CTYPE=en_GB.ISO-8859-1

English system in Switzerland
If you want the system in english (and not necessarily the data), but are otherwise not english speaking, and sure as hell do not want screwed-up data formats or medieval measurement units, you want to set up your locales like this:

export CHARSET=ISO-8859-1
export LANG=en_GB.ISO-8859-1
export LC_CTYPE=en_GB.ISO-8859-1
export LC_MESSAGE=en_GB.ISO-8859-1
export LC_MESSAGES=en_GB.ISO-8859-1
export LC_NUMERIC=de_CH.ISO-8859-1
export LC_TIME=de_CH.ISO-8859-1
export LC_COLLATE=de_CH.ISO-8859-1
export LC_MONETARY=de_CH.ISO-8859-1
export LC_NAME=de_CH.ISO-8859-1
export LC_ADDRESS=de_CH.ISO-8859-1
export LC_TELEPHONE=de_CH.ISO-8859-1
export LC_MEASUREMENT=de_CH.ISO-8859-1
export LC_IDENTIFICATION=de_CH.ISO-8859-1
export LANGUAGE=en_GB

Setting LC_PAPER can lead to problems with things you do not send to a printer (pdf-generation for instance), and setting LC_ALL makes it impossible to use different locales for different uses.

Of course, you can replace ISO-8859-15 with UTF-8 if you like.

make mlterm look decent
These are the contents of .mlterm/main:

only_use_unicode_font=yes
scrollbar_mode = right
scrollbar_view_name = next
fontsize = 16
ENCODING = UTF-8
fg_color = white
bg_color = black
use_transbg = true
brightness = 60
fade_ratio = 75
geometry = 80x25
use_anti_alias = true
logsize = 4096
word_separators = " ,;=:"

Well, yes, it now looks quite NeXTy ;).

A better cursor
Not really console-related, but anyway: Get an Icon-theme like Shere Khan X (why, it looks like the one from NeXT of course), and put the unpacked directory into ~/.icons/ Now change your .Xresources to read:

Xcursor.theme: Shere_Khan_X

Screenlock with DPMS
For some machines, xlock is seemingly unable to do DPMS. Don’t fret:

xset dpms force off && xlock -mode blank -resetsaver

See Also
An earlier post in Blog: Useful Shell Oneliners

Useful Shell Oneliners

Monday, November 12th, 2007

From time to time you come upon some useful oneliner in the shell. Either because you see it somewhere, see someone doing it, or because you need it and produce one yourself. And most of the time, it’s not enough to put into a shell-script, so you find yourself hunting for it in your .bash_history. Well, here are some:

Do something to a lot of files
for i in *; do command $i; done

You’ll need this a lot. Does not work with files containing spaces

Convert a load of images
for i in *.tif; do convert -quality 75 $i `basename $i .tif`.jpeg;

Make pdf out of a several images
convert -limit memory 32 -limit map 32 *.png target.pdf

You really want to set the limits, unless you have more RAM than the whole images converted to pbm.

With Graphicsmagick, you need to set a compression for jpg, otherwise the resulting PDF will be huge.

gm convert -compress JPEG *.jpg target.pdf

The resources you want to give those programs can be set using environment-variables:

export MAGICK_MEMORY_LIMIT="640mb"
export MAGICK_MAP_LIMIT="320mb"
export MAGICK_AREA_LIMIT="640mb"

Make pdf out of a lot of images
But the whole idea of using ImageMagick or GraphicsMagick to create pdf-files is very much flawed, since both first convert the jpeg-files into an raw, uncompressed intermediate format which tends to eat up all available memory, and then crash. And which is completely nonsensical too, since jpeg-files can be embedded into pdf as they are. Luckily, pdfjoin will help us, tough it accepts only files with the extension ‘.pdf’ as input as of yet:

mmv '*.jpg' '#1.pdf'; pdfjoin --outfile target.pdf *.pdf

Change resolution (DPI) of an image
convert -density 600 -units PixelsPerInch source.png target.png

split/crop pictures
convert -crop 1230x880 source.png target

Note that this does not really crop the image, but splits it into as many parts as necessary, using “target” as prefix, adding a number as suffix.

fix offset
convert +repage source.png target

Lately, “crop” seems to behave differently, it leaves all but the first part with an offset. This makes the picture disappear in gimp, and stretched if you make a pdf out of it. That’s why you may need to repage.

rotate
convert -rotate 90 source.png target

rotates 90 degrees clockwise.

Attach pictures to each other, one below the other
montage +frame +shadow +label -tile 1x2 -geometry "widthxheight+0+0" source1.png source2.png target.png

Important is that width and height are the dimensions of each of the sources. For putting them next to each other, just use 2×1 as tile.

Rename files according a textfile-list
for i in `cat list` ; do mv `echo $i | awk -F"-" '{print $1".ext"}'` $i.ext ; done

Delete empty directories
find . -type d -empty -depth -exec rmdir {} \;

Remove first page of a PDF
pdftk A=source.pdf cat A2-end output target.pdf

Yes, pdftks syntax is a bit alien.

Merge PDFs
pdftk sources*.pdf cat output target.pdf

Unpack lots of packed files into different directories
for i in *.rar; do mkdir `basename $i .rar`; mv $i `basename $i .rar`; cd `basename $i .rar`; rar x $i; cd ..; done

If you have a load of packed files, in this case rar, and you want to unpack each into a different subdirectory, according to the name of the rar-file.

Get rid of magnatune-advertisements in mp3s

for i in *.mp3; do mp3splt -s -p min=2 -d `basename $i .mp3` $i ; done

Merge AVI-movies
mencoder -forceidx -oac copy -ovc copy -o outputfile.avi parts*.avi

That’s the basic way. If you want to process a whole directory with avi-files whose filenames have a distinct part (like “cd≶num>” or “-Part≶num>” as in my example) you can do something this:

for i in *-Part1.avi; do mencoder -forceidx -ovc copy -oac copy -o `basename $i -Part1.avi`.avi `basename $i -Part1.avi`-Part*.avi; done

To be continued. You might also want to check out my Program-section for small useful scripts.

Debian GNU/Linux on the PC Engines WRAP

Friday, November 3rd, 2006

I finally decided to replace my Firewall, an UltraSparc 5 running Linux with something which is smaller, consumes less energy and produces less noise. I cam upon the PC Engines WRAP which is with 15x15x2cm considerably smaller than the Sparc. It has a serial port, three ethernet-ports and runs its OS from a Compact Flash II Card.

There’s a tutorial on Installing Debian on a USB flash with everything encrypted. After a first try, I decided to leave out the “encrypted” part, its complicated and I have no decent way of entering any passwords at boot.

For the WRAP, there some things which differ from some USB-media wich you have to take care of:

There is no real-time clock. Therefore you need to turn off the filesystem-check by time gone unchecked:

tune2fs -i 0 /dev/whatever

Clock-source should be pit or jiffies, with scx200_hrt I got me a running clock of a one-minute deviation per second.

echo pit jiffies > /sys/devices/system \
/clocksource/clocksource0/current_clocksource

You want to minimize writes on the Flash, thus you best put /var/lock, /var/tmp, /var/run and /tmp onto a tmpfs, as described in the above tutorial.

The Kernel sometimes is a bit too verbose, this will fix that:

echo 5 > /proc/sys/kernel/printk

It’s also slow, and the new apt feature to download diffs of the package-indices does heavily use disk and cpu to save bandwidth. Not a good idea in this case. Turn it off in /etc/apt/apt.conf:

Acquire
{
Pdiffs "false";
};

Finally, you might want a kernel which does only that which is needed, loads no modules (which puts the brake on some rootkits which want to install themselves as kernel-modules). You can try and err, but as it happens, somebody else (me) already did, so heres the .config for a pc engines WRAP, kernel 2.6.18 with the grsecurity kernel patch.