Banner of Boost Productivity with this i3 Keybindings Management Script

Enhance Your i3 Workflow: Keybinding Visualization Made Easy


Category: Linux

Date: 4 months ago
Views: 346


Introduction

I've been exploring the depths of the i3 window manager, reveling in its customization options and efficiency. Keybindings, in particular, are crucial for navigating my workflow seamlessly. However, managing, remembering and visualizing these keybindings can sometimes be challenging. That's where a simple Bash script comes to the rescue.

The Script

Let me introduce you to a handy Bash script that simplifies the management and visualization of i3 keybindings. Here's how it works:

It checks for the existence of a keybindings file: '/tmp/i3wm-keys'. If the file exists, it removes it and kills any running instances of Conky.

If the file doesn't exist, the script then filters the lines of i3 config file. The script extracts only the keybindings I want to list and show later,this is done by filtering out lines that don't start with a leading space before " bindsym". I have intentionally put the leading space in the beginning of the lines of some irrelevant keybindings in the i3 configuration file.

These keybindings are then formatted neatly in the file '/tmp/i3wm-keys' waiting to be fed to conky.

Finally, the script starts Conky, a lightweight system monitor, to display the keybindings in a customizable way.

the scirpt:

    
#!/bin/bash
if [[ -f /tmp/i3wm-keys ]]
    then
        rm /tmp/i3wm-keys
        killall conky
        killall conky
    else
	grep '^bindsym' ~/.i3/config |
        sed 's/bindsym//g;s|~/.i3/||g;s|~/bin/||g' |
        sed 's/mod1/alt/g' |
        sed 's/\$mod/win/g' |
	sed 's|~/.config/wchanger/||g' |
        sed 's/exec --no-startup-id/ /g' |
        awk '{
            keys[NR]=$1;
            for (i=2; i<=NF; i++) {
                command[NR]=command[NR] $i " ";
            }
        }
        END {
            for (i=1; i<=NR; i++) {
                key = sprintf("%-25s", keys[i]);
                cmd = sprintf("%-35s", command[i]);
                gsub(/ /,".",key);
                printf "%s %s    ", key, cmd;
                if (i % 2 == 0) printf "\n"; else printf " ";
            }
        }' > /tmp/i3wm-keys
	nohup conky -c "${HOME}/.i3/conky/shortcuts" </dev/null >/dev/null 2>&1 &
fi
    

The text goes over many filtering and cleanning steps, the last one of them is using awk that will format the key/command pairs. Finally saving it in the file '/tmp/i3wm-keys' before feeding it to the following conky script:

    
conky.config = {
    use_xft = true,
    font = 'DejaVu Sans Mono:size=13',
    xftalpha = 0.1,
    update_interval = 1,
    total_run_times = 0,

    own_window =true,
    own_window_type ="desktop",
    own_window_type ="override",
    own_window_transparent =true,
    own_window_hints ="undecorated,below,sticky,skip_taskbar,skip_pager",
    own_window_colour ="000000",
    own_window_argb_visual =true,
    own_window_argb_value =255,

    double_buffer = true,
    minimum_width =1150,
    maximum_width =1250,
    draw_shades = false,
    draw_outline = false,
    border_width = 1,
    draw_borders = false,
    draw_graph_borders = false,
    default_color = 'white',
    default_shade_color = 'red',
    default_outline_color = 'green',
    alignment = 'top_middle',
    gap_x = 10,
    gap_y = 10,
    no_buffers = true,
    uppercase = false,
    cpu_avg_samples = 2,
    net_avg_samples = 1,
    override_utf8_locale = true,
    use_spacer = 'none',
}

conky.text = [[
${color green}\
${voffset 15}\
${goto 370}\
${color green}\
_______________\
 .: i3wm shortcuts :. \
_______________\
${color lightblue}
${voffset +10}
${exec cat /tmp/i3wm-keys}
]]
    

Conclusion

In conclusion, this Bash script offers a simple yet effective solution for managing and visualizing i3 keybindings. Whether you're a seasoned i3 user or just getting started, integrating this script into your workflow can enhance your productivity and overall experience. Give it a try, and take control of your i3 keybindings like never before.

Thank you for reading, and feel free to explore further or reach out with any questions or feedback in the comments section below.



346 views

Previous Article Next Article

0 Comments, latest

No comments.