# workspace_icon.py -rw-r--r-- 1.0 KiB View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
"""
Add a lil emoji icon to workspace names. If you want to clear a name, focus on
the workspace, hit cmd+shift+n, then hit escape.

For this to work you'll need to add a keybinding like so to your sway config:

    bindsym $mod+Shift+n exec ~/path/to/workspace_icon.py

Make sure you chmod +x the script!
"""
from i3ipc import Connection
import subprocess
import sys

if __name__ == "__main__":
    i3 = Connection()
    wrkspc_name = i3.get_tree().find_focused().workspace().name
    if ' ' in wrkspc_name:
        index = wrkspc_name.split(' ')[0].strip()
    else:
        index = wrkspc_name

    result = subprocess.run([
        'rofi',
            '-show', 'emoji',
            '-combi-modes', 'emoji',
            '-emoji-mode', 'stdout'
    ], capture_output=True)
    emoji = result.stdout.decode('utf-8').strip()

    if len(emoji) == 0:
        i3.command(f'rename workspace "{wrkspc_name}" to "{index}"')
    else:
        i3.command(f'rename workspace "{wrkspc_name}" to "{index} {emoji}"')