Skip to content

riza/cocaine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cocaine logo

cocaine

Keep your machine awake. Like caffeinate, but with more kick.
A tiny Rust CLI that prevents your computer from sleeping. Works on macOS, Linux and Windows.

Release Rust Report Card

Install

Homebrew (macOS/Linux)

brew install riza/tap/cocaine

From source

cargo install --git https://github.com/riza/cocaine.git

From release

Download the latest binary for your platform from Releases, extract, and put it in your $PATH.

Platform Binary
macOS (Apple Silicon) cocaine-aarch64-apple-darwin.tar.gz
macOS (Intel) cocaine-x86_64-apple-darwin.tar.gz
Linux (x86_64) cocaine-x86_64-unknown-linux-gnu.tar.gz
Linux (ARM64) cocaine-aarch64-unknown-linux-gnu.tar.gz
Windows (x86_64) cocaine-x86_64-pc-windows-msvc.zip

Usage

cocaine [OPTIONS] [COMMAND]...

By default (no flags), cocaine prevents idle system sleep indefinitely until you hit Ctrl+C.

Options

Flag Long Description
-d --display Prevent the display from sleeping
-i --idle Prevent the system from idle sleeping
-s --system Prevent the system from sleeping entirely
-t --timeout <SECS> Stop after N seconds (default: 0 = indefinite)

Daemon mode

cocaine can run as a background daemon, keeping your machine awake without occupying a terminal.

# Start the daemon (default: prevent idle sleep)
cocaine daemon start

# Start with display-on and a 2-hour timeout
cocaine daemon start -d -t 7200

# Check if the daemon is running
cocaine daemon status

# Stop the daemon
cocaine daemon stop

The daemon writes a PID file to ~/.local/share/cocaine/cocaine.pid (Linux/macOS) or %APPDATA%\cocaine\cocaine.pid (Windows).

Examples

# Prevent idle sleep until Ctrl+C
cocaine

# Keep the display on
cocaine -d

# Keep the display on for 1 hour
cocaine -d -t 3600

# Prevent all sleep types
cocaine -d -i -s

# Keep awake while a command runs
cocaine -d -- make build

# Keep awake during a long download
cocaine -s -- curl -O https://example.com/big-file.tar.gz

How it works

cocaine uses native OS APIs on each platform to prevent sleep:

Platform API Mechanism
macOS IOKit IOPMAssertionCreateWithName Creates power assertions that are released on exit
Linux systemd-logind D-Bus Inhibit Holds an inhibit file descriptor via org.freedesktop.login1
Windows SetThreadExecutionState Sets ES_SYSTEM_REQUIRED / ES_DISPLAY_REQUIRED flags

Assertions / inhibitors are automatically released when cocaine exits -- whether that's through Ctrl+C, a timeout, or a child command finishing.

Verifying

# macOS
pmset -g assertions

# Linux
systemd-inhibit --list

# Windows (PowerShell)
powercfg /requests

License

MIT

About

A CLI tool to keep your computer awake. Works on macOS, Linux, Windows.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages