From 2738f6cc94383c08f7ee348f357026d7dd45defb Mon Sep 17 00:00:00 2001 From: Tobias Manske Date: Sun, 10 Jun 2018 21:56:57 +0200 Subject: [PATCH 1/2] Make git lg look nicer --- .gitconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitconfig b/.gitconfig index 15e47ec..fa72104 100644 --- a/.gitconfig +++ b/.gitconfig @@ -3,7 +3,7 @@ name = Tobias Manske signingkey = 978D99F12D4E041F [alias] - lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit + lg = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all cu = "!git branch --merged | grep -v '\\*' | grep -v master | xargs -n 1 git branch -d" undo = reset HEAD~ [commit] From ea533a48ab5c5ce75873387c98c5958f7a03b485 Mon Sep 17 00:00:00 2001 From: Tobias Manske Date: Sun, 10 Jun 2018 21:59:13 +0200 Subject: [PATCH 2/2] used black to reformat python scripts --- i3/scripts/dmenu/Dmenu.py | 7 ++++- i3/scripts/dmenu/init.py | 59 ++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/i3/scripts/dmenu/Dmenu.py b/i3/scripts/dmenu/Dmenu.py index 79d91d7..e0578f4 100644 --- a/i3/scripts/dmenu/Dmenu.py +++ b/i3/scripts/dmenu/Dmenu.py @@ -15,5 +15,10 @@ class Dmenu(object): def run(self): """Returns (exitCode, stdout)""" - p1 = subprocess.run(self._dmenu, input="\n".join(self._items), encoding="utf-8", stdout=subprocess.PIPE) + p1 = subprocess.run( + self._dmenu, + input="\n".join(self._items), + encoding="utf-8", + stdout=subprocess.PIPE, + ) return (p1.returncode, p1.stdout) diff --git a/i3/scripts/dmenu/init.py b/i3/scripts/dmenu/init.py index 3ada4fd..497a376 100755 --- a/i3/scripts/dmenu/init.py +++ b/i3/scripts/dmenu/init.py @@ -20,18 +20,40 @@ con = sqlite3.connect(os.path.dirname(sys.argv[0]) + "/database.sqlite") # ARGUMENTS PARSER -parser = argparse.ArgumentParser(description='Smart Dropdown Launcher for AwesomeWM') -parser.add_argument('--create', dest='FLAG_CREATE', action='store_const', const=True, default=False, help='Force TABLE \ - CREATION') -parser.add_argument('--build', dest='FLAG_BUILD', action='store_const', const=True, default=False, help='Force Build \ -the Database') -parser.add_argument('--truncate', dest='FLAG_TRUNCATE', action='store_const', const=True, default=False, help='Truncate\ - Database during build') +parser = argparse.ArgumentParser(description="Smart Dropdown Launcher for AwesomeWM") +parser.add_argument( + "--create", + dest="FLAG_CREATE", + action="store_const", + const=True, + default=False, + help="Force TABLE \ + CREATION", +) +parser.add_argument( + "--build", + dest="FLAG_BUILD", + action="store_const", + const=True, + default=False, + help="Force Build \ +the Database", +) +parser.add_argument( + "--truncate", + dest="FLAG_TRUNCATE", + action="store_const", + const=True, + default=False, + help="Truncate\ + Database during build", +) args = parser.parse_args() # Helper functions + def create_db(): command = "CREATE TABLE entries(`ID` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, `Name` TEXT, `json` TEXT, `hits` INTEGER NOT NULL DEFAULT 0, `disabled` INTEGER NOT NULL DEFAULT 0, `type` TEXT NOT NULL DEFAULT 'file', `file` TEXT);" with con: @@ -49,7 +71,7 @@ def retrieve_db(): ro = cur.fetchall() for r in ro: r = dict(r) - r['json'] = json.loads(r['json']) + r["json"] = json.loads(r["json"]) rows.append(r) return rows @@ -59,16 +81,19 @@ def build_db(): for mod in loadModules: entries.update(mod.build_db()) for k, v in entries.items(): - with con: - con.cursor().execute("INSERT INTO entries(Name, json, file, type, disabled) VALUES(?, ?, ?, ?, ?)", - (k, json.dumps(v['json']), v['file'], v['type'], v['disabled'])) + if "Exec" in v["json"]: + with con: + con.cursor().execute( + "INSERT INTO entries(Name, json, file, type, disabled) VALUES(?, ?, ?, ?, ?)", + (k, json.dumps(v["json"]), v["file"], v["type"], v["disabled"]), + ) def build_menu(): entries = [] db = retrieve_db() for mod in loadModules: - entries += mod.build_menu([x for x in db if x['type'] == mod.db_type]) + entries += mod.build_menu([x for x in db if x["type"] == mod.db_type]) # sort by hits return sorted(entries, key=lambda i: i[2], reverse=True) @@ -80,21 +105,21 @@ def run_program(data): cur.execute("UPDATE entries SET hits=? WHERE ID=?", (data[2] + 1, data[0])) cur.execute("SELECT type FROM entries WHERE ID=?", (data[0],)) con.commit() - typ = dict(cur.fetchone())['type'] + typ = dict(cur.fetchone())["type"] for mod in loadModules: if mod.db_type == typ: mod.call(data[1]) -if (args.FLAG_CREATE): +if args.FLAG_CREATE: with con: con.cursor().execute("DROP TABLE IF EXISTS entries;") create_db() # set BUILD flag so the database gets rebuilt too args.FLAG_BUILD = True -if (args.FLAG_BUILD): - if(args.FLAG_TRUNCATE): +if args.FLAG_BUILD: + if args.FLAG_TRUNCATE: with con: con.cursor().execute("DELETE FROM entries") con.cursor().execute("DELETE FROM sqlite_sequence WHERE name='entries'") @@ -104,7 +129,7 @@ if (args.FLAG_BUILD): entries = build_menu() p1 = Dmenu([x[1] for x in entries]).run() -if (p1[0] != 0): +if p1[0] != 0: # error on escape exit(1)