scriptcheck.scriptcheck

 1import argparse
 2import sys
 3
 4from pathier import Pathier
 5from younotyou import younotyou
 6
 7
 8def get_scripts_windows() -> list[str]:
 9    """Returns a list of script stems for any `.exe` file in the current Python interpreter's `Scripts` folder."""
10    pypath = Pathier(sys.executable)
11    return [file.stem for file in (pypath.parent / "Scripts").glob("*.exe")]
12
13
14def get_scripts_unix() -> list[str]:
15    """Returns a list of scripts from `~/.local/bin`."""
16    return [file.name for file in (Pathier.home() / ".local" / "bin")]
17
18
19def get_scripts() -> list[str]:
20    """Returns a list of scripts."""
21    if sys.platform == "win32":
22        return get_scripts_windows()
23    else:
24        return get_scripts_unix()
25
26
27def get_args() -> argparse.Namespace:
28    parser = argparse.ArgumentParser()
29
30    parser.add_argument(
31        "includes",
32        nargs="*",
33        type=str,
34        default=["*"],
35        help=""" A list of wildcard patterns to search for scripts with.
36        i.e. >scriptcheck a* d*
37        will only print scripts starting with an 'a' or a 'd'.""",
38    )
39    args = parser.parse_args()
40
41    return args
42
43
44def main(args: argparse.Namespace | None = None):
45    if not args:
46        args = get_args()
47    print(*[script for script in younotyou(get_scripts(), args.includes)], sep="\n")
48
49
50if __name__ == "__main__":
51    main(get_args())
def get_scripts_windows() -> list[str]:
 9def get_scripts_windows() -> list[str]:
10    """Returns a list of script stems for any `.exe` file in the current Python interpreter's `Scripts` folder."""
11    pypath = Pathier(sys.executable)
12    return [file.stem for file in (pypath.parent / "Scripts").glob("*.exe")]

Returns a list of script stems for any .exe file in the current Python interpreter's Scripts folder.

def get_scripts_unix() -> list[str]:
15def get_scripts_unix() -> list[str]:
16    """Returns a list of scripts from `~/.local/bin`."""
17    return [file.name for file in (Pathier.home() / ".local" / "bin")]

Returns a list of scripts from ~/.local/bin.

def get_scripts() -> list[str]:
20def get_scripts() -> list[str]:
21    """Returns a list of scripts."""
22    if sys.platform == "win32":
23        return get_scripts_windows()
24    else:
25        return get_scripts_unix()

Returns a list of scripts.

def get_args() -> argparse.Namespace:
28def get_args() -> argparse.Namespace:
29    parser = argparse.ArgumentParser()
30
31    parser.add_argument(
32        "includes",
33        nargs="*",
34        type=str,
35        default=["*"],
36        help=""" A list of wildcard patterns to search for scripts with.
37        i.e. >scriptcheck a* d*
38        will only print scripts starting with an 'a' or a 'd'.""",
39    )
40    args = parser.parse_args()
41
42    return args
def main(args: argparse.Namespace | None = None):
45def main(args: argparse.Namespace | None = None):
46    if not args:
47        args = get_args()
48    print(*[script for script in younotyou(get_scripts(), args.includes)], sep="\n")