Icon caching and other rofi-git-repos cleanup

This commit is contained in:
Sage Vaillancourt 2023-03-07 11:58:11 -05:00
parent b0cfe40b96
commit 28a75d8a3c
1 changed files with 15 additions and 9 deletions

View File

@ -1,23 +1,30 @@
#!/usr/bin/python3 #!/usr/bin/python3
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import os import os
import subprocess import subprocess
import sys import sys
home = os.environ['HOME'] home = os.environ['HOME']
git_dirs = [home + "/work", home + "/projects", home + "/git", home + "/WebStormProjects", home + "/RiderProjects"] git_dirs = [
home + "/work",
home + "/projects",
home + "/git",
home + "/WebStormProjects",
home + "/RiderProjects"
]
icons = {} icons = {}
def get_application_desktop_file_info(application: str, prefix: str) -> str: def get_application_desktop_file_info(application: str, prefix: str) -> str:
existing_key = prefix + application
existing = icons.get(existing_key)
if existing is not None:
return existing
path = f"{home}/.local/share/applications/jetbrains-{application}.desktop" path = f"{home}/.local/share/applications/jetbrains-{application}.desktop"
with open(path, 'r') as file: with open(path, 'r') as file:
for line in file.readlines(): for line in file.readlines():
if line.startswith(prefix): if line.startswith(prefix):
icons[existing_key] = line
return line return line
@ -62,12 +69,11 @@ def open_project(project: str) -> ():
def print_project_message(project: str) -> (): def print_project_message(project: str) -> ():
# exe=$(grep "Exec" "$HOME/.local/share/applications/jetbrains-$application.desktop" | sed 's/.*"\([^"]*\)".*/\1/')
icon = get_icon(project) icon = get_icon(project)
if icon is None: if icon is None:
return return
print(f'{project}\0icon\x1f{get_icon(project)}') print(f'{project}\0icon\x1f{icon}')
if __name__ == '__main__': if __name__ == '__main__':