Skip to content

TUI session manager for NVIDIA Optimus laptops on Linux

License

Notifications You must be signed in to change notification settings

karsterr/envytui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

envytui

TUI session manager for NVIDIA Optimus laptops on Linux

envytui is a terminal-based session manager that runs at login and lets you switch between GPU and power profiles before your desktop starts. It wraps envycontrol and power-profiles-daemon behind a clean gum-powered interface.

Features

  • Three GPU profiles -- Battery (iGPU only), Performance (hybrid), and Max (dGPU only)
  • Auto-detects your hardware -- GPU names, AC adapter, and current status shown in a dashboard
  • Confirmation before reboot -- no accidental reboots
  • Spinner feedback -- visual progress while settings are applied
  • Works on any NVIDIA Optimus laptop -- Intel or AMD iGPU paired with an NVIDIA dGPU
  • Distro-aware installer -- detects pacman, apt, dnf, and zypper
  • Supports bash and zsh login hooks
  • ShellCheck CI -- all scripts are linted on every push and PR

Supported Hardware

Any Linux laptop with an NVIDIA Optimus setup:

iGPU dGPU Supported
AMD Radeon (Ryzen) NVIDIA GeForce Yes
Intel UHD/Iris NVIDIA GeForce Yes
AMD Radeon AMD Radeon (discrete) No
Intel Intel Arc No

envytui delegates all GPU switching to envycontrol, which only supports NVIDIA Optimus configurations.

Requirements

  • gum -- TUI components
  • envycontrol -- GPU mode switching
  • powerprofilesctl (power-profiles-daemon) -- power profile management
  • lspci (pciutils) -- GPU detection
  • sudo access -- required for envycontrol and reboot

Installation

git clone https://github.com/karsterr/envytui.git
cd envytui
chmod +x install.sh
./install.sh

The installer will:

  1. Check that all dependencies are installed (with distro-specific install hints)
  2. Copy scripts to /usr/local/share/envytui
  3. Create a symlink at /usr/local/bin/envytui
  4. Print login hook instructions for your shell

Usage

Manual launch

envytui

Auto-launch at login (recommended)

Add the following to your shell's login profile (~/.zprofile for zsh, ~/.bash_profile for bash):

# --- envytui: session manager hook ---
if [[ $(tty) == /dev/tty1 && $- == *i* ]]; then
    envytui
fi
# --- end envytui ---

This ensures envytui only runs on TTY1 in interactive shells. SSH, SCP, and non-interactive sessions are unaffected.

Profiles

Profile GPU Mode Power Profile AC Required
Battery Integrated (iGPU only, dGPU off) power-saver No
Performance Hybrid (iGPU + dGPU) performance Yes
Max NVIDIA only (dGPU only) performance Yes
Skip No changes No changes No

How It Works

  1. Dashboard -- On launch, envytui detects your GPUs, current mode, power profile, and AC status, and displays them in a status panel.
  2. Selection -- You pick a profile from the list (or skip).
  3. Authorization -- sudo is requested only when needed.
  4. Apply -- GPU mode is set via envycontrol, power profile via powerprofilesctl, with spinner feedback.
  5. Confirm -- You're asked to confirm before rebooting.
  6. Reboot -- A 5-second countdown with Ctrl+C escape hatch. State is written so the next boot can confirm success.
  7. Validation -- On next login, envytui reads the state file, confirms the mode was applied, and clears the state.

Project Structure

envytui/
  envytui.sh          # Main dispatcher (phases: validate, dashboard, select, action, reboot)
  lib/
    gpu.sh            # GPU detection (lspci) and envycontrol wrapper
    power.sh          # Power profile management and AC adapter detection
    state.sh          # State file read/write/clear
  install.sh          # Installer with dependency checks
  .zprofile           # Example login hook
  .github/
    workflows/
      shellcheck.yml  # CI: ShellCheck linting
    ISSUE_TEMPLATE/
      bug_report.md
      feature_request.md
    PULL_REQUEST_TEMPLATE.md

FAQ

What happens if I select "Skip"?

Nothing changes. envytui exits cleanly and your desktop session starts as normal.

Why does it require a reboot?

envycontrol modifies Xorg/Wayland configuration files and kernel module blacklists that only take effect on the next boot. This is a limitation of how NVIDIA Optimus switching works on Linux, not an envytui design choice.

Does this work on Wayland?

Yes. envycontrol supports both Xorg and Wayland. The GPU mode switching is compositor-agnostic.

Can I use this without the login hook?

Yes. Just run envytui manually from any TTY or terminal whenever you want to switch profiles. The login hook is optional.

What if my AC adapter isn't detected?

envytui scans /sys/class/power_supply/*/type for entries with type Mains. If no AC adapter is found, a warning is printed to stderr and the AC power check is skipped (performance/max modes will still be available). If detection fails on your hardware, please open an issue with the output of ls /sys/class/power_supply/ and cat /sys/class/power_supply/*/type.

Can I add custom profiles?

Not currently. envytui exposes the three modes that envycontrol supports (integrated, hybrid, nvidia) with sensible power profile pairings. If you need different combinations, you can modify the gpu_apply_profile and power_apply_profile functions in lib/gpu.sh and lib/power.sh.

Does it work on desktop PCs?

No. envytui is designed for laptops with NVIDIA Optimus (dual-GPU) setups. Desktop PCs with a single GPU have no need for GPU mode switching.

Troubleshooting

"Could not find Nvidia GPU" warning

This is expected when switching modes while in integrated mode. The NVIDIA GPU is powered off and invisible to the PCI bus. envycontrol still writes the configuration files, and the change will take effect after reboot. This is a warning, not an error.

envycontrol command not found

Install envycontrol:

AC power detection not working

Check what your system names the AC adapter:

ls /sys/class/power_supply/
cat /sys/class/power_supply/*/type

If no entry has type Mains, your kernel may not expose AC status through sysfs. Open an issue with this output.

Profile not applying after reboot

  1. Check the state file: cat ~/.config/envytui/state
  2. Verify envycontrol applied the mode: envycontrol --query
  3. Check if the state was PENDING (indicates reboot didn't complete) or READY (indicates envytui didn't run on next boot -- check your login hook).

Permission denied errors

envytui needs sudo for envycontrol, powerprofilesctl, and reboot. Make sure your user is in the sudo / wheel group and can run sudo -v successfully.

ShellCheck warnings in my fork

Run ShellCheck locally before pushing:

shellcheck --severity=warning envytui.sh lib/*.sh install.sh

Contributing

See CONTRIBUTING.md for guidelines on reporting bugs, suggesting features, and submitting pull requests.

License

This project is licensed under the GNU General Public License v3.0. See LICENSE for details.

Languages