From 6b41d602cfe783ffb6c6cc4aca671e7ba5c00551 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Mon, 14 Dec 2020 10:12:45 +0100 Subject: [PATCH] Fix crash when no command set --- dirbuild.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dirbuild.py b/dirbuild.py index 768ffac..aa29b15 100755 --- a/dirbuild.py +++ b/dirbuild.py @@ -71,9 +71,10 @@ def set_command(cursor: Cursor, cwd: str, command: str): def get_command(cursor: Cursor, cwd: str) -> str: """Get the command for the current directory""" - return cursor.execute( + cmd = cursor.execute( "SELECT cmd FROM commands WHERE dir = ? ORDER BY id DESC LIMIT 1", (cwd,) - ).fetchone()[0] + ).fetchone() + return cmd[0] if cmd is not None else "" def dump_db(cursor: Cursor): @@ -90,6 +91,7 @@ def main(): db = init_db() if arguments["set"]: set_command(db.cursor(), os.getcwd(), arguments[""]) + print("Saved command successfully") elif arguments["get"]: print(get_command(db.cursor(), os.getcwd())) elif arguments["dump"]: