Preface
Goal: Separate Main Flow, Code, and Data.
So anyone can focus to alter special customization in Main Script, without changing the whole stuff.
Reading
Before you jump off to scripting, you might desire to read this overview.
All The Source Code:
Impatient coder like me, like to open many tab on browser.
Table of Content
-
Preface: Table of Content
-
3: System Calls
-
6: Hash: Config
-
10: Run Baby Run
Screenshot
Since statusbar is out of topic in this tutorial, I present no panel HerbstluftWM screenshot featuring zero gap.
1: Directory Structure
Directory Structure has been explained in preface.
This figure will explain how it looks
in BASH script
directory.
2: Modularizing in BASH
Here we are talking how to create module and call module. It is very straightforward in BASH. No dark magic required.
Declare a module
Nothing to declare, just do not forget the shebang #!
and executable permission.
Call a module
3: System Calls
There is no such thing as system calls in bash. Everything in bash is command called in system environment. That is the most advantage of using BASH to configure HLWM.
Here we wrap herbstclient
system call
in a function named hc
.
helper.sh
autostart.sh
4: Array: Tag Names and Keys
config.sh
5: Hash: Color Schemes
Using key-value pairs, a simple data structure.
gmc.sh
autostart.sh
View Source File:
6: Hash: Config
The Hash in Config is very similar with the colors above. Except that it has string interpolation all over the place.
config.sh
This config will be utilized in main script as shown in the following code.
autostart.sh
Specific BASH Issue
Be aware of these two. Specific BASH only issue. Since BASH directly interpret the interpolation in system environment. Changing double quote to single quote prevent the terminal spawning, even when you double quote it later.
I also have unsolved issue with tilde ~
expansion inside double quote.v
I have still have to use some config without helper.
View Source File:
7: Processing The Hash Config
This is the heart of this script.
This do-config
function has two arguments,
the herbstclient command i.e “keybind”, and hash from config.
Since BASH does not have built support for passing hash argument,
this require a little hack and a few cryptic character.
helper.sh
Debug Herbstclient Command
I do not remove line where I do debug when I made this script, so anyone can use it later, avoid examining blindly. Sometimes strange things happen. Just uncomment this line to see what happened.
You can see the debugging result in figure below.
View Source File:
8: Setting the Tags
This should be done before doing any config rules. I did copy-paste part of the original configuration, turn the code into function, and make just a few modification.
Nothing special here, BASH read all global variable from other files.
helper.sh
9: Launch the Panel
Two more functions left, it is do_panel
and startup_run
.
Again, I did copy-paste part of the original configuration,
turn the code into function, and make just a few modification.
This two should be very easy to do in BASH. Nothing special in BASH. But this could be complex task, in other language, such as Lua.
helper.sh
10: Run Baby Run
This is the last part. It is intended to be modified. Everyone has their own personal preferences.
startup.sh
View Source File:
11: Putting It All Together
The last part is going to main script and putting it all back together.
Now the flow is clear
Header Part: autostart.sh
Procedural Part: autostart.sh
View Source File:
Coming up Next
After the Window Manager, comes the Panel.
Happy Configuring.