{"id":18136270,"url":"https://github.com/purarue/havecmd","last_synced_at":"2026-02-09T16:31:48.311Z","repository":{"id":94610203,"uuid":"296639774","full_name":"purarue/havecmd","owner":"purarue","description":"A template for bash scripts, to provide a nicer interface to check for the presence of external commands on the users $PATH","archived":false,"fork":false,"pushed_at":"2024-11-12T03:57:07.000Z","size":30,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-21T21:39:48.631Z","etag":null,"topics":["bash","dependency-manager","scripting","template"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/purarue.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":"2020-09-18T14:11:12.000Z","updated_at":"2024-11-12T03:57:10.000Z","dependencies_parsed_at":"2024-11-12T04:24:54.547Z","dependency_job_id":"2cd4baef-f36b-4baf-b04d-c3790610ab13","html_url":"https://github.com/purarue/havecmd","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/purarue/havecmd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2Fhavecmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2Fhavecmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2Fhavecmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2Fhavecmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/purarue","download_url":"https://codeload.github.com/purarue/havecmd/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2Fhavecmd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29272747,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T13:47:44.167Z","status":"ssl_error","status_checked_at":"2026-02-09T13:47:43.721Z","response_time":56,"last_error":"SSL_read: 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","dependency-manager","scripting","template"],"created_at":"2024-11-01T14:41:35.345Z","updated_at":"2026-02-09T16:31:48.296Z","avatar_url":"https://github.com/purarue.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# havecmd\n\nA template for `bash` scripts, to provide a nicer interface to check for the presence of external commands on the users `$PATH`.\n\nThis isn't a dependency, because the whole point of this script is to check for dependencies. So, this is vendorized; whenever I'm writing a substantial bash script that depends on external commands that may or may not be installed, I copy the `./template` script and start from there.\n\nEasiest way to understand the interface is to read it:\n\n```shell\n#!/usr/bin/env bash\n# Template from https://github.com/purarue/havecmd\n\n# get the name of this script\ndeclare script_name\nscript_name=\"$(basename \"${BASH_SOURCE[0]}\")\"\n\n# function to verify an external command is installed\nhavecmd() {\n\tlocal BINARY ERRMSG\n\tBINARY=\"${1:?Must provide command to check}\"\n\t# the command is on the users $PATH, exit with success\n\tif command -v \"${BINARY}\" \u003e/dev/null 2\u003e\u00261; then\n\t\treturn 0\n\telse\n\t\t# construct error message\n\t\tERRMSG=\"'${script_name}' requires '${BINARY}', could not find that on your \\$PATH\"\n\t\t[[ -n \"$2\" ]] \u0026\u0026 ERRMSG=\"${ERRMSG}. $2\"\n\t\tprintf '%s\\n' \"${ERRMSG}\" 1\u003e\u00262\n\t\treturn 1\n\tfi\n} \u0026\u0026 export -f havecmd\n# export the function, it is defined in any other bash scripts this calls\n\n# If the first argument isn't available on the users $PATH\n# print an error and the second argument (installation instructions), if given\n\n# set the -e flag; this script exits if any of the dependencies aren't satisfied\nset -e\n# Examples\nhavecmd python\nhavecmd fd 'See installation instructions at https://github.com/sharkdp/fd'\nhavecmd wait-for-internet \"Install it with 'cargo install --git https://github.com/purarue/wait-for-internet'\"\nhavecmd pmark\nset +e\n\n# at this point, all dependencies are satisfied\n\nmain() {\n\techo \"ran '${script_name}' with arguments '$*'\"\n\treturn 0\n}\n\nmain \"$@\" || exit $?\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurarue%2Fhavecmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurarue%2Fhavecmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurarue%2Fhavecmd/lists"}