Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Renaming i3 workspaces with https://github.com/acrisci/i3ipc-python while keeping the <number>: <letter> prefix for keyboard navigation.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# renameworkspace.py - Renaming i3 workspaces with https://github.com/acrisci/i3ipc-python while keeping the <number>: <letter> prefix for keyboard navigation.
# Written in 2017 by Fahrstuhl
# To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
import i3ipc
import re
class WorkspaceRenamer(object):
prefixRegex = re.compile('\d+:\S+')
def __init__(self):
self.i3 = i3ipc.Connection()
def findFocusedWorkspace(self):
focused = self.i3.get_tree().find_focused()
workspace = focused.workspace()
return workspace
def getWorkspacePrefix(self):
workspace = self.findFocusedWorkspace()
oldname = workspace.name
prefix = self.prefixRegex.match(oldname)
if prefix is None:
raise LookupError("No workspace name found")
return prefix[0]
def interactiveRenameCurrentWorkspace(self):
prefix = self.getWorkspacePrefix()
renameCommand = 'rename workspace to "{} %s"'.format(prefix)
inputCommand = """exec i3-input -F '{}' -P "Rename workspace to: {} " """.format(renameCommand, prefix)
print(renameCommand)
print(inputCommand)
self.i3.command(inputCommand)
def main():
renamer = WorkspaceRenamer()
renamer.interactiveRenameCurrentWorkspace()
if __name__ == "__main__":
main()
@ekeih

This comment has been minimized.

Show comment Hide comment
@ekeih

ekeih Aug 18, 2017

Hi,

thank you for this helpful script!
I would like to put it in a repository to adjust it for my use case. Could you please add some licensing information?

Thank you in advance!
Max

ekeih commented Aug 18, 2017

Hi,

thank you for this helpful script!
I would like to put it in a repository to adjust it for my use case. Could you please add some licensing information?

Thank you in advance!
Max

@fahrstuhl

This comment has been minimized.

Show comment Hide comment
@fahrstuhl

fahrstuhl Oct 13, 2017

Oops, I overlooked your comment, sorry.
It's CC0 now.

Owner

fahrstuhl commented Oct 13, 2017

Oops, I overlooked your comment, sorry.
It's CC0 now.

@ekeih

This comment has been minimized.

Show comment Hide comment
@ekeih

ekeih Dec 31, 2017

Awesome, thank you 👍

ekeih commented Dec 31, 2017

Awesome, thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment