"Premature optimization is the root of all evil", Donald Knuth.

Thursday, April 28, 2016

Xterm configuration

Overview


Xterm is the native Terminal emulator of X window system. This article will provide some useful options to configure Xterm to be usable and comfortable.
NOTE: This article was written for Arch Linux but can be applied to other Distros with some different approachs.

Xterm configuration


Config file location


Xterm is configured though X resources file ~/.Xresources , this file may not exist by default, you can manually create it with any text editor.





Loading config file


Most Display manager will load ~/.Xresources file on login, if you use startx , you will need to add the line:
xrdb ~/.Xresources
to your xinitrc file.
If you want your changes to take effect, you need to restart X Server or reload X Resources file manually.

Reverse color


Add this line to your X resources file to enable black background:
XTerm*reverseVideo: on

Enable UTF-8


Xterm with UTF-8 can be access via uxterm command, but you can configure xterm to accept UTF-8 characters. 
First make sure that your locale settings are correct for UTF-8. Sample UTF-8 locale configuration: 
Uncomment the line in /etc/locale.gen
...
#en_SG ISO-8859-1
en_US.UTF-8 UTF-8
#en_US ISO-8859-1
...
Generate locales as root:
$ locale-gen
Edit /etc/locale.conf:
LANG=en_US.UTF-8
After configured locales, add this line to your X resources file to enable UTF-8:
XTerm*locale: true

Fix 'alt' key


If you use the 'alt' key for your shortcut, add this line to X resources file:
XTerm*metaSendsEscape: true

Disable bold fonts


Bold characters are sometimes hard to read on small font. Disable it:
XTerm*allowBoldFonts: false

Change title of terminal


This is a small bash script to change title of terminal:
/usr/bin/title
#!/usr/bin/bash
xwit -id $WINDOWID -name "$1"
Usage example:
$ title "my new title"
xwit can be installed from aur

Automatic transparency


To enable transparency, you need to install the package transset-df and a composite manager, I recommend using Compton because it is stable and runs smoother than others.
To install Compton , first make sure that Composite extension is enabled for the X Server. Run:
$ xdpyinfo | grep Composite
If there is no output, add the Composite option to the Extensions section of xorg.conf
/etc/X11/xorg.conf
Section "Extensions"
        Option  "Composite" "true"
EndSection
Install compton :
$ pacman -S compton
To use compton , you need to start it manually :
$ compton 
Or you can add it to xinitrc file:
/etc/X11/xinit/xinitrc
...
exec compton &
...
When your have installed compton, add this line to ~/.bashrc file to enable automatic transparency:
[ -n "$XTERM_VERSION" ] && transset-df --id "$WINDOWID" > /dev/null

Bash interaction prompt decoration


This is a sample bash interaction prompt configuration: 
/etc/bash.bashrc
...
if [ `whoami` = 'root' ]; then
PS1='\[\e[1;33m\][\u@\h \W]\$\[\e[0m\] '
else
PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '
fi
PS2='> '
PS3='> '
PS4='+ '
...
The terminal will look like this
And with root shell:


Resources:

No comments:

Post a Comment