pdinfo: show USB-C Power Delivery charger info on Linux

Command-line script, app-menu/desktop launcher and per-user installer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bsncubedandClaude Opus 5.5 committed 2026-11-13 13:22:40 +11:00
commit 34cd0359ba
5 files changed
+194

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Ben Nicholson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+68
View File
@@ -0,0 +1,68 @@
# pdinfo
See what USB-C Power Delivery (PD) your Linux laptop is actually getting from its charger.
Desktop settings usually only say "plugged in". `pdinfo` reads the kernel's USB Type-C sysfs
interface and shows whether the charger negotiated PD, every voltage/current it offers,
its max wattage, and how fast the battery is charging right now.
```
=== USB-C Charger Info ===
[port0]
Mode: usb_power_delivery
PD supported: yes
PD revision: 2.0
Charger offers:
fixed_supply 5.0 V 3.00 A = 15 W
fixed_supply 9.0 V 3.00 A = 27 W
fixed_supply 15.0 V 3.00 A = 45 W
fixed_supply 20.0 V 2.25 A = 45 W
Charger max: 45 W
Battery BAT0: 33%, Charging, 29.7 W
```
A charger (or cable) that isn't doing PD shows:
```
Mode: 3.0A
PD supported: no
(no PD contract - plain USB-C power, max 15 W)
```
## Install
```sh
git clone https://gitea.apointless.space/bsncubed/pdinfo.git
cd pdinfo
./install.sh
```
This installs, for the current user only (no root needed):
- `~/.local/bin/pdinfo` - run `pdinfo` in a terminal
- a **USB-C Charger Info** entry in your app menu
- the same launcher on your desktop (skip with `./install.sh --no-desktop-icon`).
On GNOME/Ubuntu you may need to right-click it and pick **Allow Launching**.
Uninstall with `./install.sh --uninstall`.
## Requirements
- Linux with the USB Type-C class (`/sys/class/typec`) and USB PD class
(`/sys/class/usb_power_delivery`, kernel 6.0+). Most modern laptops expose this via UCSI.
- bash and awk.
## Notes / caveats
- The listed offers come from the charger's Source Capabilities as reported by the
laptop's PD controller firmware. Some firmware reports little or nothing; if `PD supported`
says `no` with a charger you know does PD, try a different cable first.
- `voltage_now` from the UCSI power supply is often stale on some laptops, so `pdinfo`
reports the charger's offers and the battery charge rate instead.
- The PD revision shown may reflect the laptop side of the connection rather than the charger.
## License
MIT
Executable
+40
View File
@@ -0,0 +1,40 @@
#!/bin/bash
# Install pdinfo for the current user: command, app-menu entry and (optionally) a desktop icon.
# Usage: ./install.sh [--no-desktop-icon] | ./install.sh --uninstall
set -e
cd "$(dirname "$0")"
BIN="$HOME/.local/bin"
APPS="$HOME/.local/share/applications"
DESKTOP_DIR="$(xdg-user-dir DESKTOP 2>/dev/null || echo "$HOME/Desktop")"
if [ "$1" = "--uninstall" ]; then
rm -f "$BIN/pdinfo" "$APPS/pdinfo.desktop" "$DESKTOP_DIR/pdinfo.desktop"
echo "pdinfo uninstalled."; exit 0
fi
mkdir -p "$BIN" "$APPS"
install -m 755 pdinfo "$BIN/pdinfo"
RUN="$BIN/pdinfo; echo; read -n1 -rsp 'Press any key to close...'"
if command -v ptyxis >/dev/null; then
EXEC="ptyxis --standalone -- bash -c \"$RUN\""; TERM_FLAG=false
elif command -v gnome-terminal >/dev/null; then
EXEC="gnome-terminal -- bash -c \"$RUN\""; TERM_FLAG=false
elif command -v konsole >/dev/null; then
EXEC="konsole -e bash -c \"$RUN\""; TERM_FLAG=false
else
EXEC="bash -c \"$RUN\""; TERM_FLAG=true
fi
# Escape & and | so they survive sed
ESC_EXEC=$(printf '%s' "$EXEC" | sed 's/[&|]/\\&/g')
sed -e "s|@EXEC@|$ESC_EXEC|" -e "s|@TERMINAL@|$TERM_FLAG|" pdinfo.desktop.in > "$APPS/pdinfo.desktop"
chmod 644 "$APPS/pdinfo.desktop"
if [ "$1" != "--no-desktop-icon" ] && [ -d "$DESKTOP_DIR" ]; then
install -m 755 "$APPS/pdinfo.desktop" "$DESKTOP_DIR/pdinfo.desktop"
command -v gio >/dev/null && gio set "$DESKTOP_DIR/pdinfo.desktop" metadata::trusted true 2>/dev/null || true
fi
echo "pdinfo installed."
case ":$PATH:" in *":$BIN:"*) ;; *) echo "Note: $BIN is not on your PATH; add it to run 'pdinfo' from a terminal." ;; esac
Executable
+57
View File
@@ -0,0 +1,57 @@
#!/bin/bash
# pdinfo - show USB-C Power Delivery info for connected chargers (Linux sysfs)
VERSION=1.0.0
case "$1" in
-v|--version) echo "pdinfo $VERSION"; exit 0 ;;
-h|--help) echo "Usage: pdinfo [-h|--help] [-v|--version]"
echo "Show USB-C Power Delivery info for connected chargers."; exit 0 ;;
esac
r() { cat "$1" 2>/dev/null; }
echo "=== USB-C Charger Info ==="
found=0
for p in /sys/class/typec/port*-partner; do
[ -e "$p" ] || continue
port=$(basename "${p%-partner}")
found=1
echo
echo "[$port]"
echo " Mode: $(r /sys/class/typec/$port/power_operation_mode)"
echo " PD supported: $(r "$p/supports_usb_power_delivery")"
pd=$(readlink -f "$p/usb_power_delivery" 2>/dev/null)
if [ -n "$pd" ] && [ -d "$pd" ]; then
echo " PD revision: $(r "$pd/revision")"
echo " Charger offers:"
max=0
for c in "$pd"/source-capabilities/*:*/; do
[ -d "$c" ] || continue
name=$(basename "$c"); type=${name#*:}
if [ -f "$c/voltage" ]; then
v=$(r "$c/voltage"); i=$(r "$c/maximum_current")
v=${v%mV}; i=${i%mA}
w=$(( v * i / 1000000 ))
awk -v t="$type" -v v="$v" -v i="$i" -v w="$w" \
'BEGIN { printf " %-15s %5.1f V %5.2f A = %3d W\n", t, v/1000, i/1000, w }'
[ "$w" -gt "$max" ] && max=$w
else
lo=$(r "$c/minimum_voltage"); hi=$(r "$c/maximum_voltage")
cur=$(r "$c/maximum_current"); pw=$(r "$c/maximum_power")
printf " %-15s %s - %s %s%s\n" "$type" "$lo" "$hi" "${cur}" "${pw:+ $pw}"
fi
done
echo " Charger max: ${max} W"
else
echo " (no PD contract - plain USB-C power, max 15 W)"
fi
done
[ "$found" = 0 ] && echo && echo "No USB-C charger detected."
for b in /sys/class/power_supply/BAT*; do
[ -d "$b" ] || continue
pw=$(r "$b/power_now")
echo
awk -v n="$(basename "$b")" -v c="$(r "$b/capacity")" -v s="$(r "$b/status")" -v p="${pw:-0}" \
'BEGIN { printf "Battery %s: %s%%, %s, %.1f W\n", n, c, s, p/1000000 }'
done
+8
View File
@@ -0,0 +1,8 @@
[Desktop Entry]
Type=Application
Name=USB-C Charger Info
Comment=Show USB Power Delivery info for the connected charger
Exec=@EXEC@
Icon=battery-full-charging
Terminal=@TERMINAL@
Categories=System;