Table of Contents

1 [Fu]n Ha[cks]

  • UNIX related thingies.

1.1 Rebind keys with xmodmap

  • ⚠ This program may have to be externally installed.

Rebinds left CapsLock to Control, Return to Control and Right Shift to

remove lock      = Caps_Lock
add Control      = Caps_Lock
keysym Caps_Lock = Control_L

remove Control   = Control_R
remove Shift     = Shift_R
keycode 0x3e     = Return
keycode 0x24     = Control_R
add Control      = Control_R
  • Assigns Caps-Lock to the control group and makes it a synonym with Left-Control.
  • Assigns Return to the control group and makes it a synonym with Right-Control.
  • Assigns Right-Shift as a synonym with Return.

Rebinds CapsLock to Left Control

remove lock      = Caps_Lock
add Control      = Caps_Lock
keysym Caps_Lock = Control_L

This code can be put in the xmodmap config, or just
evaluated with:

$ xmodmap ./rebind_keys

Where ./rebind_keys is a file containing one of the above [configs|other config]

1.2 XdoTool Magic within X

  • ⚠ This program may have to be externally installed.

XdoTool [X do Tool], does as per it’s name certain desirable The
program Xdo also exists and provides almost identical features,
which i actually prefer more over XdoTool.

1.2.1 Change workspace width xdotool

XdoTool has a loot of features for playing around with windows.

Changing workspace (if there is support) can be done with xdotool set_desktop N where N is a valid desktop index, under the return
value of xdotool get_num_desktops, indexing starts at 0. The current
desktop index can be gotten with xdatool get_desktop.

A program to change to the next workspace can easily be written as

WORKSPACE_AMT=$(xdotool get_num_desktops)
WORKSPACE_CUR=$(xdotool get_desktop)
xdotool set_desktop $(($WORKSPACE_CUR + 1)) || xdotool set_desktop 0

1.2.2 Simulation of input with xdotool

To type some text with xdotool.

xdotool type "Happy Hacking"

To move the mouse to some arbitrary position you can use;

xdotool mousemove $x $y

1.3 Bash (illustrative) examples


GNU Bourne-Again Shell

Is the bash implementation i will be
using, however there exists versions which GNU has not created,
as well as other shells like sh, zsh, fish, chsh, eshell..

Most of these have implemented divergent scripting features and may
not be fully POSIX compliment (Backwards compatibility could take a
hit). Bash however is pretty solid

1.3.1 Dictionary’s with a for-loop

Use dictionary DICT with 3 elements with keys {"A", "B", "C"},
print the key and the value

declare -A DICT
DICT=(["A"]="Alpha" ["B"]="Beta" ["G"]="Gamma")

    for char in "${!DICT[@]}"; do 

        printf " =➡ Key:\"$char\" Value:\"${DICT[$char]}\"=\n"

➡ Key:"G" Value:"Gamma"
➡ Key:"B" Value:"Beta"
➡ Key:"A" Value:"Alpha"

1.3.2 Practical Dictionary’s

This will search a predetermined site for a query and open it in a
browser (icecat). Notice how the URL’s are formatted, this can be
obtained by looking in the URL of a search which usually looks
something like: search?q= where the string after = is the search

declare -A SITES
SITES=( ["gentoowiki"]=""

function search_site {
    echo " =➡ $BROWSER ${SITES[$SITE]}$QUERY="

search_site "gentoowiki" "emacs"

➡ icecat

1.3.3 Arguments and flags for programs / utils in bash

This function accepts the arguments;

  • {-x <yes|no>, -f <input file>, -o <output file>},

and is able to decode what bound value each parameter
has. This is done through the getopts function.

Where: getopts <opt1:opt2:...opt2:> <name>

function fun {
    echo "≡≡≡≡≡ Result ≡≡≡≡≡"
    while getopts x:o:f: option
        case "${option}"
            x) echo " -x := ${OPTARG} ";;
            o) echo " -o := ${OPTARG} ";;
            f) echo " -f := ${OPTARG} ";;
            ?) echo " error =  Bad " ;;    
    echo ""

fun -x yes -f ./file -o ./new;

≡≡≡≡≡ Result ≡≡≡≡≡
-x := yes
-f := ./file
-o := ./new

