r/linux • • 21d ago

Software Release pathaction - One Linux command to run, compile, lint, deploy, or debug any file or directory [Release 1.1.0]

https://github.com/jamescherti/pathaction

When jumping between different codebases and environments, it can be hard to remember the specific deployment method, build tools, linters, and test runners for each file or project.

The pathaction tool is a command-line tool for running commands on files and directories. Think of pathaction as the equivalent of your IDE's "Run" and "Debug" buttons, or a Makefile designed to work on individual files and directories.

Pass any file or directory as an argument, and pathaction executes the right command based on a .pathaction.yaml configuration:

  • Works on any file: source code, config files, media...

  • Supports Jinja2 in .pathaction.yaml so you can build dynamic commands using the target path's filename, extension, or directory.

  • Define multiple actions for the exact same file type. You can map the default action to execute a script, a debug tag to attach a debugger, and a lint tag to check formatting.

This tool is built for software developers or Linux administrators who manage multiple projects across diverse environments.

0 Upvotes

7 comments sorted by

3

u/CoolGuyMemeHead 21d ago

Why would I want one command that I have to configure to do what I want when I could just run the command that does every time exactly what I want?

0

u/jamescherti 20d ago

If you are just running a one-off command (e.g., python script.py) in your terminal, typing it out directly is faster. That is not really the problem pathaction is solving.

Think of pathaction it as an abstraction layer between your tools (like editors or shell bindings) and the diverse environments on your filesystem:

  • If you use an editor such as Emacs or Vim, you probably want a single hotkey to run, test, lint, or deploy the current buffer. Instead of hardcoding project-specific runners in your editor config, the editor just calls something like pathaction -t deploy <current-file>. The local .pathaction.yaml rules ensure the right command is executed.

  • Execution environments change based on the directory. A .py file in ~/project_a might need ./.venv/bin/pytest, while one in ~/project_b requires docker exec -i container pytest. Because .pathaction.yaml files cascade up the tree like .gitignore, you can set global defaults in your home directory and override them per project.

  • It saves you from digging through shell history for long commands like g++ -Wall -O2 file.cpp -o file && ./file. You define the rule once per directory and use a uniform interface everywhere.

It is the same logic behind using Makefile targets to avoid typing raw compiler invocations. The difference is that pathaction acts on any file paths instead of being tied to static build targets in a single directory.

1

u/kantorcodes1 20d ago

You mention that .pathaction.yaml files cascade up the tree like .gitignore. If home and project configs define the same tag, does the nearest file override just that action or the whole rule for that file type?

0

u/jamescherti 19d ago edited 19d ago

Hello u/kantorcodes1,

Thanks for the question. The nearest .pathaction.yaml file overrides only the specific rule that matches both the file type and the tag. When pathaction evaluates .pathaction.yaml rule-set files from your home directory down to your project directory, it merges the action lists by placing your local project actions/rules at the very top and the inherited global rules (home directory) below them.

When you pass a file or a directory to the pathaction tool, it scans this combined list from top to bottom. It stops and runs the first action block that matches both your target file and the requested tag.

I added the above to the README file with an example

Let me know if you have any other questions.

Note: Please ensure upgrading to pathaction >= 1.1.1. I added enhancements related to the above.

0

u/kantorcodes1 18d ago

Thanks for adding the README example. The cascade is much clearer now. Since pathaction launches configured commands for file and directory targets, it could fit as a command source in HOL Guard. We'd welcome a descriptor PR for the executable and its target behavior. The command extension guide shows the descriptor and tests; a first PR can add it with a fixture under contributions/command-sources/ against main. External command sources stay disabled until a local admin enables them.

1

u/arwinda 20d ago

This feels like "I couldn't remember the commands and did not want to read the README, so I built a new tool where I have to remember the commands".

0

u/jamescherti 19d ago

I understand why it might look that way, but the intent is the exact opposite.

The problem pathaction addresses is context switching. When you work across multiple ecosystems daily (such as Python, Node.js, Ansible, and Go), every project has its own specific way to run, build, test, deploy, or lint. You end up having to memorize a dozen different toolchains or constantly check the README for every repository.

The goal of pathaction is to eliminate that mental overhead. You define the .pathaction.yaml configuration once. After that, you do not have to remember any of the underlying commands. You just run one unified command, or press a single hotkey in your editor, and it executes the correct toolchain based on the exact file type or directory you are currently looking at.