From 29358b8d15ec1ddd8d2c11e2f2f6964ec49edc52 Mon Sep 17 00:00:00 2001 From: benj Date: Mon, 9 Sep 2019 15:22:07 -0700 Subject: basic i3 setup --- des/i3/i3blocks/config | 46 +++++++++++++++++++ des/i3/i3blocks/scripts/archupdates | 10 +++++ des/i3/i3blocks/scripts/bandwidth | 88 +++++++++++++++++++++++++++++++++++++ des/i3/i3blocks/scripts/battery | 29 ++++++++++++ des/i3/i3blocks/scripts/brightness | 10 +++++ des/i3/i3blocks/scripts/calendar | 40 +++++++++++++++++ des/i3/i3blocks/scripts/fan | 10 +++++ des/i3/i3blocks/scripts/memory | 49 +++++++++++++++++++++ des/i3/i3blocks/scripts/temperature | 69 +++++++++++++++++++++++++++++ des/i3/i3blocks/scripts/volume | 70 +++++++++++++++++++++++++++++ 10 files changed, 421 insertions(+) create mode 100644 des/i3/i3blocks/config create mode 100755 des/i3/i3blocks/scripts/archupdates create mode 100755 des/i3/i3blocks/scripts/bandwidth create mode 100755 des/i3/i3blocks/scripts/battery create mode 100755 des/i3/i3blocks/scripts/brightness create mode 100755 des/i3/i3blocks/scripts/calendar create mode 100755 des/i3/i3blocks/scripts/fan create mode 100755 des/i3/i3blocks/scripts/memory create mode 100755 des/i3/i3blocks/scripts/temperature create mode 100755 des/i3/i3blocks/scripts/volume (limited to 'des/i3/i3blocks') diff --git a/des/i3/i3blocks/config b/des/i3/i3blocks/config new file mode 100644 index 0000000..0835c08 --- /dev/null +++ b/des/i3/i3blocks/config @@ -0,0 +1,46 @@ +command=/usr/local/i3blocks/$BLOCK_NAME +separator=false +separator_block_width=15 +markup=pango + +[battery] +interval=1 +color=#a8afb0 + +[brightness] +interval=once +signal=9 +color=#ffff33 + +[volume] +instance=Master +interval=once +signal=10 +color=#4ca2df + +[fan] +interval=1 +color=#a8afb0 + +[bandwidth] +instance=wlp3s0 +interval=1 +# color=#859900 + +[memory] +label= +interval=1 +color=#e6ccff + +[temperature] +label= +interval=10 +color=#cb4b16 + +[archupdates] +interval=60 +color=#49E20E + +[calendar] +interval=60 +color=#ffffff diff --git a/des/i3/i3blocks/scripts/archupdates b/des/i3/i3blocks/scripts/archupdates new file mode 100755 index 0000000..c07c45f --- /dev/null +++ b/des/i3/i3blocks/scripts/archupdates @@ -0,0 +1,10 @@ +#!/usr/bin/bash + +PAC_UPDATES=$(checkupdates | wc -l) +AUR_UPDATES=$(cower -u | wc -l) + +if [[ $PAC_UPDATES -gt 0 || $AUR_UPDATES -gt 0 ]]; then + echo " [$PAC_UPDATES .. $AUR_UPDATES]" +else + echo " 0" +fi \ No newline at end of file diff --git a/des/i3/i3blocks/scripts/bandwidth b/des/i3/i3blocks/scripts/bandwidth new file mode 100755 index 0000000..d7db2a6 --- /dev/null +++ b/des/i3/i3blocks/scripts/bandwidth @@ -0,0 +1,88 @@ +#!/bin/bash +# Copyright (C) 2012 Stefan Breunig +# Copyright (C) 2014 kaueraal +# Copyright (C) 2015 Thiago Perrotta + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Use the provided interface, otherwise the device used for the default route. +if [[ -n $BLOCK_INSTANCE ]]; then + INTERFACE=$BLOCK_INSTANCE +else + INTERFACE=$(ip route | awk '/^default/ { print $5 ; exit }') +fi + +# Issue #36 compliant. +if ! [ -e "/sys/class/net/${INTERFACE}/operstate" ] || ! [ "`cat /sys/class/net/${INTERFACE}/operstate`" = "up" ] +then + echo "$INTERFACE down" + echo "$INTERFACE down" + echo "#FF0000" + exit 0 +fi + +# path to store the old results in +path="/dev/shm/$(basename $0)-${INTERFACE}" + +# grabbing data for each adapter. +read rx < "/sys/class/net/${INTERFACE}/statistics/rx_bytes" +read tx < "/sys/class/net/${INTERFACE}/statistics/tx_bytes" + +# get time +time=$(date +%s) + +# write current data if file does not exist. Do not exit, this will cause +# problems if this file is sourced instead of executed as another process. +if ! [[ -f "${path}" ]]; then + echo "${time} ${rx} ${tx}" > "${path}" + chmod 0666 "${path}" +fi + +# read previous state and update data storage +read old < "${path}" +echo "${time} ${rx} ${tx}" > "${path}" + +# parse old data and calc time passed +old=(${old//;/ }) +time_diff=$(( $time - ${old[0]} )) + +# sanity check: has a positive amount of time passed +[[ "${time_diff}" -gt 0 ]] || exit + +# calc bytes transferred, and their rate in byte/s +rx_diff=$(( $rx - ${old[1]} )) +tx_diff=$(( $tx - ${old[2]} )) +rx_rate=$(( $rx_diff / $time_diff )) +tx_rate=$(( $tx_diff / $time_diff )) + +# shift by 10 bytes to get KiB/s. If the value is larger than +# 1024^2 = 1048576, then display MiB/s instead + +# incoming +echo -n "⇘" +rx_kib=$(( $rx_rate >> 10 )) +if [[ "$rx_rate" -gt 1048576 ]]; then + printf '%sM' "`echo "scale=1; $rx_kib / 1024" | bc`" +else + echo -n "${rx_kib}K" +fi + +# outgoing +echo -n "" +tx_kib=$(( $tx_rate >> 10 )) +if [[ "$tx_rate" -gt 1048576 ]]; then + printf '%sM' "`echo "scale=1; $tx_kib / 1024" | bc`" +else + echo -n "${tx_kib}K" +fi diff --git a/des/i3/i3blocks/scripts/battery b/des/i3/i3blocks/scripts/battery new file mode 100755 index 0000000..802689b --- /dev/null +++ b/des/i3/i3blocks/scripts/battery @@ -0,0 +1,29 @@ +#!/usr/bin/bash + +BAT_DIR=/sys/class/power_supply/BAT0 +CHARGE=$(cat $BAT_DIR/capacity) +CHARGE_FULL=$(cat $BAT_DIR/charge_full) +CHARGE_NOW=$(cat $BAT_DIR/charge_now) +STATUS=$(cat $BAT_DIR/status) + +ICON_BATTERY_25_P= +ICON_BATTERY_50_P= +ICON_BATTERY_75_P= +ICON_BATTERY_FULL= +ICON_BATTERY_CHARGING= +ICON_FULL= + +PERCENT_FULL=$(echo - | awk -v charge_full="$CHARGE_FULL" -v charge_now="$CHARGE_NOW" '{printf "%1.0f\n", (charge_now / charge_full)*100}') +if [[ $STATUS == "Full" ]]; then + echo "$ICON_FULL" +elif [[ $STATUS == "Charging" ]]; then + echo "$ICON_BATTERY_CHARGING ($PERCENT_FULL%)" +elif [[ $PERCENT_FULL -lt 100 ]]; then + echo "$ICON_BATTERY_FULL ($PERCENT_FULL%)" +elif [[ $PERCENT_FULL -lt 75 ]]; then + echo "$ICON_BATTERY_75_P ($PERCENT_FULL%)" +elif [[ $PERCENT_FULL -lt 50 ]]; then + echo "$ICON_BATTERY_50_P ($PERCENT_FULL%)" +elif [[ $PERCENT_FULL -lt 25 ]]; then + echo "$ICON_BATTERY_25_P ($PERCENT_FULL%)" +fi diff --git a/des/i3/i3blocks/scripts/brightness b/des/i3/i3blocks/scripts/brightness new file mode 100755 index 0000000..64ea1d8 --- /dev/null +++ b/des/i3/i3blocks/scripts/brightness @@ -0,0 +1,10 @@ +#!/usr/bin/bash + +BRIGHTNESS_DIR=/sys/class/backlight/intel_backlight +MAX_BRIGHTNESS=$(cat $BRIGHTNESS_DIR/max_brightness) +CURR_BRIGHTNESS=$(cat $BRIGHTNESS_DIR/actual_brightness) + +ICON_BRIGHT_SUN="☀" +BRIGHTNESS_P=$(echo - | awk -v max="$MAX_BRIGHTNESS" -v curr="$CURR_BRIGHTNESS" '{printf "%1.0f\n", (curr / max)*100}') + +echo "$ICON_BRIGHT_SUN $BRIGHTNESS_P%" diff --git a/des/i3/i3blocks/scripts/calendar b/des/i3/i3blocks/scripts/calendar new file mode 100755 index 0000000..27653a5 --- /dev/null +++ b/des/i3/i3blocks/scripts/calendar @@ -0,0 +1,40 @@ +#! /bin/sh + +WIDTH=${WIDTH:-100} +HEIGHT=${HEIGHT:-100} +DATEFMT=${DATEFMT:-"+%Y-%m-%d %H:%M"} +SHORTFMT=${SHORTFMT:-"+%H:%M:%S"} + +OPTIND=1 +while getopts ":f:W:H:" opt; do + case $opt in + f) DATEFMT="$OPTARG" ;; + W) WIDTH="$OPTARG" ;; + H) HEIGHT="$OPTARG" ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +case "$BLOCK_BUTTON" in + 1|2|3) + + # the position of the upper left corner of the popup + posX=$(( ( $BLOCK_X - 230 ) - $WIDTH / 2 )) + posY=$(( ( $BLOCK_Y - 200 ) - $HEIGHT )) + + i3-msg -q "exec yad --calendar \ + --width=$WIDTH --height=$HEIGHT \ + --undecorated --fixed \ + --close-on-unfocus --no-buttons \ + --posx=$posX --posy=$posY \ + > /dev/null" +esac +echo "$LABEL$(date "$DATEFMT") " +echo "$LABEL$(date "$SHORTFMT") " diff --git a/des/i3/i3blocks/scripts/fan b/des/i3/i3blocks/scripts/fan new file mode 100755 index 0000000..84f1725 --- /dev/null +++ b/des/i3/i3blocks/scripts/fan @@ -0,0 +1,10 @@ +#!/usr/bin/bash + +FAN_DIR=/sys/devices/platform/applesmc.768 +MAX_FAN=$(cat $FAN_DIR/fan1_max) +CURR_FAN=$(cat $FAN_DIR/fan1_output) + +ICON_FAN="" +FAN_P=$(echo - | awk -v max="$MAX_FAN" -v curr="$CURR_FAN" '{printf "%1.0f\n", (curr / max)*100}') + +echo "$ICON_FAN $FAN_P%" diff --git a/des/i3/i3blocks/scripts/memory b/des/i3/i3blocks/scripts/memory new file mode 100755 index 0000000..e28af4e --- /dev/null +++ b/des/i3/i3blocks/scripts/memory @@ -0,0 +1,49 @@ +#!/bin/sh +# Copyright (C) 2014 Julien Bonjean + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +TYPE="${BLOCK_INSTANCE:-mem}" + +awk -v type=$TYPE ' +/^MemTotal:/ { + mem_total=$2 +} +/^MemFree:/ { + mem_free=$2 +} +/^Buffers:/ { + mem_free+=$2 +} +/^Cached:/ { + mem_free+=$2 +} +/^SwapTotal:/ { + swap_total=$2 +} +/^SwapFree:/ { + swap_free=$2 +} +END { + # full text + if (type == "swap") + printf("%.1fG\n", (swap_total-swap_free)/1024/1024) + else + printf("%.1fG\n", mem_free/1024/1024) + + # TODO: short text + + # TODO: color (if less than X%) +} +' /proc/meminfo diff --git a/des/i3/i3blocks/scripts/temperature b/des/i3/i3blocks/scripts/temperature new file mode 100755 index 0000000..ad745c3 --- /dev/null +++ b/des/i3/i3blocks/scripts/temperature @@ -0,0 +1,69 @@ +#!/usr/bin/perl +# Copyright 2014 Pierre Mavro +# Copyright 2014 Vivien Didelot +# Copyright 2014 Andreas Guldstrand +# Copyright 2014 Benjamin Chretien + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +use strict; +use warnings; +use utf8; +use Getopt::Long; + +binmode(STDOUT, ":utf8"); + +# default values +my $t_warn = 70; +my $t_crit = 90; +my $chip = ""; +my $temperature = -9999; + +sub help { + print "Usage: temperature [-w ] [-c ] [--chip ]\n"; + print "-w : warning threshold to become yellow\n"; + print "-c : critical threshold to become red\n"; + print "--chip : sensor chip\n"; + exit 0; +} + +GetOptions("help|h" => \&help, + "w=i" => \$t_warn, + "c=i" => \$t_crit, + "chip=s" => \$chip); + +# Get chip temperature +open (SENSORS, "sensors -u $chip |") or die; +while () { + if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) { + $temperature = $1; + last; + } +} +close(SENSORS); + +$temperature eq -9999 and die 'Cannot find temperature'; + +# Print short_text, full_text +print "$temperature°C\n" x2; + +# Print color, if needed +if ($temperature >= $t_crit) { + print "#FF0000\n"; + exit 33; +} elsif ($temperature >= $t_warn) { + print "#FFFC00\n"; +} + +exit 0; diff --git a/des/i3/i3blocks/scripts/volume b/des/i3/i3blocks/scripts/volume new file mode 100755 index 0000000..1e318a0 --- /dev/null +++ b/des/i3/i3blocks/scripts/volume @@ -0,0 +1,70 @@ +#!/bin/bash +# Copyright (C) 2014 Julien Bonjean +# Copyright (C) 2014 Alexander Keller + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +#------------------------------------------------------------------------ + +# The second parameter overrides the mixer selection +# For PulseAudio users, use "pulse" +# For Jack/Jack2 users, use "jackplug" +# For ALSA users, you may use "default" for your primary card +# or you may use hw:# where # is the number of the card desired +MIXER="default" +[ -n "$(lsmod | grep pulse)" ] && MIXER="pulse" +[ -n "$(lsmod | grep jack)" ] && MIXER="jackplug" +MIXER="${2:-$MIXER}" + +# The instance option sets the control to report and configure +# This defaults to the first control of your selected mixer +# For a list of the available, use `amixer -D $Your_Mixer scontrols` +SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols | + sed -n "s/Simple mixer control '\([A-Za-z ]*\)',0/\1/p" | + head -n1 + )}" + +# The first parameter sets the step to change the volume by (and units to display) +# This may be in in % or dB (eg. 5% or 3dB) +STEP="${1:-5%}" + +#------------------------------------------------------------------------ + +capability() { # Return "Capture" if the device is a capture device + amixer -D $MIXER get $SCONTROL | + sed -n "s/ Capabilities:.*cvolume.*/Capture/p" +} + +volume() { + amixer -D $MIXER get $SCONTROL $(capability) +} + +format() { + perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)' + perl_filter+='{CORE::say $4 eq "off" ? " MUTE" : "' + # If dB was selected, print that instead + perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo ' $1') + perl_filter+='"; exit}' + perl -ne "$perl_filter" +} + +#------------------------------------------------------------------------ + +case $BLOCK_BUTTON in + 3) amixer -q -D $MIXER sset $SCONTROL $(capability) toggle ;; # right click, mute/unmute + 4) amixer -q -D $MIXER sset $SCONTROL $(capability) ${STEP}+ unmute ;; # scroll up, increase + 5) amixer -q -D $MIXER sset $SCONTROL $(capability) ${STEP}- unmute ;; # scroll down, decrease +esac + +volume | format -- cgit v1.2.3