{"id":20438200,"url":"https://github.com/kiprasmel/cputils","last_synced_at":"2025-03-05T07:20:37.878Z","repository":{"id":64974957,"uuid":"312564882","full_name":"kiprasmel/cputils","owner":"kiprasmel","description":"CLI utilities for competitive programming (mostly making C++ feel interpreted instead of compiled)","archived":false,"fork":false,"pushed_at":"2024-02-06T22:13:25.000Z","size":145,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-15T19:54:26.670Z","etag":null,"topics":["cli","competitive-programming","cpp","utilities","utils"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/kiprasmel.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,"publiccode":null,"codemeta":null}},"created_at":"2020-11-13T12:06:06.000Z","updated_at":"2023-03-04T04:48:42.000Z","dependencies_parsed_at":"2025-01-18T11:32:23.336Z","dependency_job_id":null,"html_url":"https://github.com/kiprasmel/cputils","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiprasmel%2Fcputils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiprasmel%2Fcputils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiprasmel%2Fcputils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiprasmel%2Fcputils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kiprasmel","download_url":"https://codeload.github.com/kiprasmel/cputils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241983319,"owners_count":20052655,"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","competitive-programming","cpp","utilities","utils"],"created_at":"2024-11-15T09:09:45.298Z","updated_at":"2025-03-05T07:20:37.853Z","avatar_url":"https://github.com/kiprasmel.png","language":"Shell","readme":"# cputils\n\n\u003c!-- CLI utilities for competitive programmers --\u003e\n\u003cu\u003ec\u003c/u\u003eompetitive \u003cu\u003ep\u003c/u\u003erogramming \u003cu\u003eutils\u003c/u\u003e\n\n## Installation\n\n[![](https://github.com/kiprasmel/cputils/workflows/full-setup/badge.svg)](https://github.com/kiprasmel/cputils/actions?query=workflow:full-setup+branch:master)\n\n```sh\ngit clone https://github.com/kiprasmel/cputils.git\n# or:  git clone git@github.com:kiprasmel/cputils.git\n\ncd cputils\n\nmake\n\n# env vars:\n# PREFIX: where to put /bin, /include folders into.\n#         default /usr/local/\n#\n# INSTALL_DEBUGLIB: whether to install debug lib to make example work.\n#                   https://github.com/kiprasmel/debug.h\n\n# linux, intel mac:\nPREFIX=/usr/local    sudo make install\n\n# M1 mac:\nPREFIX=/opt/homebrew sudo make install\n```\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\nRuntime dependencies\n\u003c/summary\u003e\n\n- g++ (soon the compiler will be configurable -- choose yours)\n- xargs\n- (optional) `xclip` / `pbpaste` / `xsel` / `/dev/clipboard` or any other tool to paste from clipboard\n- (optional) GNU time (`/usr/bin/env time`) for printing not only time, but also memory usage\n \n\u003c/details\u003e\n\n## Features\n\n- create files from your custom templates\n\t- auto-open created file with your editor\n- run instantly without recompilation if nothing changed\n- forward arguments to the compiler\n\t- shell aliasing fully supported\n- see memory usage\n- more to come @ the [Roadmap](https://github.com/kiprasmel/cputils/issues/1)\n\nEverything above is customizable — see [#Usage](#Usage) and [#Enhancements](#Enhancements) below.\n\n## Usage\n\n### Quickstart\n\n```sh\ncputils new a.cpp\ncputils run a.cpp\n```\n\n### Complete info\n\n```sh\n$ cputils\n\nusage:\n\ncputils COMMAND [COMMAND_ARGS...]\n\nCOMMAND:\n        new        - new file from template\n        run        - run file\n        cfgen      - codeforces generator from template\n        config     - edit the configuration file\n    \n\nsee individual commands for details\n\n```\n\n[![](https://github.com/kiprasmel/cputils/workflows/cputils-new/badge.svg)](https://github.com/kiprasmel/cputils/actions?query=workflow:cputils-new+branch:master)\n\n```sh\n$ cputils new\n\nusage:\n\ncputils-new NEW_FILENAME.EXTENSION [OPTIONS]\n\n  where\n    NEW_FILENAME      = the name of a new file\n  \n    EXTENSION         = the file extension (not limited to \"cpp\" -\n                                            you can create templates for various langs)\n\n    -t TEMPLATE_ID    = use template by id (template.TEMPLATE_ID.EXTENSION)\n                        default: unset, thus \"template.cpp\"\n\n                        templates should be added to the config directory\n                        (\"$HOME/.config/cputils\"),\n                        named \"template.TEMPLATE_ID.EXTENSION\",\n                        e.g.  \"template.t.cpp\" (maybe a regular template with test cases?),\n                              \"template.py\"    (default for python files),\n                              \"template.js\"    (default for javascript files) etc.\n  \n    -y                = non-interactive (do not open file with editor etc.)\n                        default: false\n\n    -i                = interactive (overrides previous `-y`)\n                        default: true\n                        will open created file with editor\n                        if editor specified and enabled in the config\n\n    -h, --help        = show this\n\n\n  examples:\n    cputils-new a.cpp               # create file a.cpp from default template.cpp\n    cputils-new b.cpp -t t          # create file b.cpp from         template.t.cpp\n    cputils-new c.py                # create file c.py  from default template.py\n    cputils-new d.js                # create file d.js  from default template.js\n\n```\n\n[![](https://github.com/kiprasmel/cputils/workflows/cputils-run/badge.svg)](https://github.com/kiprasmel/cputils/actions?query=workflow:cputils-run+branch:master)\n\n```sh\n$ cputils run\n\nusage:\n\ncputils-run FILENAME.cpp [OPTIONS]... [-- EXTRA_COMPILER_ARGS]\n\n  where\n    FILENAME.cpp                = source file you want to run\n\n    -f [INPUT_FILE]             = read input from (default) INPUT_FILE\n                                  instead of reading from stdin\n\n    INPUT_FILE                  = specify your own INPUT_FILE instead of the default\n                                  default: FILENAME.cpp.txt (configurable)\n\n    -c                          = read input from clipboard\n\n    -r, --recompile             = force recompilation no matter if the file hash\n                                  matches previously compiled file's hash\n                                  default: false\n\n                                  note: this does not matter if the user has not\n                                  provided a hashing function in their config.\n                                  see README for more info\n\n    -e, --edit                  = edit the INPUT_FILE with configured editor\n    \n    -a \"EXTRA_COMPILER_ARGS\"    = pass arguments to the compiler (quotes necessary),\n                                  can be used multiple times.\n\n                                  hint: set custom #define's from here\n                                  or override default settings etc.\n                                  very useful for shell aliases / functions\n                                  (see the examples below)\n\n    -- EXTRA_COMPILER_ARGS      = same as `-a`, just for extra convenience\n                                  (no quotes needed, must be used at most once,\n                                  since `--` will stop argument parsing\n                                  and will forward everything to the compiler)\n\n    -h                          = see this\n\n    --help                      = see this + examples (even if hidden via config)\n\n\nexamples:\n\n  simple:\n    cputils-run a.cpp                # reads input from stdin (if a.cpp needs it)\n    cputils-run a.cpp -c             # reads input from clipboard\n    cputils-run a.cpp -f             # reads input from file `a.cpp.txt`\n    cputils-run a.cpp -f in          # reads input from file `in`\n    cputils-run a.cpp \u003c  in          # reads input from stdin redirect (from file `in`)\n    cat in | cputils-run a.cpp       # reads input from stdin pipe     (from file `in`)\n\n  with args to the compiler:\n    cputils-run a.cpp          -- -DDEBUG -std=c++98 -Wextra -Wpedantic\n    cputils-run a.cpp -f       -- -DDEBUG -std=c++11 -Wl,--stack,$((2 ** 28)) \n    cputils-run a.cpp -f in    -- -DEVAL  -std=c++14 -O2\n\tcputils-run a.cpp          --         -std=c++17 -O3 \u003c in\n    cat in | cputils-run a.cpp --         -std=c++20 -O3\n\n  using alias functions:\n\n  .bashrc / .zshrc / etc:\n  \n  ```sh\n  xd() { cputils-run -a \"-DDEBUG\" $* }\n  ...\n\n  and replace `cputils-run a.cpp`\n  with        `xd a.cpp`\n\n```\n\n## Enhancements\n\n- for extra speed create an alias in i.e. `.bashrc` / `.zshrc` (replace `x` with whatever alias you want):\n\n```sh\nx()  { cputils $* }\nxn() { cputils new $* }\nxr() { cputils run $* }\nxd() { cputils run -a \"-DDEBUG\" $* }\nxp() { cputils run -a \"-DEVAL\"  $* }\n```\n\n- enable reading input from clipboard with `cputils run -c`:\n\nedit the config file `$HOME/.config/cputils/cputils.config.bash` -- inside the `paste_from_clipboard` function provide a way to paste input from your clipboard if it's not already handled:\n\n```bash\n# cputils.config.bash\n\n# ...\n\npaste_from_clipboard() {\n\tif   command -v xclip   \u0026\u003e/dev/null; then printf \"$(xclip -selection clipboard -o)\"\n\telif command -v pbpaste \u0026\u003e/dev/null; then printf \"$(pbpaste)\"\n\telif command -v xsel    \u0026\u003e/dev/null; then printf \"$(xsel --clipboard)\"\n\telif ls /dev/clipboard  \u0026\u003e/dev/null; then printf \"$(cat /dev/clipboard)\"\n\t# add your's!\n\telse return 1\n\tfi\n}\nexport -f paste_from_clipboard\n\n# ...\n```\n\n\n- auto-open a file created by `cputils new`:\n\nedit the config file `$HOME/.config/cputils/cputils.config.bash` -- inside the `open_with_editor` function provide a way to open the file `\"$1\"` with your editor:\n\n```bash\n# cputils.config.bash\n\n# ...\n\nopen_with_editor() {\n\treturn 1 # comment out this line and choose your editor if you want to\n\n\t# vim \"$1\"\n\t# code \"$1\"\n\t# emacs \"$1\"\n\t# geany \"$1\" \u0026\n}\nexport -f open_with_editor\n\n# ...\n```\n\n- provide a source file hashing function to avoid recompilation if no changes occured\n\nedit the config file `$HOME/.config/cputils/cputils.config.bash` -- inside the `create_hash` function provide a way to hash file `\"$1\"`:\n\n```bash\n# cputils.config.bash\n\n# ...\n\ncreate_hash() {\n\treturn 1  # comment out this line to enable and choose the appropriate method\n\t\n\t# openssl dgst -sha256 -r \"$1\" | awk '{ print $1 }'\n\t# sha256sum \"$1\" | awk '{ print $1 }'\n}\nexport -f create_hash\n\n# ...\n\n```\n\n\u003e note - we handle other side effects ourselves (`EXTRA_COMPILER_ARGS`, `CPP_COMPILER_DEFAULT_ARGS` and (hopefully) anything else that should invalidate the cache). Create an issue if we missed something\n\n- customize file templates for `cputils new`:\n\n```sh\ncd \"$HOME/.config/cputils/\"\n```\n\nand overwrite the default `template.cpp`;\n\nadditionally - create other templates named `template.TEMPLATE_ID.cpp` and use them via\n\n```sh\ncputils new file.cpp -t TEMPLATE_ID\n```\n\nyou can even have templates for other languages too - just use a different file extension (like `template.py`, `template.js` etc.)\n\n- other configurations\n\nexplore the config file `$HOME/.config/cputils/cputils.config.bash`. Some settings include:\n\n- `INPUT_CACHE_FILE_EXTENSION`\n- `HIDE_EXAMPLES`\n- `CPP_COMPILER_DEFAULT_ARGS`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiprasmel%2Fcputils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkiprasmel%2Fcputils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiprasmel%2Fcputils/lists"}