{"id":21605970,"url":"https://github.com/archf/shlib","last_synced_at":"2026-05-15T21:33:38.401Z","repository":{"id":89975075,"uuid":"145618486","full_name":"archf/shlib","owner":"archf","description":"Resuable script template and snippets","archived":false,"fork":false,"pushed_at":"2021-04-15T14:08:18.000Z","size":27,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-29T01:26:07.067Z","etag":null,"topics":["bash","dash","shell","snippets","template"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/archf.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}},"created_at":"2018-08-21T20:53:58.000Z","updated_at":"2022-03-20T03:42:46.000Z","dependencies_parsed_at":"2023-06-18T16:52:46.783Z","dependency_job_id":null,"html_url":"https://github.com/archf/shlib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/archf/shlib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archf%2Fshlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archf%2Fshlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archf%2Fshlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archf%2Fshlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/archf","download_url":"https://codeload.github.com/archf/shlib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/archf%2Fshlib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33080777,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T20:25:35.270Z","status":"ssl_error","status_checked_at":"2026-05-15T20:25:34.732Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["bash","dash","shell","snippets","template"],"created_at":"2024-11-24T20:18:24.163Z","updated_at":"2026-05-15T21:33:38.380Z","avatar_url":"https://github.com/archf.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# shlib\n\nReusable shell script boilerplate and shell snippets.\n\n## Features \u0026 Guidelines\n\n- All template provided functions syntax are meant to be as portable as possible.\n  To run a `dash` script simply edit the shebang.\n- Pure shell implementation preferred over usage of external programs ( `date`,\n    `readlink`,...) to avoid extra I/O operations and scheduling of OS processes.\n- Provided more than needed. Need less? Just delete what you don't want.\n\n## Conventions\n\n- External environmental variables that may influence the script behavior are\nall capital case. E.g.:\n  - `VERBOSE`\n  - `DEBUG`\n  - `FORCE`\n  - ...\n- Function names are prefixed by a single underscore '`_`' unless they are meant for public consumption\n  and/or are relevant public entry points. (e.g.: `function _my_private_func () {true;}`)\n- Variables names are prefixed by a double underscore '`__`'  unless the scope is function\n  local. ( e.g.: `__my_script_var='foo'`).\n\n- Safety first spirit. Shell options below are enabled by default when they\n  are available.\n\n```\n# Exit immediately on error. Same as '-e'. Use of '|| true' or '|| :' may be\n# handy. We purposely avoid setting this in interactive shell. We use posix\n# compatible case statement for portability because in simple '[' tests the\n# *i* pattern would expand filenames in pwd instead...\ncase \"$-\" in\n  *i*) :;;\n  *) [ -n \"${ZSH_VERSION}\" ] \u0026\u0026 setopt ERR_EXIT || set -o errexit;;\nesac\n\n# Any trap on ERR is inherited by any functions or subshells. Available on bash\n# only.\n[ -n \"${BASH_VERSION:-}\" ] \u0026\u0026 set -o errtrace || true\n\n# Return value of a pipeline is the one of right most cmd with non-zero exit\n# code. Available on bash only.\n[ -n \"${BASH_VERSION:-}\" ] \u0026\u0026 set -o pipefail || true\n\n# Errors on unset variables and parameters. Same as '-u'. Use '${VAR:-}'.\nset -o nounset\n```\n\n- Provide useful attributes as variables akin to python's one:\n  - `__file__` -\u003e Fully qualified script path after symlink resolution.\n  - `__path__` -\u003e Script directory derived from `__file__`.\n  - `__name__` -\u003e Program name based on `__file__` basename.\n  - `__version__` -\u003e Script version string. Will be read in file\n  `${__path__}/${__version__}` if it exists. Alternatively, you may define it\n  directly in your script.\n  - `__doc__` -\u003e Script usage script. Displayed by the `_usage` function.\n\n## Shell snippets\n\nCopy paste in your script useful shell snippets packaged as functions and\ngrouped by category in the `lib` directory of this repository.\n\n## Usage\n\n```\nVERBOSE=7 ./template.sh -v 7\n```\n\n### Method #1: Use the standalone script\n\n1. Copy and rename the `shlib_template_standalone.sh` script.\n2. Customize it deleting what you don't need.\n3. Code what you need.\n\n### Method 2: Source it from your script.\n\n1. Copy and rename `shlib_template.sh`. Doing that the `shlib` library must be\n   available to be sourced. That methode makes it easier to maintain\n   your scripts if you have many in case of eventual `shlib` library update.\n2. Customize it deleting what you don't need.\n3. Code what you need.\n\nThis is most probably the way to go to in order to break subcommands in\ndistinct files.\n\n## Todo\n\n- better STDERR color toggling support\n- trap handling functions template\n- namespacing support (sourcing multiple scripts)\n- add systemd unit file template for easy daemonizing\n- add systemd timer file template for easy cron jobs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchf%2Fshlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farchf%2Fshlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farchf%2Fshlib/lists"}