{"id":15687151,"url":"https://github.com/64kramsystem/simple_scripting","last_synced_at":"2025-05-07T19:09:41.615Z","repository":{"id":47873838,"uuid":"95044935","full_name":"64kramsystem/simple_scripting","owner":"64kramsystem","description":"Ruby library for simplifying some typical scripting functionalities. ","archived":false,"fork":false,"pushed_at":"2024-12-25T18:49:37.000Z","size":114,"stargazers_count":9,"open_issues_count":7,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T19:08:56.600Z","etag":null,"topics":["linux","shell-scripts","sysadmin"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/64kramsystem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2017-06-21T20:49:31.000Z","updated_at":"2024-12-25T18:49:41.000Z","dependencies_parsed_at":"2025-05-07T19:08:59.240Z","dependency_job_id":null,"html_url":"https://github.com/64kramsystem/simple_scripting","commit_stats":null,"previous_names":["saveriomiroddi/simple_scripting"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fsimple_scripting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fsimple_scripting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fsimple_scripting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/64kramsystem%2Fsimple_scripting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/64kramsystem","download_url":"https://codeload.github.com/64kramsystem/simple_scripting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252940934,"owners_count":21828769,"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":["linux","shell-scripts","sysadmin"],"created_at":"2024-10-03T17:44:14.473Z","updated_at":"2025-05-07T19:09:41.553Z","avatar_url":"https://github.com/64kramsystem.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gem Version][GV img]](https://rubygems.org/gems/simple_scripting)\n[![Build Status][BS img]](https://travis-ci.org/saveriomiroddi/simple_scripting)\n[![Code Climate][CC img]](https://codeclimate.com/github/saveriomiroddi/simple_scripting)\n[![Coverage Status][CS img]](https://coveralls.io/r/saveriomiroddi/simple_scripting)\n\n# SimpleScripting\n\n`SimpleScripting` is a library composed of three modules (`TabCompletion`, `Argv` and `Configuration`) that simplify three common scripting tasks:\n\n- writing autocompletion scripts\n- implementing the commandline options parsing (and the related help)\n- loading and decoding the configuration for the script/application\n\n`SimpleScripting` is an interesting (and useful) exercise in design, aimed at finding the simplest and most expressive data/structures that accomplish the given task(s). For this reason, the library can be useful for people who frequently write small scripts (eg. devops or nerds).\n\n## SimpleScripting::TabCompletion\n\n`TabCompletion` makes trivial to define tab-completion for terminal commands on Linux/Mac systems; it's so easy that an example is much simpler than an explanation.\n\n`TabCompletion` supports Bash, and Zsh (with `bashcompinit`).\n\n### Example\n\nSuppose we have the command:\n\n```sh\nopen_project [-e|--with-editor EDITOR] \u003cproject_name\u003e\n```\n\nWe want to add tab completion both for the option and the project name. Easy!!\n\nInstall the gem (`simple_scripting`), then create this class (`/my/completion_scripts/open_project_completion.rb`):\n\n```ruby\n#!/usr/bin/env ruby\n\nrequire 'simple_scripting/tab_completion'\n\nclass OpenProjectTabCompletion\n  SYSTEM_EDITORS = `update-alternatives --list editor`.split(\"\\n\").map { |filename| File.basename(filename) }\n\n  def with_editor(prefix, suffix, context)\n    SYSTEM_EDITORS.grep /^#{prefix}/\n  end\n\n  def project_name(prefix, suffix, context)\n    Dir[\"/my/home/my_projects/#{prefix}*\"]\n  end\nend\n\nif __FILE__ == $PROGRAM_NAME\n  completion_definition = [\n    [\"-e\", \"--with-editor EDITOR\"],\n    'project_name'\n  ]\n\n  SimpleScripting::TabCompletion.new(completion_definition).complete(OpenProjectTabCompletion.new)\nend\n```\n\nthen chmod and register it:\n\n```sh\n$ chmod +x /my/completion_scripts/open_project_completion.rb\n$ complete -C /my/completion_scripts/open_project_completion.rb -o default open_project\n```\n\nDone!\n\nNow type the following, and get:\n\n```sh\n$ open_project g\u003ctab\u003e           # lists: \"geet\", \"gitlab-ce\", \"gnome-terminal\"\n$ open_project --with-editor v  # lists: \"vim.basic\", \"vim.tiny\"\n$ open_project --wi\u003ctab\u003e        # autocompletes \"--with-editor\"; this is built-in!\n```\n\nHappy completion!\n\n### Zsh\n\n`TabCompletion` on Zsh requires `bashcompinit`; add the following to your `~/.zshrc`:\n\n```sh\nautoload bashcompinit\nbashcompinit\n```\n\nNote that a **recent version of Zsh is required**; the stock Ubuntu 16.04 version (5.1.1-1ubuntu2.2) has bug that breaks bash tab completion.\n\n### More complex use cases\n\nFor a description of the more complex use cases, including edge cases and error handling, see the [wiki](https://github.com/saveriomiroddi/simple_scripting/wiki/SimpleScripting::TabCompletion-Guide).\n\n## SimpleScripting::Argv\n\n`Argv` is a module which acts as frontend to the standard Option Parser library (`optparse`), giving a very convenient format for specifying the arguments. `Argv` also generates the help.\n\nThis is a definition example:\n\n    require 'simple_scripting/argv'\n\n    result = SimpleScripting::Argv.decode(\n      ['-s', '--only-scheduled-days',     'Only print scheduled days'                           ],\n      ['-d', '--print-defaults TEMPLATE', 'Print the default activities from the named template'],\n      'schedule',\n      '[weeks]',\n      long_help: 'This is the long help! It can span multiple lines.'\n    ) || exit\n\nwhich:\n\n- optionally accepts the `-s`/`--only-scheduled-days` switch, interpreting it as boolean,\n- optionally accepts the `-d`/`--print-defaults` switch, interpreting it as string,\n- requires the `schedule` argument,\n- optionally accepts the `weeks` argument,\n- automatically adds the `-h` and `--help` switches,\n- prints all the options and the long help if the help is invoked,\n- exits with a descriptive error if invalid parameters are passed.\n\nThis is a sample result:\n\n    {\n      only_scheduled_days: true,\n      print_defaults:      'my_defaults',\n      schedule:            'schedule.txt',\n      weeks:               '3',\n    }\n\nThis is the corresponding help:\n\n    Usage: tmpfile [options] \u003cschedule\u003e [\u003cweeks\u003e]\n        -s, --only-scheduled-days        Only print scheduled days\n        -d, --print-defaults TEMPLATE    Print the default activities from the named template\n        -h, --help                       Help\n\n    This is the long help! It can span multiple lines.\n\nCommands are also supported (with unlimited depth), by using a hash:\n\n    commands, result = SimpleScripting::Argv.decode(\n      'pr' =\u003e {\n        'create' =\u003e [\n          'title',\n          'description',\n          long_help: 'This is the create PR command help.'\n        ]\n      },\n      'issues' =\u003e {\n        'list' =\u003e []\n      }\n    ) || exit\n\nFor the guide, see the [wiki page](https://github.com/saveriomiroddi/simple_scripting/wiki/SimpleScripting::Argv-Guide).\n\n## SimpleScripting::Configuration\n\n`Configuration` is a module which acts as frontend to the ParseConfig gem (`parseconfig`), giving compact access to the configuration and its values, and adding a few helpers for common tasks.\n\nSay one writes a script (`foo_my_bar.rb`), with a corresponding (`$HOME/.foo_my_bar`) configuration, which contains:\n\n    some_relative_file_path=foo\n    some_absolute_file_path=/path/to/bar\n    multiple_paths=foo:/path/to/bar\n    my_password=uTxllKRD2S+IH92oi30luwu0JIqp7kKA\n\n    [a_group]\n    group_key=baz\n\nThis is the workflow and functionality offered by `Configuration`:\n\n    require 'simple_scripting/configuration'\n\n    # Picks up automatically the configuration file name, based on the calling program\n    #\n    configuration = SimpleScripting::Configuration.load(passwords_key: 'encryption_key')\n\n    configuration.some_relative_file_path.full_path # '$HOME/foo'\n    configuration.some_absolute_file_path           # '/path/to/bar'\n    configuration.some_absolute_file_path.full_path # '/path/to/bar' (recognized as absolute)\n    configuration.multiple_paths.full_paths         # ['$HOME/foo', '/path/to/bar']\n\n    configuration.my_password.decrypted             # 'encrypted_value'\n\n    configuration.a_group.group_key                 # 'baz'; also supports #full_path and #decrypted\n\n### Encryption note\n\nThe purpose of encryption in this library is just to avoid displaying passwords in plaintext; it's not considered safe against attacks.\n\n## Help\n\nSee the [wiki](https://github.com/saveriomiroddi/simple_scripting/wiki) for additional help.\n\n[GV img]: https://badge.fury.io/rb/simple_scripting.png\n[BS img]: https://travis-ci.org/saveriomiroddi/simple_scripting.svg?branch=master\n[CC img]: https://codeclimate.com/github/saveriomiroddi/simple_scripting.png\n[CS img]: https://coveralls.io/repos/saveriomiroddi/simple_scripting/badge.png?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F64kramsystem%2Fsimple_scripting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F64kramsystem%2Fsimple_scripting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F64kramsystem%2Fsimple_scripting/lists"}