This script dynamically updates i3wm workspace names based on the names of the windows therein.
It also allows users to define an icon to show for a named window from the Font Awesome icon list or other system wide icon fonts.
update i3-bar workspace names to look something like this
Install the package from pypi with pip.
sudo pip3 install i3-workspace-names-daemon
NB. if you don't have sudo privileges instead do
pip3 install --user i3-workspace-names-daemon
You can use all icon fonts available on your system thanks to pango. More here.
You can install the Font Awesome font via your favourite package manager. This is necessary if you want to show an icon instead of a window's name in the i3 status bar.
For Debian/Ubuntu et al.
sudo apt install fonts-font-awesome
NB: if the glyphs are not rendering make sure the font is installed.
Add the following line to your ~/.i3/config
.
exec_always --no-startup-id exec i3-workspace-names-daemon
If you use the $mod+1
etc. shortcuts to switch workspaces then update the following so that the switch to workspace and move focused window to workspace shortcuts still work.
from
bindsym $mod+1 workspace 1
bindsym $mod+Shift+1 move container to workspace 1
# etc
to
bindsym $mod+1 workspace number 1
bindsym $mod+Shift+1 move container to workspace number 1
# etc
Configure what icons to show for what application-windows in the file ~/.i3/app-icons.json
or ~/.config/i3/app-icons.json
(in JSON format). For example:
chris@vulcan: ~$ cat ~/.i3/app-icons.json
{
"firefox": "firefox",
"chromium-browser": "chrome",
"chrome": "chrome",
"google-chrome": "chrome",
"x-terminal-emulator": "terminal",
"thunderbird": "envelope",
"jetbrains-idea-ce": "edit",
"nautilus": "folder-open",
"clementine": "music",
"vlc": "play",
"signal": "comment",
"_no_match": "question"
}
NB: to validate your config file is formatted correctly run this command and check it doesn't report an error
python3 -m json.tool /path/to/your/app-icons.json
where the key is the name of the i3-window (ie. what is shown in the i3-bar when it is not configured yet) and the value is the font-awesome icon name you want to show instead, see picking icons.
Note: the hard-coded list above is used if you don't add this icon-config file.
You can debug windows names with xprop
Windows names are detected by inspecting in the following priority
- name
- title
- instance
- class
If there is no window name available a question mark is shown instead.
Another (simpler) way for debugging window names is running this script with -v
or --verbose
flag, it is suggested to use a terminal emulator that supports unicode (eg. kitty or urxvt)
If a window is not in the icon config then by default the window title will be displayed instead.
The maximum length of the displayed window title can be set with the command line argument --max_title_length
or -l
.
To show a specific icon in place of unrecognised windows, specify an icon for window _no_match
in the icon config.
If you want to show only that icon (hiding the name) then use the --no-match-not-show-name
or -n
option.
To hide all unknown applications, use the --ignore-unknown
or -i
option.
The window delimiter can be specified with -d
or --delimiter
parameter by default it is |
.
The easiest way to pick an icon is to search for one in the gallery. NB: the "pro" icons are not available in the debian package.
As the i3bar supports pango markup, you can use almost all (icon-)fonts available on your system.
Custom text can be used instead of icons too.
All icon definitions starting with the <
character will be interpreted as pango markup.
To check which fonts are available for use in pango, run the command
pango-list
To test if you properly installed all required fonts and the markup is valid, you can use the following command, assuming you installed the file-icons or all-the-icons fonts (links are to the current page with codes that you need to put in the markup, not the homepage of the fonts):
echo -e '<span font_desc="file-icons">\ue926</span>' | pango-view --markup /dev/stdin
It should render the markup correctly. If not, you need to check your font installation.
The following example displays an emacs icon for all instances of emacs and the text "FF" in red for every firefox instance.
{
"firefox": "<span foreground=\"red\">FF</span>",
"emacs": "<span font_desc=\"file-icons\">\ue926</span>"
}
Some applications display the title of the current project in the window title to differentiate between multiple instances.
This information can be displayed in the i3bar by using the transform_title
directive.
Instead of a single string for the icon definition, use a json object as the property.
For the title transformation the property transform_title
is required.
The window identifier to be used, the same as in matching windows paragraph, defaults to window_title
that should be good for most of the use cases
The from
property defines a regex which must match the title of the window.
If the window title is not matched, no output will be shown.
To match any window title, use .*
as the value.
Use capturing groups (()
) to capture strings, which you can use in the transformation (as \1
, \2
, \3
, …).
Remember to escape backslashes with another backslash.
The string that will be displayed.
You can use strings that were matched by capturing groups in the from
regex.
Enables shortening the resulting displayed strings in a more recognizable name.
The name is split into groups of alphanumeric strings, which are all cut to a length of 3 and joined together using the adjacent separator in the original string.
This is applied after from
-> to
regex modification is done.
Example: i3-workspace_names+daemon
→ i3-wor_nam+dae
Emacs displays the current project in brackets ([<project name>]: <file name>
).
The project name can be matched by the capturing group in this regex: ".*\\[(.+?)\\].*"
.
Only the project name is shown as a result of the to
property.
"emacs": {
"transform_title": {
"from": ".*\\[(.+?)\\].*",
"to": "\\1",
"compress": true
},
"icon": "<span font_desc=\"file-icons\">\ue926</span>"
}