Some time ago when I was mostly writing about Openbox setup I also showed how to setup xterm(1) so it will start with new random theme with each start. Since then I reworked that feature a little and also added random theme and background selection for urxvt(1) terminal. This post will guide you through the needed steps to make that setup working.
You may want to check other articles in the FreeBSD Desktop series on the FreeBSD Desktop – Global Page where you will find links to all episodes of the series along with table of contents for each episode’s contents.
I already once wrote about random xterm(1) themes in the FreeBSD Desktop – Part 12 – Configuration – Openbox part – but I really wanted to expand that topic and also include other terminals.
After trying many terminal emulators – some more bulky like Konsole/GNOME Terminal/XFCE Terminal/MATE Terminal – some more lightweight like st(1)/rox-term(1)/eterm(1)/… – I always went back to the most old-school and basic one – good old xterm(1) terminal. Mostly because of its good compatibility with all UNIX systems – especially the older ones like IBM AIX or HP-UX. I do not remember last time when I had to manage these archaic systems but the respect for xterm(1) remains.
The other one that always got my attention was urxvt(1) terminal. Unfortunately it has some issues with fonts rendering – making larger spaces between the lines and making fonts bigger for example – but as I also like bitmap fonts like CLEAN or FIXED – so I use bitmap fonts for urxvt(1).
Recently also sakura(1) got my attention – but it’s theming possibilities are even more limited then xterm(1) with themes/colors hardcoded directly into the source code. That is why I will omit it in this article – but I mention it since its also nice terminal.
This is the Table of Contents for this article.
- Proper Font Selection
- Selecting Text for Copy/Paste
- Selection Buffers and Keyboard Shortcuts
- Increase/Decrease Font Size on the Fly
- Copy/Paste with [CTRL]+[SHIFT]+[C/V]
- Interactive Menus
- Random xterm(1) Theme
- Tabbed Interface
- Daemon and Client Mode
- Random urxvt(1) Theme and Background
- Different sakura(1) Themes
- RAM Usage Comparison
- CPU Time Usage Comparison
First lest start with some reasonable configuration in the ~/.Xdefaults file. Alternatively some people use ~/.Xresources file. You can use any of them. Just pick one and stick to it.
xterm*VT100*translations: #override \n\
<btn1up>: select-end(PRIMARY, CLIPBOARD, CUT_BUFFER0) \n\
Ctrl <key> minus: smaller-vt-font() \n\
Ctrl <key> plus: larger-vt-font() \n\
Ctrl Shift <key> C: copy-selection(CLIPBOARD) \n\
Ctrl Shift <key> V: insert-selection(CLIPBOARD)
I will not discuss all possible settings as they are well described in the xterm(1) man page but I will comment some more useful and interesting ones.
Proper Font Selection
This advice is not limited to xterm(1) but its worth to mention it. Many times after adding fonts to my system – and renaming them to my ‘standard’ which looks like that one below I was asking myself how to properly specify the variant I need.
% ls -1 ~/.fonts/ubuntu-mono*
The answer to that question comes with fc-match(1) from fontconfig package. Check my ‘queries’ below.
% fc-match consolas:bold
consolas-bold.ttf: "Consolas" "Bold"
% fc-match consolas
consolas.ttf: "Consolas" "Regular"
% fc-match consolas:bold:italic
consolas-bold-italic.ttf: "Consolas" "Bold Italic"
Selecting Text for Copy/Paste
The xterm*charClass defines which sets of characters should be treated the same when doing cut and paste. Especially with double-clicking the text. The setting above I use is based on 15 years of experience and seems to work best. You are of course encouraged to investigate the CHARACTER CLASSES section of the xterm(1) man page to read more on this topic.
The xterm*on4Clicks and xterm*on5Clicks are not used by default while xterm*on2Clicks are predefined as word and xterm*on3Clicks as line values. This is why I added them so you can select entire group with xterm*on4Clicks and entire page with xterm*on5Clicks option. Alternatively you can also use some fancy regex for some of these ‘CLICKS’ but I never thought about a REGEX that would be useful here – maybe you will come with something sensible.
Here are these ‘CLICKS’ in action.
First the xterm*on2Clicks with word selection. This is when the xterm*charClass is taken into account – what is word and that is not 🙂
Then xterm*on3Clicks with line selection.
Now xterm*on4Clicks with group selection.
Finally the xterm*on5Clicks entire page selection.
Selection Buffers and Keyboard Shortcuts
The last interesting option is xterm.VT100.translations which is used for keyboard shortcuts.
The first one select-end(PRIMARY, CLIPBOARD, CUT_BUFFER0) is better described in the https://davidsimmons.com/soft/xtermhacks/ page from 2005. I will try to short the meritum here. The X11 applications have two different selection buffers:
CLIPBOARD – selection buffer used for cut/paste functions – you select/highlight text and then select Copy from context menu or use [CTRL]+[C] shortcut. Then you use Paste or [CTRL]+[C] shortcut.
PRIMARY – this one receives data when user selects/highlights text with mouse. None other operations such as Copy or Paste are needed. You end selecting the text and its already in PRIMARY buffer. You then paste it with MIDDLE mouse button.
Using the option above selecting/highlighting the text in xterm(1) copies the text into both selection buffers simultaneously. You can now either Paste it info Firefox or hit MIDDLE mouse button to paste it in other xterm(1) terminal. Best of both worlds.
If that setting does not suit you then use the xterm*selectToClipboard instead. When set to true it copies selected text to CLIPBOARD buffer and when set to false it copies selection to the PRIMARY one.
Increase/Decrease Font Size on the Fly
I always missed the shortcuts to decrease or increase font size on the fly in xterm(1) and for many years I believed that its just not possible and then I found some blog post (do not remember which one now of course) in which I found these settings and started to use them.
They are smaller-vt-font() and larger-vt-font() for decrease and increase respectively with [CTRL]+[-] and [CTRL]+[+] shortcuts – keep in mind that [SHIFT] is not used here.
Copy/Paste with [CTRL]+[SHIFT]+[C/V]
If by some reason you prefer to copy and paste by using [CTRL]+[SHIFT]+[C] and [CTRL]+[SHIFT]+[V] shortcuts then copy-selection(CLIPBOARD) and insert-selection(CLIPBOARD) will do the needed job here. As you probably guessed you can use PRIMARY instead of CLIPBOARD here if that is what you desire.
The xterm(1) comes with three different interactive menus. I will now show all three of them here with screenshots.
Menu displayed with clicking [CTRL]+[LEFT-MOUSE-BUTTON] in the terminal area.
Menu displayed with clicking [CTRL]+[MIDDLE-MOUSE-BUTTON] in the terminal area.
Menu displayed with clicking [CTRL]+[RIGHT-MOUSE-BUTTON] in the terminal area.
Random xterm(1) Theme
To have random xterm(1) theme on every startup you need four things:
I gathered all these themes all over the Internet, only the VERMADEN and VERMADEN-OLD themes are created by me.
Little preview of some of the included xterm(1) themes.
From now on to have random xterm(1) theme at each start always start it with ~/scripts/xterm.sh script. The script itself is not very complicated. It just draws random theme from the ~/.config/Xdefaults/themes dir – then loads the ~/.Xdefaults config – then merges the colors from chosen random theme – and finally starts new xterm(1) instance.
I use urxvt(1) less often but still sometimes I want to use bitmap fonts instead.
For a start here is the urxvt(1) configuration in the ~/.Xdefaults file.
! urxvt.font: xft:monaco:pixelsize=9,style=regular,minspace=True
To get tabs in urxvt(1) add the following option to the ~/.Xdefaults configuration file.
With this option you will open new tab with [SHIFT]+[DOWN] shortcut.
To switch between the tabs left and right use [CTRL]+[SHIFT]+[LEFT] and [CTRL]+[SHIFT]+[RIGHT] shortcut respectively.
You can also use [CTRL]+[LEFT] and [CTRL]+[RIGHT] to move current tab left and right.
The timeless [CTRL]+[D] – which of course is not a strictly urxvt(1) shortcut but a general shortcut for closing all terminals.
Daemon and Client Mode
The urxvt(1) can be run in special daemon mode where you start one urxvtd(1) server and many urxvtc(1) clients.
rxvt-unicode daemon listening on /home/vermaden/.urxvt/urxvtd-w520.local.
Now you will start each new urxvt(1) terminal with urxvtc(1) command.
The drawback of that approach is that when urxvtd(1) dies or crashes then also all your urxvtc(1) client terminals disappear 🙂
Random urxvt(1) Theme and Background
To have random urxvt(1) theme and background on every startup you need four things:
Little preview of some of the included urxvt(1) themes and backgrounds.
From now on to have random urxvt(1) theme at each start always start it with ~/scripts/urxvt.sh script. The script for urxvt(1) is little more advanced. First it draws random theme from the ~/.config/Xdefaults/themes dir – then checks if its DARK or LIGHT theme – then draws either random LIGHT or DARK background from the ~/.config/Xdefaults/urxvt dir – finally loads the ~/.Xdefaults config and then merges the colors from chosen LIGHT or DARK theme. Of course then it finally starts new urxvt(1) instance.
The more modern and GTK based sakura(1) also supports tabs. To open new tab use [CTRL]+[SHIFT]+[T] shortcut. To switch between the tabs use [CTRL]+[ALT]+[LEFT] and [CTRL]+[ALT]+[RIGHT] shortcuts. You can also move tab between left and right with [CTRL]+[SHIFT]+[LEFT] and [CTRL]+[SHIFT]+[RIGHT].
One things that sakura(1) impresses me is that you can scale down its window and then scale that window up and the contents that did not fit in the window after downscalling are back again in the terminal. Doing the same operation in xterm(1) or urxvt(1) terminals will result in these characters being lost. The output is also dynamically ‘fit’ into the new larger window while maintaining the new lines etc. Besides that nice feature it is small and fast and uses relatively small amount of RAM.
Different sakura(1) Themes
If you would also like to start sakura(1) with different theme everytime the options are quite limited here. The palettes and color sets are hardcoded into the sakura(1) source code.
I will not show you how to modify them using the FreeBSD Ports system.
The sakura(1) port is located at /usr/ports/x11/sakura directory. For the record – I use WRKDIRPREFIX option in the /etc/make.conf file. This means that when I type make extract in the /usr/ports/x11/sakura dir the work directory will not be created at /usr/ports/x11/sakura/work directory but at /usr/ports/obj/usr/ports/x11/sakura/work instead. That way I can clean my Ports tree fast by removing the /usr/ports/obj directory.
We will now extract and patch the sakura(1) port on FreeBSD.
% grep WRKDIRPREFIX /etc/make.conf
# cd /usr/ports/x11/sakura
# make patch
# cd /usr/ports/obj/$( pwd )/work/*/src || cd work/*/src
# grep -m 1 DEFAULT_PALETTE sakura.c
#define DEFAULT_PALETTE "tango"
# grep -o -E '[a-z]+_palette\[PALETTE_SIZE\]' sakura.c
As you can see the default sakura(1) palette is Tango. Fortunately you can use palette=solarized_dark option in the ~/.config/sakura/sakura.conf config file to change it into Solarized Dark for example.
Besides hardcoded palettes sakura(1) also has several Color Sets.
If you would like to make random theme (from the hardcoded ones) for each start you would have to use this syntax with prepared dedicated config files for each palette.
% sakura --config-file ~/.config/sakura/sakura.solarized_dark.conf --colorset 1
% sakura --config-file ~/.config/sakura/sakura.tango.conf --colorset 3
I do not use sakura(1) that much so I was too lazy to write random startup theme script also for it 🙂
Changing sakura(1) palette or color set manually is shown below.
RAM Usage Comparison
Just started xterm(1) terminal takes about 16 MB or RAM as you have seen on the urxvt(1) screenshots. The urxvt(1) started without tabs uses more then 2 TIMES of xterm(1) terminal RAM usage. The urxvt(1) started in tabbed mode uses more then 3 TIMES of xterm(1) terminal RAM usage. The sakura(1) also uses more then 3 TIMES of xterm(1) terminal RAM usage.
Table below shows RAM usage comparison. I have added more feature packed mate-terminal(1) to the list and also added the st(1) minimalistic terminal from Suckless project for compassion.
52 urxvt (tabbed)
CPU Time Usage Comparison
I also made simple benchmark of the CPU used. The ‘benchmark’ was to check how much time each terminal would take to print output of dmesg | lolcat -b -r command. Here xterm(1) does not shine that much.
The above ‘benchmark’ was was quite ‘hard’ because of all the colors generated by lolcat(1) command. Lets try something more practical now. We will measure CPU time used to display out of the find find /usr/local/share/doc command.
Seems that lolcat(1) was not that ‘hard’. The st(1) minimalistic terminal really seems to suck less here 🙂