Created
March 31, 2021 08:17
-
-
Save theonejb/44fb56aeaf177861488ecb107cdb10aa to your computer and use it in GitHub Desktop.
A simple Python script to create an empty workspace in i3 using the next available number.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Creates a new i3 workspace with a number one greater than the last numbered workspace. If there are no numbered workspaces, uses 1. | |
""" | |
from i3ipc import Connection | |
def workspace_name_to_int(name): | |
digits = "".join([ | |
d for d in name if d.isdigit() | |
]) | |
if digits: | |
return int(digits) | |
else: | |
return 0 | |
def get_workspace_numbers(i3_con): | |
workspaces = i3_con.get_workspaces() | |
return [ | |
workspace_name_to_int(w.name) for w in workspaces | |
] | |
def get_next_available_workspace_number(i3_con): | |
current_workspace_numbers = get_workspace_numbers(i3_con) | |
sorted_workspace_numbers = sorted(current_workspace_numbers) | |
return sorted_workspace_numbers[-1] + 1 | |
def create_workspace(i3_con, number): | |
i3_con.command("workspace {}".format(number)) | |
if __name__ == "__main__": | |
i3_con = Connection() | |
next_workspace_number = get_next_available_workspace_number(i3_con) | |
create_workspace(i3_con, next_workspace_number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment