i3: Fast switching named workspaces

i3 is a tiling window manager which allows to work nicely with named workspaces. For example, I have a messaging/social workspace, a calendar and TODO workspace, two browser workspaces, my code workspaces and so forth. However, as the number of projects I work on increases, it becomes more difficult to keep track of the different workspaces. To solve this, it would be necessary to create new named workspaces. However, to do this, the config needs to be updated which I am usually to lazy to do.

Now, the core idea to solve this is based on the  i3-input  directive. This lets the user type the name of the desired workspace in order to easily create, rename and move to workspaces with very specific names on the fly. However, this becomes cumbersome when workspace names are longer than two or three characters. To solve this I came up with a little Python script which allows so “shortcode” workspaces. In the following I introduce the Python script as well as the corresponding i3 config entries.

The Python script

The Python script takes three parameters “prefix”, “query”, and “postfix”. It will then pick a workspace from the list of existing i3 workspaces if the query is a prefix of that workspace name (priority 1) or if the workspace contains the query (priority 2). Also, the script supports an “index”, i.e., you can append something to query using a . which is then appended to the name chosen by the script. For example is the workspaces project and project2 exists, then the query is p.2 will choose project2.  Then the script executes a command built from the prefix, the chosen workspace and the postfix: <prefix><chosen name><postfix> .

The i3 config

The Python script introduced above is then used in the i3 config as follows:

This allows to rename a workspace using MOD+Ctrl+m . For example using the name project2 . Then using MOD+m and typing p or  p.2 will take you to that workspace. Similarly, MOD+Shift+m and typing p or  p.2 will move the active container to the project workspace.


This made my life a lot easier since now it is possible to quickly create, rename, and move to arbitrarily named workspaces. I hope this helps a few people making their lives easier 😉 Finally, let me know if you have alternative or better solutions!