77 lines
2.4 KiB
Python
Executable File
77 lines
2.4 KiB
Python
Executable File
#!/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 subprocess
|
|
import sys
|
|
|
|
home = os.environ['HOME']
|
|
git_dirs = [home + "/work", home + "/projects", home + "/git", home + "/WebStormProjects", home + "/RiderProjects"]
|
|
icons = {}
|
|
|
|
|
|
def get_application_desktop_file_info(application: str, prefix: str) -> str:
|
|
path = f"{home}/.local/share/applications/jetbrains-{application}.desktop"
|
|
with open(path, 'r') as file:
|
|
for line in file.readlines():
|
|
if line.startswith(prefix):
|
|
return line
|
|
|
|
|
|
def get_project_type(project) -> str:
|
|
for file in os.listdir(project):
|
|
if file.endswith("pom.xml"):
|
|
return "idea"
|
|
if file.endswith("package.json"):
|
|
return "webstorm"
|
|
if file.endswith("cargo.toml") or file.endswith(".c"):
|
|
return "clion"
|
|
if file.endswith(".csproj") or file.endswith("DotSettings"):
|
|
return "rider"
|
|
if file.endswith(".py"):
|
|
return "pycharm"
|
|
if file.endswith(".go"):
|
|
return "goland"
|
|
return "idea"
|
|
|
|
|
|
def get_icon(project: str) -> str | None:
|
|
project_type = get_project_type(project)
|
|
if project_type is None:
|
|
return None
|
|
icon_line = get_application_desktop_file_info(project_type, 'Icon')
|
|
return icon_line[5:].rstrip()
|
|
|
|
|
|
def open_project(project: str) -> ():
|
|
project_type = get_project_type(project)
|
|
if project_type is None:
|
|
return
|
|
command = get_application_desktop_file_info(project_type, 'Exec')[6:-5]
|
|
subprocess.Popen([command + " " + project], shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
|
|
|
|
def print_project_message(project: str) -> ():
|
|
# exe=$(grep "Exec" "$HOME/.local/share/applications/jetbrains-$application.desktop" | sed 's/.*"\([^"]*\)".*/\1/')
|
|
icon = get_icon(project)
|
|
if icon is None:
|
|
return
|
|
|
|
print(f'{project}\0icon\x1f{get_icon(project)}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) == 1:
|
|
for git_dir in git_dirs:
|
|
if not os.path.isdir(git_dir):
|
|
continue
|
|
for project in os.listdir(git_dir):
|
|
project = f'{git_dir}/{project}'
|
|
if os.path.isdir(project):
|
|
print_project_message(project)
|
|
else:
|
|
open_project(sys.argv[1])
|