feat: add Python linting support with pylint and black
This commit is contained in:
@ -9,22 +9,27 @@ import subprocess
|
||||
sys.path.append(os.path.join(os.path.expanduser("~/.dotfiles"), "bin"))
|
||||
from helpers.functions import printfe, run_command
|
||||
|
||||
|
||||
def check_command_exists(command):
|
||||
"""Check if a command is available in the system"""
|
||||
try:
|
||||
subprocess.run(["which", command],
|
||||
check=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
subprocess.run(
|
||||
["which", command],
|
||||
check=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
return True
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
|
||||
|
||||
def list_screen_sessions():
|
||||
"""List all screen sessions"""
|
||||
success, output = run_command(["screen", "-ls"])
|
||||
return output
|
||||
|
||||
|
||||
def wipe_dead_sessions():
|
||||
"""Check and clean up dead screen sessions"""
|
||||
screen_list = list_screen_sessions()
|
||||
@ -32,47 +37,51 @@ def wipe_dead_sessions():
|
||||
print("Found dead sessions, cleaning up...")
|
||||
run_command(["screen", "-wipe"])
|
||||
|
||||
|
||||
def is_app_running(app_name):
|
||||
"""Check if an app is already running in a screen session"""
|
||||
screen_list = list_screen_sessions()
|
||||
return app_name in screen_list
|
||||
|
||||
|
||||
def start_app(app_name, command):
|
||||
"""Start an application in a screen session"""
|
||||
printfe("green", f"Starting {app_name} with command: {command}...")
|
||||
run_command(["screen", "-dmS", app_name] + command.split())
|
||||
time.sleep(1) # Give it a moment to start
|
||||
|
||||
|
||||
def main():
|
||||
# Define dictionary with app_name => command mapping
|
||||
apps = {
|
||||
"vesktop": "vesktop",
|
||||
"ktailctl": "flatpak run org.fkoehler.KTailctl",
|
||||
"ulauncher": "ulauncher --no-window-shadow --hide-window"
|
||||
"ulauncher": "ulauncher --no-window-shadow --hide-window",
|
||||
}
|
||||
|
||||
|
||||
# Clean up dead sessions if any
|
||||
wipe_dead_sessions()
|
||||
|
||||
|
||||
print("Starting auto-start applications...")
|
||||
for app_name, command in apps.items():
|
||||
# Get the binary name (first part of the command)
|
||||
command_binary = command.split()[0]
|
||||
|
||||
|
||||
# Check if the command exists
|
||||
if check_command_exists(command_binary):
|
||||
# Check if the app is already running
|
||||
if is_app_running(app_name):
|
||||
printfe("yellow", f"{app_name} is already running. Skipping...")
|
||||
continue
|
||||
|
||||
|
||||
# Start the application
|
||||
start_app(app_name, command)
|
||||
|
||||
|
||||
# Display screen sessions
|
||||
print(list_screen_sessions())
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
Reference in New Issue
Block a user