{"id":27169406,"url":"https://github.com/samdmarshall/battery-level","last_synced_at":"2026-06-14T21:32:10.224Z","repository":{"id":142005682,"uuid":"80322564","full_name":"samdmarshall/battery-level","owner":"samdmarshall","description":"access to the current battery % on OS X machines","archived":false,"fork":false,"pushed_at":"2020-06-17T06:07:24.000Z","size":64,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-29T09:34:55.901Z","etag":null,"topics":["battery","battery-info","battery-level","macos","macosx","osx"],"latest_commit_sha":null,"homepage":null,"language":"Nim","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/samdmarshall.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-01-29T01:24:24.000Z","updated_at":"2020-06-17T06:07:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"48907f5b-4606-45f0-8c3a-45ac4e6daf3e","html_url":"https://github.com/samdmarshall/battery-level","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/samdmarshall/battery-level","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdmarshall%2Fbattery-level","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdmarshall%2Fbattery-level/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdmarshall%2Fbattery-level/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdmarshall%2Fbattery-level/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samdmarshall","download_url":"https://codeload.github.com/samdmarshall/battery-level/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samdmarshall%2Fbattery-level/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34339194,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["battery","battery-info","battery-level","macos","macosx","osx"],"created_at":"2025-04-09T06:36:07.222Z","updated_at":"2026-06-14T21:32:10.211Z","avatar_url":"https://github.com/samdmarshall.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"battery-level\r\n=============\r\n\r\nThis utility reports on the remaining battery percentage and charging status of\r\nmacOS-based computers. It is intended to be incorprated into shell prompts,\r\nterminal-based editor status-lines, scripts, etc.\r\n\r\nUsage\r\n-----\r\n\r\nMacs can have multiple power sources (though it's rare). Use the `--list` flag\r\nto tell you how many sources you have, and then `--index:\u003cnum\u003e` to select the\r\nsource you want. Note that it is a zero-based array, so if you have one source,\r\nthen use `--index:0`. The default output is the percentage of battery remaining.\r\n\r\n    $ battery-level --list\r\n    1\r\n    $ battery-level --index:0\r\n    48\r\n\r\nThere is also a handy `--default` flag to automatically select the first source.\r\n\r\n    $ battery-level --default\r\n    48\r\n\r\nYou can pass the flag `--charging`, which will return `1` if the battery is\r\ncurrently charging, and `0` if it is not. Cases where it will return `0` include\r\nwhen the computer is not plugged in, as well as when it is plugged in but the\r\nbattery is full.\r\n\r\nBoth of these result in the same output:\r\n\r\n    $ battery-level --index:0 --charging\r\n    0\r\n    $ battery-level --default --charging\r\n    0\r\n\r\nExample Shell Integration\r\n-------------------------\r\n\r\nYou can put the following in your `~/.bashrc`\r\n\r\n    prompt_battery() {\r\n      charge=$(battery-level --default --charging)\r\n      if [[ $charge -eq 1 ]]; then\r\n        echo '⚡️'\r\n      fi\r\n    }\r\n    \r\n    export PS1=\"\\$(prompt_battery) \\d \\@ \\w $ \"\r\n\r\nAnd, if the battery is charging, your prompt will look like\r\n\r\n    ⚡️  Mon Feb 27 10:18 AM ~/Development/battery-level $\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamdmarshall%2Fbattery-level","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamdmarshall%2Fbattery-level","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamdmarshall%2Fbattery-level/lists"}