Skip to content

Instantly share code, notes, and snippets.

View VladSavitsky's full-sized avatar

Vlad Savitsky VladSavitsky

View GitHub Profile
#!/usr/bin/env bash
BAT=$(echo /sys/class/power_supply/BAT*)
BAT_STATUS="$BAT/status"
BAT_CAP="$BAT/capacity"
LOW_BAT_PERCENT=20
AC_PROFILE="performance"
BAT_PROFILE="balanced"
LOW_BAT_PROFILE="power-saver"

Found here by Stephan Farestam

Here is a bash-only YAML parser that leverages sed and awk to parse simple yaml files:

function parse_yaml {
   local prefix=$2
   local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
   sed -ne "s|^\($s\):|\1|" \
        -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \

-e "s|^($s)($w)$s:$s(.*)$s$|\1$fs\2$fs\3|p" $1 |