Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: DavidLyhedDanielsson/i3scripts
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: justbuchanan/i3scripts
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 3 files changed
  • 2 contributors

Commits on Dec 3, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fe70c44 View commit details
  2. format code with yapf

    justbuchanan committed Dec 3, 2021
    Copy the full SHA
    e00d710 View commit details

Commits on Sep 23, 2024

  1. util.py: fix SyntaxWarning in Python 3.12

    Python 3.12 (which is shipped on Ubuntu 24.04) raises a SyntaxWarning
    for a backslash-character pair (it was previously a DeprecationWarning,
    which is hidden by default). Fix it by using a raw string as suggested
    in the Python 3.12 release notes[1].
    
    [1]: https://docs.python.org/3/whatsnew/3.12.html#other-language-changes
    iomartin authored and justbuchanan committed Sep 23, 2024
    Copy the full SHA
    17e0cf8 View commit details
Showing with 28 additions and 26 deletions.
  1. +15 −15 autoname_workspaces.py
  2. +5 −6 rename_workspace.py
  3. +8 −5 util.py
30 changes: 15 additions & 15 deletions autoname_workspaces.py
Original file line number Diff line number Diff line change
@@ -72,6 +72,7 @@
'gnome-control-center': fa.icons['toggle-on'],
'gnome-terminal-server': fa.icons['terminal'],
'google-chrome': fa.icons['chrome'],
'prusa-slicer': fa.icons['cube'],
'gpick': fa.icons['eye-dropper'],
'imv': fa.icons['image'],
'insomnia': fa.icons['globe'],
@@ -135,8 +136,8 @@ def icon_for_window(window):
cls = cls.lower() # case-insensitive matching
if cls in WINDOW_ICONS:
return WINDOW_ICONS[cls]
logging.info(
'No icon available for window with classes: %s' % str(classes))
logging.info('No icon available for window with classes: %s' %
str(classes))
return DEFAULT_ICON


@@ -165,26 +166,27 @@ def rename_workspaces(i3, icon_list_format='default'):
n += 1

new_name = construct_workspace_name(
NameParts(
num=new_num, shortname=name_parts.shortname, icons=new_icons))
NameParts(num=new_num,
shortname=name_parts.shortname,
icons=new_icons))
if workspace.name == new_name:
continue
i3.command(
'rename workspace "%s" to "%s"' % (workspace.name, new_name))
i3.command('rename workspace "%s" to "%s"' %
(workspace.name, new_name))


# Rename workspaces to just numbers and shortnames, removing the icons.
def on_exit(i3):
for workspace in i3.get_tree().workspaces():
name_parts = parse_workspace_name(workspace.name)
new_name = construct_workspace_name(
NameParts(
num=name_parts.num, shortname=name_parts.shortname,
icons=None))
NameParts(num=name_parts.num,
shortname=name_parts.shortname,
icons=None))
if workspace.name == new_name:
continue
i3.command(
'rename workspace "%s" to "%s"' % (workspace.name, new_name))
i3.command('rename workspace "%s" to "%s"' %
(workspace.name, new_name))
i3.main_quit()
sys.exit(0)

@@ -204,13 +206,11 @@ def on_exit(i3):
'--icon_list_format',
type=str,
default='default',
help=
"The formatting of the list of icons."
help="The formatting of the list of icons."
"Accepted values:"
" - default: no formatting,"
" - mathematician: factorize with superscripts (e.g. aababa -> a⁴b²),"
" - chemist: factorize with subscripts (e.g. aababa -> a₄b₂)."
)
" - chemist: factorize with subscripts (e.g. aababa -> a₄b₂).")
args = parser.parse_args()

RENUMBER_WORKSPACES = not args.norenumber_workspaces
11 changes: 5 additions & 6 deletions rename_workspace.py
Original file line number Diff line number Diff line change
@@ -61,13 +61,12 @@ def rename_workspace(new_shortname=None):

# get the current workspace and rename it
new_name = construct_workspace_name(
NameParts(
num=name_parts.num,
shortname=new_shortname,
icons=name_parts.icons))
NameParts(num=name_parts.num,
shortname=new_shortname,
icons=name_parts.icons))
workspace = focused_workspace(i3)
res = i3.command(
'rename workspace "%s" to "%s"' % (workspace.name, new_name))
res = i3.command('rename workspace "%s" to "%s"' %
(workspace.name, new_name))
assert res[0]['success'], "Failed to rename workspace"


13 changes: 8 additions & 5 deletions util.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ def focused_workspace(i3):
# * 'icons' - the string that comes after the
# Any field that's missing will be None in the returned dict
def parse_workspace_name(name):
m = re.match('(?P<num>\d+):?(?P<shortname>\w+)? ?(?P<icons>.+)?',
m = re.match(r'(?P<num>\d+):?(?P<shortname>\w+)? ?(?P<icons>.+)?',
name).groupdict()
return NameParts(**m)

@@ -57,6 +57,7 @@ def xprop(win_id, property):
_superscript = "⁰¹²³⁴⁵⁶⁷⁸⁹"
_subscript = "₀₁₂₃₄₅₆₇₈₉"


def _encode_base_10_number(n: int, symbols: str) -> str:
"""Write a number in base 10 using symbols from a given string.
@@ -82,7 +83,8 @@ def format_icon_list(icon_list, icon_list_format='default'):
new_list = []
for icon, count in Counter(icon_list).items():
if count > 1:
new_list.append(icon + _encode_base_10_number(count, _superscript))
new_list.append(icon +
_encode_base_10_number(count, _superscript))
else:
new_list.append(icon)
return ' '.join(new_list)
@@ -93,11 +95,12 @@ def format_icon_list(icon_list, icon_list_format='default'):
new_list = []
for icon, count in Counter(icon_list).items():
if count > 1:
new_list.append(icon + _encode_base_10_number(count, _subscript))
new_list.append(icon +
_encode_base_10_number(count, _subscript))
else:
new_list.append(icon)
return ' '.join(new_list)

else:
raise ValueError("Unknown format name for the list of icons: ", icon_list_format)

raise ValueError("Unknown format name for the list of icons: ",
icon_list_format)