improved automatic script alias creation and switched to lookup paths for nix-shell invocations

This commit is contained in:
Seaswimmer 2024-12-02 15:05:24 -05:00
parent 41a1a6a5f5
commit 209294075c
Signed by: cswimr
GPG key ID: 0EC431A8DA8F8087
7 changed files with 21 additions and 10 deletions

View file

@ -128,13 +128,26 @@ alias_dictionary = {
"s": "sudo", "s": "sudo",
} }
# Create aliases for scripts with the .py extension stripped # Create aliases for scripts with the file extension stripped
script_path = Path("/etc/nixos/scripts") script_path = Path("/etc/nixos/scripts")
if script_path.exists(): if script_path.exists():
for script in script_path.glob("*.py"): for sub_dir in script_path.iterdir():
if script.name == "__init__.py": # ignore files within the nix subdirectory, since they are just nix-shell expressions
# if you aren't using nix, you can remove this if statement
if sub_dir.name == "nix":
continue continue
script_name = script.name.strip(".py") if not sub_dir.is_dir():
aliases.update({script_name: [str(script)]}) c = colors.Colors
print(f"{c.YELLOW}{c.BOLD}WARNING: The path {c.PURPLE}'{sub_dir}'{c.YELLOW} is not a directory. Skipping alias creation for this path.{c.END}")
continue
extension = f".{sub_dir.name}"
for script in sub_dir.glob(f"*{extension}"):
if script.name == "__init__.py":
continue
script_name = script.stem
aliases[script_name] = [str(script)]
aliases.update(alias_dictionary) aliases.update(alias_dictionary)

View file

@ -1,7 +1,5 @@
let let
nixpkgs = fetchTarball pkgs = import <nixpkgs> {
"https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz";
pkgs = import nixpkgs {
config = { }; config = { };
overlays = [ ]; overlays = [ ];
}; };

View file

@ -1,5 +1,5 @@
#! /usr/bin/env nix-shell #! /usr/bin/env nix-shell
#! nix-shell /etc/nixos/nixos/script-dependencies.nix -i python #! nix-shell /etc/nixos/scripts/nix/python.nix -i python
import argparse import argparse
import os import os

View file

@ -1,5 +1,5 @@
#! /usr/bin/env nix-shell #! /usr/bin/env nix-shell
#! nix-shell /etc/nixos/nixos/script-dependencies.nix -i python #! nix-shell /etc/nixos/scripts/nix/python.nix -i python
import argparse import argparse
import mimetypes import mimetypes