From a1d6fc2f3e6ab041cc51cb085ac59a646a126d25 Mon Sep 17 00:00:00 2001 From: Peter Son Struschka Date: Wed, 29 Jul 2020 16:40:02 +0800 Subject: basics+bspwm+herbstluftwm+i3wm+meta+polybar+xmonad: wm configs overhaul Created polybar as its own config instead of duplicated in bspwm and i3's directories allowing them both to be installed. Created herbstluftwm, xmonad window manager configs. Added scripts for a status bar, and fixed scripts. --- basics/.local/bin/battery-monitor | 45 ++++++++++++++++++++++++++++++++----- basics/.local/bin/change-vol | 10 +++++++++ basics/.local/bin/edit-config | 4 ++-- basics/.local/bin/locate-config | 30 +++++++++---------------- basics/.local/bin/macho | 25 +++++++++++++++++++++ basics/.local/bin/statusbar/battery | 30 +++++++++++++++++++++++++ basics/.local/bin/statusbar/memory | 22 ++++++++++++++++++ 7 files changed, 140 insertions(+), 26 deletions(-) create mode 100755 basics/.local/bin/change-vol create mode 100755 basics/.local/bin/macho create mode 100755 basics/.local/bin/statusbar/battery create mode 100755 basics/.local/bin/statusbar/memory (limited to 'basics/.local/bin') diff --git a/basics/.local/bin/battery-monitor b/basics/.local/bin/battery-monitor index ff1ef8b..1dfa7b6 100755 --- a/basics/.local/bin/battery-monitor +++ b/basics/.local/bin/battery-monitor @@ -1,6 +1,41 @@ +#!/bin/sh + +battery_path='/sys/class/power_supply/BAT0' + +percentage=$(head -n1 "${battery_path}/capacity") +state=$(head -n1 "${battery_path}/status") +rate=$([ -f "${battery_path}/current_now" ] && head -n1 "${battery_path}/current_now" || head -n1 "${battery_path}/power_now") +volt=$(head -n1 "${battery_path}/voltage_now") +now=$([ -f "${battery_path}/charge_now" ] && head -n1 "${battery_path}/charge_now" || head -n1 "${battery_path}/energy_now") +max=$([ -f "${battery_path}/current_full" ] && head -n1 "${battery_path}/current_full" || head -n1 "${battery_path}/energy_full") +cap=$([ "$state" = "Charging" ] && printf "%d-%d\n" "${max}" "${now}" | bc || echo "${now}") + +remaining=$( printf "%d/%d\n" "${cap}" "${volt}" | bc -l ) +current_rate=$( printf "%d/%d\n" "${rate}" "${volt}" | bc -l ) +echo $( [ "${current_rate}" != "0" ] && echo "not zero" || echo "is zero" ) +seconds=$( [ "${current_rate}" != "0" ] && printf "3600*%f/%f\n" "${remaining}" "${current_rate}" | bc || echo "0") +time_remaining=$( date -ud "@${seconds}" "+%H:%M:%S" ) + +echo "percentage ${percentage}%" +echo "state ${state}" +echo "rate ${rate}" +echo "volt ${volt}" +echo "now ${now}" +echo "max ${max}" +echo "cap ${cap}" +echo "remaining ${remaining}" +echo "current_rate ${current_rate}" +echo "seconds ${seconds}" +echo "time ${time_remaining}" + +exit 0 + battery_level=`acpi -b | cut -d ' ' -f 4 | grep -o '[0-9]*'` +battery_level=$(head -n1 /sys/class/power_supply/BAT0/capacity) battery_state=$(acpi | grep 'Battery' | sed 's/Battery\s[0-9]*: //' | sed 's/, [0-9][0-9]*\%.*//') +battery_state=$(head -n1 /sys/class/power_supply/BAT0/status) battery_remaining=$(acpi | grep -oh '[0-9:]* remaining' | sed 's/:\w\w remaining$/ Minutes/' | sed 's/00://' | sed 's/:/h /') +kk if [ ! -f "/tmp/.battery" ]; then echo "$battery_level" > /tmp/.battery @@ -18,12 +53,12 @@ checkBatteryLevel() { exit fi - if [ $battery_level -le 3 ]; then + if [ $battery_level -le 4 ]; then sudo systemctl suspend - elif [ $battery_level -le 5 ]; then - notify-send "Low Battery" "Your computer will suspend soon unless plugged into a power outlet." -u critical + elif [ $battery_level -le 7 ]; then + notify-send "Low Battery" "(${time_remaining}) Your computer will suspend soon unless plugged into a power outlet." -u critical elif [ $battery_level -le 10 ]; then - notify-send "Low Battery" "${battery_level}% (${battery_remaining}) of battery remaining." -u normal + notify-send "Low Battery" "${battery_level}% (${time_remaining}) of battery remaining." -u normal fi } @@ -38,4 +73,4 @@ checkBatteryStateChange() { } checkBatteryStateChange -checkBatteryLevel \ No newline at end of file +checkBatteryLevel diff --git a/basics/.local/bin/change-vol b/basics/.local/bin/change-vol new file mode 100755 index 0000000..a4309fd --- /dev/null +++ b/basics/.local/bin/change-vol @@ -0,0 +1,10 @@ +#!/bin/sh + +case "$1" in + "+") ;; + "-") ;; + *) exit 1; +esac + +pactl set-sink-mute 0 false +pactl set-sink-volume 0 "${1}5%" diff --git a/basics/.local/bin/edit-config b/basics/.local/bin/edit-config index 7d1baae..436a812 100755 --- a/basics/.local/bin/edit-config +++ b/basics/.local/bin/edit-config @@ -1,6 +1,6 @@ #/bin/sh FILE=$(locate-config) -[ -z "$FILE" ] && exit 1 +[ -z "$FILE" ] || [ ! -f "$FILE" ] && exit 1 -$EDITOR $FILE +${TERMINAL} -e ${EDITOR} ${FILE} diff --git a/basics/.local/bin/locate-config b/basics/.local/bin/locate-config index d798a39..26fd2cb 100755 --- a/basics/.local/bin/locate-config +++ b/basics/.local/bin/locate-config @@ -1,24 +1,16 @@ -#! /usr/bin/env bash +#!/bin/sh set -e -CONFIG_FILES=`ls -1 ~/.local/share/config-files | cut -d "" -f 1 | sort -d` -CONFIG_ARRAY=(`find ~/.local/share/config-files/ -maxdepth 1 -mindepth 1 -print0 | sort -z | xargs -r0 echo`) +config_dir="$HOME/.local/share/config-files" -INDEX=`echo "$CONFIG_FILES" | rofi -dmenu -format "i" -no-custom -mesg "Find config file for..."` -[ -z "$INDEX" ] && exit 1 -SOURCE=${CONFIG_ARRAY[$INDEX]} -#echo "$CONFIG_FILES" -#for item in ${CONFIG_ARRAY[*]} -#do -# printf " %s\n" $item -#done -# (https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself) -while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink - DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" - SOURCE="$(readlink "$SOURCE")" - [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located -done -DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" +p="Config:" + +sel=$(find "$config_dir" -writable -type l | cut -d "/" -f 7- | sort -d | dmenu -p "$p" -l 20) +ec=$? +[ "$ec" -ne 0 ] && exit $ec + +target=$(readlink -f "${config_dir}/${sel}") + +echo "$target" -echo $SOURCE diff --git a/basics/.local/bin/macho b/basics/.local/bin/macho new file mode 100755 index 0000000..2566d7d --- /dev/null +++ b/basics/.local/bin/macho @@ -0,0 +1,25 @@ +#!/bin/sh + +export FZF_DEFAULT_OPTS=' +--height=30% +--layout=reverse +--prompt="Manual: " +--preview="echo {1} | sed -E \"s/^\((.+)\)/\1/\" | xargs -I{S} man -Pcat {S} {2} 2>/dev/null"' + +while getopts ":s:" opt; do + case $opt in + s ) SECTION=$OPTARG; shift; shift;; + \?) echo "Invalid option: -$OPTARG" >&2; exit 1;; + : ) echo "Option -$OPTARG requires an argument" >&2; exit 1;; + esac +done + +manual=$(apropos -s ${SECTION:-''} ${@:-.} | \ + grep -v -E '^.+ \(0\)' |\ + awk '{print $2 " " $1}' | \ + sort | \ + fzf | \ + sed -E 's/^\((.+)\)/\1/') + +[ -z "$manual" ] && exit 0 +man $manual diff --git a/basics/.local/bin/statusbar/battery b/basics/.local/bin/statusbar/battery new file mode 100755 index 0000000..da6dd12 --- /dev/null +++ b/basics/.local/bin/statusbar/battery @@ -0,0 +1,30 @@ +#!/bin/sh + +battery_path='/sys/class/power_supply/BAT0' + +percentage=$(head -n1 "${battery_path}/capacity") +state=$(head -n1 "${battery_path}/status") +rate=$([ -f "${battery_path}/current_now" ] && + head -n1 "${battery_path}/current_now" || + head -n1 "${battery_path}/power_now") +volt=$(head -n1 "${battery_path}/voltage_now") +now=$([ -f "${battery_path}/charge_now" ] && + head -n1 "${battery_path}/charge_now" || + head -n1 "${battery_path}/energy_now") +max=$([ -f "${battery_path}/current_full" ] && + head -n1 "${battery_path}/current_full" || + head -n1 "${battery_path}/energy_full") +cap=$([ "$state" = "Charging" ] && + echo "$max $now" | awk '{printf "%d", $1 - $2}' || + echo "$now") + +remaining=$( echo "$cap $volt" | awk '{printf "%f", $1/$2}' ) +current_rate=$( echo "$rate $volt" | awk '{printf "%f", $1/$2}' ) +seconds_remaining=$( [ "${current_rate#0.00}" = "$current_rate" ] && + echo "$remaining $current_rate" | + awk '{printf "%d", 3600*$1/$2}' || + echo "0" ) +time_remaining=$( date -ud "@${seconds_remaining}" "+%H:%M:%S" ) + +# TODO: more variable output with flags? +echo "$state $percentage $time_remaining" diff --git a/basics/.local/bin/statusbar/memory b/basics/.local/bin/statusbar/memory new file mode 100755 index 0000000..7a952d8 --- /dev/null +++ b/basics/.local/bin/statusbar/memory @@ -0,0 +1,22 @@ +#!/bin/sh + +meminfo=$(awk ' +/^MemTotal:/ {Total=$2*1024} +/^MemAvailable:/ {Available=$2*1024} +/^MemFree:/ {Free=$2*1024} +/^Buffers:/ {Buffers=$2*1024} +/^Cached:/ {Cached=$2*1024} +/^SReclaimable:/ {SReclaimable=$2*1024} +/^Shmem:/ {Shmem=$2*1024} +END { +print Total ":" Available ":" Free ":" Buffers ":" Cached ":" SReclaimable ":" Shmem}' /proc/meminfo) + +echo "$meminfo" | + while IFS=: read -r t a f b c sr sh; do + memfree=$(echo "$a $t" | awk '{printf "%.3f", ($1 / $2) * 100}') + memused=$(echo "$memfree" | awk '{printf "%.3f", (100 - $1)}') + + # Percentage values + # TODO: other values, controllable by flags? + echo "$memfree $memused" + done -- cgit v1.2.3