{"id":21441569,"url":"https://github.com/atreyagaurav/onchange","last_synced_at":"2025-07-14T17:31:59.137Z","repository":{"id":111461664,"uuid":"601328067","full_name":"Atreyagaurav/onchange","owner":"Atreyagaurav","description":"CLI utility to automatically run commands on file change","archived":false,"fork":false,"pushed_at":"2024-02-15T02:47:36.000Z","size":203,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-02-15T03:33:16.813Z","etag":null,"topics":["cli"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Atreyagaurav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-02-13T20:49:23.000Z","updated_at":"2023-06-18T03:48:39.000Z","dependencies_parsed_at":"2024-02-15T03:31:45.622Z","dependency_job_id":"cf7dbc70-c241-43c5-b049-89c4a43297c4","html_url":"https://github.com/Atreyagaurav/onchange","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atreyagaurav%2Fonchange","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atreyagaurav%2Fonchange/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atreyagaurav%2Fonchange/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Atreyagaurav%2Fonchange/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Atreyagaurav","download_url":"https://codeload.github.com/Atreyagaurav/onchange/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225990491,"owners_count":17556152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli"],"created_at":"2024-11-23T01:38:29.749Z","updated_at":"2024-11-23T01:38:30.272Z","avatar_url":"https://github.com/Atreyagaurav.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\nOnChange is a CLI utility that can run commands when it detects changes on the files you ask it to watch. \n\nThe syntax is: `onchange file1 file2... -- command`. You have to separate the command with `--` or you can have no command if you only want to see the changes. There are other flags like the template for change message, and flags for async execution of the command. \n\nThe async flag will help you if you don't want to miss on other changes when the command is executing, each command will be executed in a thread with this flag.\n\nIf you want more functionality there is a tool with more options than this one: [watchexec](https://github.com/watchexec/watchexec).\n\n# Demo\n\n![Screenshot](images/screenshot.png)\n\nHere in this image, the pdf is shown in green box (right), which is being compiled anytime the `.tex` file or `graph.pdf` file is changed (blue box). And the `graph.pdf` file is generated every time `graph.gv` file is changed (yellow box). So when you change the graviz file (red box), the `graph.pdf` is updated and then the final pdf. Hence, you can use it when you need to review changes without having to re-compile stuffs.\n\n[Video Demo](https://youtu.be/PbEqUU-tBXQ)\n\n# Usage\n\n## Command Template\nYou can put a simple command after `--` that'll run the same, or you can use some variables based on the file the changes were detected on.\n\nThe templates for the file change detect, and the command can have few variables. Pass the template with these variables inside curly braces `{}`. Remember to escape the curly braces itself.\n\n| Variable | Value                                             |\n|----------|---------------------------------------------------|\n| path     | full path of the changed file                     |\n| rpath    | relative path of the changed file wrt PWD         |\n| dir      | directory (parent) of the changed file (absolute) |\n| rdir     | directory (parent) of the changed file (relative) |\n| name     | filename of the changed file                      |\n| ext      | extension of the changed file (excludes `.`)      |\n| name.ext | name and extension of the changed file            |\n\nFor example: you can do `onchange --recursive . --template '{path}'` to watch any file change in a working directory. Similarly, you can use other variables to be creative with the commands.\n\n## config file\nYou can use config files to determine the default actions for some file extensions. If you give commands then the config file will be ignored.\n\nThe config will be read from these locations:\n- \"/etc/onchange.toml\"\n- \"$HOME/.config/onchange.toml\"\n- \".onchange.toml\"\nThe later will overwrite the former if same config is present. And if you provide a file with `--config` flag, then none of these will be read and only the config from the fill will be used.\n\nThe format of the config file should be something like:\n\n    [latex]\n    extensions=\"tex\"\n    command=\"latexmk -pdf {name.ext}\"\n\nHere the rule will be in `[]` and then the space separated list of extensions to apply this rule to, and then command template to run. You can put a rule with empty command if you want to make \"ignore rule\" (though it'll be detected and shown). Here, with this config, any change in `.tex` file will run `latexmk` command on that file to generate a pdf.\n\n# Help\n\n`onchange --help` will give you the help menu with usage details.\n\n\n    Usage: onchange [OPTIONS] \u003cWATCH\u003e... [-- [COMMAND]...]\n    \n    Arguments:\n      \u003cWATCH\u003e...    List paths to watch\n      [COMMAND]...  Command to run\n    \n    Options:\n      -d, --duration \u003cDURATION\u003e  Scan duration in miliseconds [default: 500]\n      -r, --recursive            Watch in Recursive Mode\n      -a, --async                Run commands on Async\n      -t, --template \u003cTEMPLATE\u003e  List paths to watch [default: \"Change Detected: {path}\"]\n      -h, --help                 Print help\n\n\n# Inspiration\nThe need to have something run on file change is everywhere, and I had been using a shell script for latex files to compile when the file changed. But since I might need it for lots of other stuffs too, like the graphviz example here. I thought of making a program to specialize in it. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatreyagaurav%2Fonchange","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatreyagaurav%2Fonchange","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatreyagaurav%2Fonchange/lists"}