Shortcuts package

This commit is contained in:
Nathan McCarty 2023-06-17 03:22:55 -04:00
parent e78180c263
commit 3d80cdf667
Signed by: thatonelutenist
SSH Key Fingerprint: SHA256:hwQEcmak9E6sdU9bXc98RHw/Xd1AhpB5HZT7ZSVJkRM
3 changed files with 91 additions and 1 deletions

View File

@ -281,7 +281,11 @@
}; };
}; };
in { in {
packages = flake-utils.lib.flattenTree { packages = let
writePython311Script =
pkgs.writers.makePythonWriter pkgs.python311 pkgs.python311Packages
pkgs.buildPackages.python311Packages;
in flake-utils.lib.flattenTree {
discordWayland = pkgs.callPackage ./packages/discord/default.nix rec { discordWayland = pkgs.callPackage ./packages/discord/default.nix rec {
pname = "discord-electron"; pname = "discord-electron";
binaryName = "DiscordCanary"; binaryName = "DiscordCanary";
@ -297,6 +301,19 @@
swayimg = pkgs.callPackage ./packages/swayimg/default.nix { }; swayimg = pkgs.callPackage ./packages/swayimg/default.nix { };
hyprland-autoname-workspaces = hyprland-autoname-workspaces =
pkgs.callPackage ./packages/workspace-renamer/default.nix { }; pkgs.callPackage ./packages/workspace-renamer/default.nix { };
shortcuts = let
script = writePython311Script "shortcuts" { }
(builtins.readFile ./scripts/shortcuts/shortcuts.py);
in pkgs.stdenv.mkDerivation {
name = "shortcuts";
src = ./shortcuts;
installPhase = ''
mkdir -p $out/bin
ln -s ${script} $out/bin/shortcuts
mkdir -p $out/shortcuts
cp -r * $out/shortcuts
'';
};
}; };
}); });
} }

68
scripts/shortcuts/shortcuts.py Executable file
View File

@ -0,0 +1,68 @@
# https://blog.stigok.com/2019/11/05/packing-python-script-binary-nicely-in-nixos.html
import argparse
import tomllib
import os
import subprocess
import sys
from pathlib import Path
def parse_directory(directory):
dictionary = {}
for entry in os.listdir(directory):
path = directory / entry
if path.is_dir():
dictionary[entry] = parse_directory(path)
else:
dictionary[entry] = path
return dictionary
def merge(dict1, dict2):
for key in iter(dict2):
if key in dict1:
if isinstance(dict1[key], dict) and isinstance(dict2[key], dict):
merge(dict1[key], dict2[key])
else:
dict1[key] = dict2[key]
else:
dict1[key] = dict2[key]
parser = argparse.ArgumentParser(prog='shortcuts.py',
description="shortcut dispatcher")
parser.add_argument('config')
args = parser.parse_args()
data = ""
with open(args.config, 'rb') as f:
data = tomllib.load(f)
dicts = []
for dir in data["directories"]:
path = Path(dir).expanduser()
if path.exists():
dicts.append(parse_directory(path))
res = {}
for d in dicts:
merge(res, d)
while isinstance(res, dict):
items = '\n'.join(sorted(res))
proc = subprocess.Popen(data["picker_command"],
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
proc.stdin.write(str.encode(items))
outs, errs = proc.communicate()
outs = outs.decode().strip()
res = res[outs]
proc = subprocess.Popen(res,
stdin=sys.stdin.buffer,
stdout=sys.stdout.buffer,
stderr=sys.stderr.buffer)
proc.wait()

5
shortcuts/vmware/1440p Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
sleep 3 &
echo "Hello"
wait