[Python] How to globally configure just on Windows to run and edit scripts using short aliases...

Discussão em 'Python' iniciado por Stack, Maio 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to globally configure just on my Windows machine to simplify running and editing scripts from anywhere using short aliases.

    Folder Structure


    I have a folder D:\Scripts with subfolders containing Python and JavaScript scripts:

    D:\Scripts\
    ├── mvsl\
    │ ├── find-duplicate-images.py
    │ └── kinopoisk.ru-downloader.js
    └── comics\
    ├── rename_cbz.py
    └── zip_up.py

    What I Want


    I'd like to define simple aliases like this in a global justfile:

    mvsl_finddups = "mvsl/find-duplicate-images.py"


    Then be able to run commands like:

    just run mvsl.finddups # Runs the script using the correct interpreter
    just edit mvsl.finddups # Opens the script in VSCode


    Requirements:


    • I want to run just from any folder (i.e., global config).


    • The run command should detect the correct interpreter based on file extension:
      • .py → Python
      • .js → Node.js

    • The edit command should open the corresponding file in VSCode.


    • I only want to specify the folder and short name, and just should handle the rest (paths, interpreter, etc).
    What I Tried


    I tried defining a global justfile like this:

    # Use PowerShell on Windows
    set windows-shell := ["powershell.exe", "-NoLogo", "-Command"]

    # Base script directory
    script_dir := "D:/Scripts/"

    # Script mapping (short aliases)
    mvsl_finddups := "mvsl/find-duplicate-images.py"
    mvsl_kinopoisk := "mvsl/kinopoisk.ru-downloader.js"

    # Run a script by alias
    run alias:
    script := {{alias}}
    path := script_dir + script

    if path.endswith(".py") {
    python {{path}}
    } else if path.endswith(".js") {
    node {{path}}
    } else {
    echo "Unsupported script type: {{path}}"
    }

    # Edit a script by alias
    edit alias:
    code {{script_dir}}{{alias}}


    But when I run:

    just run mvsl_finddups


    it doesn't work as expected, and it's hard to manage path separators and aliases this way. Also, my earlier attempt with:

    run subfolder script_name:
    python "{{ script_dir }}{{ subfolder }}/{{ script_name }}"


    led to issues where mvsl was passed literally as the folder name instead of resolving to movie-stills/.

    Question


    How can I globally configure a justfile on Windows to:

    • Use short aliases like mvsl.finddups
    • Automatically resolve to full paths under D:/Scripts/
    • Use the correct interpreter based on file extension
    • Support commands like just run alias and just edit alias?

    If possible, I'd like to avoid manually typing full paths or file extensions every time and keep my configuration DRY and declarative.

    Continue reading...

Compartilhe esta Página