As we can see the results correspond to the input, with all keys being
able to be extracted.

1.4 Configure Swedish (Or other lang) keymaps in X11

  • ⚠ This may have to be externally installed.

The program setxkbmap, is able to set the keymap for the keyboard
used in X Server, which is very useful. This can be configured
permanently through X configuration files, but sometimes you can be lazy and
just add them to the auto-start script (or similar).

This sets the Swedish keymap;

setxkbmap se

1.5 W540 Thinkpad, turn of Thinkpad (use Trackpoint)

This is a script i use for turning of the Touch-pad on my w540
Thinkpad, this because without a desktop environment which
auto configures it, it is almost unusable. Interrupts typing, randomly
selects and deletes code, from random palm movements etc.

This will probably work on other laptops with some modification.
The program xinput is very easy to use, and very powerful. I can
strongly recommend it.

# Ge the correct input device from xinput
DEVICE=$(xinput | grep "TouchPad" | cut -f2 | awk -F "=" '{print $2 }')

# Useful if you just want to make the TouchPad less shitty
xinput set-prop $DEVICE 352 1 && printf "Palm Detection ⟹ On\n"
xinput set-prop $DEVICE 358 0 && printf "Gestures       ⟹ Off\n"

# Just turn it off anyway
xinput set-prop $DEVICE 343 1 && printf "TouchPad       ⟹ Off\n"

1.6 Run Webmacs without the “Thread error”

Webmacs Docs:
Webmacs Git:

Not sure if it is just my installation, the latest installation or my configs.
But my favorite browser webmacs does not launch on simply typing ./webmacs,
and throws a thread error and crashes.

I have looked through the Python source and deduced that the problem
was a bug in the default profile selection.

# Name: wmacs # Start on this site, can be left blank (FSF Shill)
INSTANCE=main   # Set instance, in where different instances are separete processes
webmacs -p=default -i=$INSTANCE $URL

The trick it seemed, was setting the profile to (=default). you can
add it as a globally recognized binary by linking it (script) to

chmod +x wmacs
ln -sr ./wmacs /usr/bin/wmacs

Now it can be ran with $ wmacs, but you may have to refresh your
[environment|restart shell], for it to directly recognize it.

1.7 Run Awesome WM within XFCE4

Awesome is a great window manager, but the integration of GTK+/2/3
is isn’t that good. There are a lot of things (some unnessisary) you
have to do when compensating with some of the features in desktop

And when using XFCE4, all of my keybindings stops working, my
keybindings which has been permanently etched into my brain and muscle
memory. There is not really any good way to manage windows the same way.

So it seems you can load XFCE4 as a Desktop Environment, but with
Awesome as Window Manager. You can do this with the XFCE
configuration tool.

xfconf-query -c xfce4-session -p /sessions/Failsafe/Client0_Command -t string -s “awesome” -a

To remove it simply run.

xfconf-query -c xfce4-session -p /sessions/Failsafe/Client0_Command -t string -s “xfwm4” -t string -s “–replace” -a

1.8 Rofi ⊃ DMenu

rofi is (like dmenu) a program for prompting, creating prompts and
running programs from prompts etc. For example when dmenu is
installed, a program called dmenu_run is installed. This program
opens up a prompt on the top of the screen, where you can run

1.8.1 DMenu

dmenu in itself is just a program to display and select text
(Menus), which has a lot of features and can be very powerful when
combined with other UNIX tools.

echo -e "One\nTwo\nThree" | dmenu

This program pipes a string of text into dmenu, where dmenu
separates the text into items (each line is an item). When one value
is selected and enter is pressed, that string is then returned. If the
users types a string which does not match with anything in the
text. It is also returned.

N1=$(echo -e "(10 - 309)\n-1" | dmenu -p "x = ")
N2=$(echo -e "-1\n2\n200\n(2 * 29)" | dmenu -p "y = ")
N3=$(echo -e "$N1 * $N2
$N1 + $N2
$N1 / $N2
$N1 - $N2" | dmenu -p "Method: ")

echo $[$N3] # Calculate 

This program prompts for the input of two numbers or equations where
they later are operated upon and the answer returned. Anyhow i think
you got the point.