diff --git a/home-profiles/desktop/.config/qbar/blocks/battery2 b/home-profiles/desktop/.config/qbar/blocks/battery2 new file mode 100755 index 0000000000000000000000000000000000000000..b4d6925308ea0485abb18864254d25efda7948d2 --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/battery2 @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2016 James Murphy, 2018 Jens Nolte +# Licensed under the GPL version 2 only +# +# A battery indicator blocklet script for i3blocks + +import re +from subprocess import check_output + +status = check_output(['acpi'], universal_newlines=True) + +if not status: + # stands for no battery found + fulltext = "<span color='red'>🔋âŒ</span>" + percentleft = 100 +else: + # if there is more than one battery in one laptop, the percentage left is + # available for each battery separately, although state and remaining + # time for overall block is shown in the status of the first battery + batteries = status.split("\n") + state_batteries=[] + commasplitstatus_batteries=[] + percentleft_batteries=[] + time = "" + for battery in batteries: + if battery!='': + state_batteries.append(battery.split(": ")[1].split(", ")[0]) + commasplitstatus = battery.split(", ") + if not time: + time = commasplitstatus[-1].strip() + # check if it matches a time + time = re.match(r"(\d+):(\d+)", time) + if time: + time = ":".join(time.groups()) + timeleft = " ({})".format(time) + else: + timeleft = "" + + p = int(commasplitstatus[1].rstrip("%\n")) + if p>0: + percentleft_batteries.append(p) + commasplitstatus_batteries.append(commasplitstatus) + state = state_batteries[0] + commasplitstatus = commasplitstatus_batteries[0] + if percentleft_batteries: + percentleft = int(sum(percentleft_batteries)/len(percentleft_batteries)) + else: + percentleft = 0 + + # stands for charging + FA_LIGHTNING = "âš¡" + + # stands for plugged in + FA_PLUG = "🔌" + + # stands for using battery + FA_BATTERY = "🔋" + + # stands for unknown status of battery + FA_QUESTION = "â“" + + + discharging=True + + if state == "Discharging": + fulltext = FA_BATTERY + " " + elif state == "Full": + fulltext = FA_PLUG + " " + timeleft = "" + discharging=False + elif state == "Unknown": + fulltext = FA_BATTERY + FA_QUESTION + " " + timeleft = "" + else: + fulltext = FA_PLUG + FA_LIGHTNING + " " + discharging=False + + def color(percent): + if percent < 10: + # exit code 33 will turn background red + return "#FFFFFF" + if percent < 15: + return "#FF3300" + if percent < 20: + return "#FF6600" + if percent < 25: + return "#FF9900" + if percent < 30: + return "#FFCC00" + if percent < 35: + return "#FFFF00" + if percent < 40: + return "#FFFF33" + if percent < 45: + return "#FFFF66" + return "#FFFFFF" + + if discharging: + form = '<span color="{}">{}%</span>' + fulltext += form.format(color(percentleft), percentleft) + else: + form = '{}%' + fulltext += form.format(percentleft) + fulltext += timeleft + +print(fulltext) +print(fulltext) +if percentleft < 10: + exit(33) diff --git a/home-profiles/desktop/.config/qbar/blocks/calendar b/home-profiles/desktop/.config/qbar/blocks/calendar new file mode 100755 index 0000000000000000000000000000000000000000..89f0f44a3ae6cab078c128cf2ff2924d29f30ed2 --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/calendar @@ -0,0 +1,38 @@ +#! /bin/sh + +width=200 +height=200 +datefmt="+%a %d.%m.%Y <span color='#ffffff'>%H:%M</span>" + +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 - $width / 2)) + posY=$(($BLOCK_Y - $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 +date "$datefmt" diff --git a/home-profiles/desktop/.config/qbar/blocks/cpu_usage b/home-profiles/desktop/.config/qbar/blocks/cpu_usage new file mode 100755 index 0000000000000000000000000000000000000000..b94ff91310bc9d3d3b3df2ab5d0b0b4421eb1333 --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/cpu_usage @@ -0,0 +1,59 @@ +#!/usr/bin/env perl +# +# Copyright 2014 Pierre Mavro <deimos@deimos.fr> +# Copyright 2014 Vivien Didelot <vivien@didelot.org> +# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com> +# +# Licensed under the terms of the GNU GPL v3, or any later version. + +use strict; +use warnings; +use utf8; +use Getopt::Long; + +# default values +my $t_warn = 80; +my $t_crit = 90; +my $cpu_usage = -1; +my $decimals = 2; + +sub help { + print "Usage: cpu_usage [-w <warning>] [-c <critical>] [-d <decimals>]\n"; + print "-w <percent>: warning threshold to become yellow\n"; + print "-c <percent>: critical threshold to become red\n"; + print "-d <decimals>: Use <decimals> decimals for percentage (default is $decimals) \n"; + exit 0; +} + +GetOptions("help|h" => \&help, + "w=i" => \$t_warn, + "c=i" => \$t_crit, + "d=i" => \$decimals, +); + +# Get CPU usage +$ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is +open (MPSTAT, 'mpstat 1 1 |') or die; +while (<MPSTAT>) { + if (/^.*\s+(\d+\.\d+)[\s\x00]?$/) { + $cpu_usage = 100 - $1; # 100% - %idle + last; + } +} +close(MPSTAT); + +$cpu_usage eq -1 and die 'Can\'t find CPU information'; + +# Print short_text, full_text +printf "%.${decimals}f%%\n", $cpu_usage; +printf "%.${decimals}f%%\n", $cpu_usage; + +# Print color, if needed +if ($cpu_usage >= $t_crit) { + print "#FF0000\n"; + #exit 33; +} elsif ($cpu_usage >= $t_warn) { + print "#FFFC00\n"; +} + +exit 0; diff --git a/home-profiles/desktop/.config/qbar/blocks/iface b/home-profiles/desktop/.config/qbar/blocks/iface new file mode 100755 index 0000000000000000000000000000000000000000..25ff09c0e44bcf87abdd3613dfb5a95a02165c3a --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/iface @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info> +# Copyright (C) 2014 Alexander Keller <github@nycroth.com> + +# 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 <http://www.gnu.org/licenses/>. + +#------------------------------------------------------------------------ + +# Use the provided interface, otherwise the device used for the default route. +if [[ -n $BLOCK_INSTANCE ]]; then + IF=$BLOCK_INSTANCE +else + IF=$(ip route | awk '/^default/ { print $5 ; exit }') +fi + +#------------------------------------------------------------------------ + +# As per #36 -- It is transparent: e.g. if the machine has no battery or wireless +# connection (think desktop), the corresponding block should not be displayed. +[[ ! -d /sys/class/net/${IF} ]] && exit + +#------------------------------------------------------------------------ + +AF=inet6? +LABEL="" + +for flag in "$1" "$2"; do + case "$flag" in + -4) + AF=inet ;; + -6) + AF=inet6 ;; + -L) + if [[ "$IF" = "" ]]; then + LABEL="iface " + else + LABEL="$IF: " + fi ;; + esac +done + +if [[ "$IF" = "" ]] || [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then + echo "${LABEL}down" # full text + echo "${LABEL}down" # short text + echo \#FF0000 # color + exit +fi + +# if no interface is found, use the first device with a global scope +IPADDR=$(ip addr show $IF | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit") + +case $BLOCK_BUTTON in + 3) echo -n "$IPADDR" | xclip -q -se c ;; +esac + +#------------------------------------------------------------------------ + +echo "$LABEL$IPADDR" # full text +echo "$LABEL$IPADDR" # short text diff --git a/home-profiles/desktop/.config/qbar/blocks/irc b/home-profiles/desktop/.config/qbar/blocks/irc new file mode 100755 index 0000000000000000000000000000000000000000..57772148cdf726e14a3fa0b5751f3177d3e4a2b8 --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/irc @@ -0,0 +1,8 @@ +#!/usr/bin/env zsh + +if timeout 3s ssh jens-vps weechat-get-notify +then + echo "💬" +else + echo "" +fi diff --git a/home-profiles/desktop/.config/qbar/blocks/memory b/home-profiles/desktop/.config/qbar/blocks/memory new file mode 100755 index 0000000000000000000000000000000000000000..eb056fb3171f3cf8e5d71bf70eac46e8fc4897c6 --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/memory @@ -0,0 +1,69 @@ +#!/bin/sh +# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info> + +# 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 <http://www.gnu.org/licenses/>. + +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 { + if (type == "swap") { + free=swap_free/1024/1024 + used=(swap_total-swap_free)/1024/1024 + total=swap_total/1024/1024 + } else { + free=mem_free/1024/1024 + used=(mem_total-mem_free)/1024/1024 + total=mem_total/1024/1024 + } + + pct=0 + if (total > 0) { + pct=used/total*100 + } + + # full text + printf("%.1f/%.1f\n", used, total) + + # short text + printf("%.f%%\n", pct) + + # color + if (pct > 90) { + print("#FF0000\n") + } else if (pct > 80) { + print("#FFAE00\n") + } else if (pct > 70) { + print("#FFF600\n") + } +} +' /proc/meminfo diff --git a/home-profiles/desktop/.config/qbar/blocks/network-environment b/home-profiles/desktop/.config/qbar/blocks/network-environment new file mode 100755 index 0000000000000000000000000000000000000000..da26be3530635d6f1ad3c52e410459498df1fb1c --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/network-environment @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +if [[ -z $UID || ! -d "/run/user/$UID" ]] +then + echo "error" + exit 2 +fi + +ENVIRONMENT_FILE="/run/user/$UID/network-environment" + +SSID=$(iwgetid -r) + +if [[ "$SSID" == "011010010011" ]] +then + ENVIRONMENT="home" + SYMBOL="ðŸ " + COLOR="#88bbff" +elif [[ "$SSID" == "100111010110" ]] +then + ENVIRONMENT="mobile" + SYMBOL="ðŸŒ" +elif [[ "$SSID" == "subraum" ]] +then + ENVIRONMENT="subraum" + SYMBOL="🚀" + COLOR="#ff7020" +elif [[ "$SSID" == "eduroam" ]] +then + ENVIRONMENT="uni" + SYMBOL="🎓" +elif [[ "$SSID" == "Robs_IPhone" ]] +then + ENVIRONMENT="work" + SYMBOL="ðŸ¢" +elif [[ "$SSID" == "congress" ]] +then + ENVIRONMENT="congress" + SYMBOL="🚀" + COLOR="#ff00aa" +else + ENVIRONMENT="unknown" + SYMBOL="ðŸŒ" +fi + +LAST_ENVIRONMENT=`cat $ENVIRONMENT_FILE` +echo "$ENVIRONMENT" > $ENVIRONMENT_FILE + +output_block() { + echo "$1" +} + + +if [[ "$ENVIRONMENT" != "$LAST_ENVIRONMENT" ]]; then + # new environment + if [[ -z ENVIRONMENT_EFFECT ]]; then + output_block "$SYMBOL $ENVIRONMENT_EFFECT" + else + output_block "<span color='${COLOR:-#ffb840}'>$SYMBOL $ENVIRONMENT</span>" + fi + # run environment handler + ACTIVATION_HANDLER=$HOME/run/network-environment/activation_handler + if [[ -x $ACTIVATION_HANDLER ]] + then + $ACTIVATION_HANDLER "$ENVIRONMENT" "$SYMBOL" >/dev/null + fi +else + output_block "$SYMBOL $ENVIRONMENT" + + # only invoke click handlers if the network has not changed + if [[ $BLOCK_BUTTON == "1" ]]; then + notify-send "$ENVIRONMENT primary"; + elif [[ $BLOCK_BUTTON == "3" ]]; then + notify-send "$ENVIRONMENT secondary"; + fi +fi diff --git a/home-profiles/desktop/.config/qbar/blocks/temperature b/home-profiles/desktop/.config/qbar/blocks/temperature new file mode 100755 index 0000000000000000000000000000000000000000..18587f78f645ad12d15bf45e04af9acd6435cbd2 --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/temperature @@ -0,0 +1,7 @@ +#!/usr/bin/env nix-shell +#!nix-shell --pure -i sh -p jq lm_sensors + +echo -n "🔥 " + +sensors -j | jq --join-output '."coretemp-isa-0000"."Package id 0".temp1_input' +echo °C diff --git a/home-profiles/desktop/.config/qbar/blocks/todo b/home-profiles/desktop/.config/qbar/blocks/todo new file mode 100755 index 0000000000000000000000000000000000000000..605df50537881bd206de4cd213905edac27267fe --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/todo @@ -0,0 +1,30 @@ +#!/usr/bin/env zsh + +if [[ $BLOCK_BUTTON == "1" ]] +then + notify "TODO" +elif [[ $BLOCK_BUTTON == "3" ]] +then + notify "Rechnung" +fi + +TIME=$(date "+%H%M") + +if (($TIME > 0100 && $TIME < 0800)) +then + if (($TIME > 0230)) + then + echo "<span color='#000000' background='#ff2200'>💤 sleep</span>" + elif (($TIME > 0200)) + then + echo "<span color='#ff4400'>💤 sleep</span>" + else + echo "<span color='#ff8800'>💤 sleep</span>" + fi + + exit +fi + +echo "â• <span color='#ffffff'>start</span>" +#echo "â• <span color='#ffffff'>todo</span> (0/1)" +#echo "✅ <span color='#ffffff'>done</span> (0/1)" diff --git a/home-profiles/desktop/.config/qbar/blocks/touchscreen b/home-profiles/desktop/.config/qbar/blocks/touchscreen new file mode 100755 index 0000000000000000000000000000000000000000..cd3af3f2b4e059844e06b4ab7dc191970e9ea5cc --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/touchscreen @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh + +if [[ -z $UID || ! -d "/run/user/$UID" ]]; then + echo "error" + exit 2 +fi + +touchscreen_disabled_file="/tmp/touchscreen_disabled" + +if [[ $BLOCK_BUTTON == "1" ]] +then + if [[ -f $touchscreen_disabled_file ]] + then + # touchscreen is disabled + sudo modprobe i2c_hid + sleep 0.1 + xinput --map-to-output $(xinput list --id-only "SYNA7501:00 06CB:16D1") eDP-1 + rm $touchscreen_disabled_file + notify-send --urgency=low "Touchscreen enabled"; + else + # touchscreen is enabled + sudo modprobe -r i2c_hid + touch $touchscreen_disabled_file + notify-send --urgency=low "Touchscreen disabled"; + fi +elif [[ $BLOCK_BUTTON == "3" ]] +then + xinput --map-to-output $(xinput list --id-only "SYNA7501:00 06CB:16D1") eDP-1 + notify-send --urgency=low "Updated touchscreen mapping"; +fi + +if [[ -f $touchscreen_disabled_file ]] +then + # touchscreen is disabled + echo "✊" +else + # touchscreen is enabled + echo "<span color='#ffffff'>👆</span>" +fi diff --git a/home-profiles/desktop/.config/qbar/blocks/volume-pulseaudio b/home-profiles/desktop/.config/qbar/blocks/volume-pulseaudio new file mode 100755 index 0000000000000000000000000000000000000000..db8ca2277f64202e193a26580770e8cfce5e446e --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/volume-pulseaudio @@ -0,0 +1,180 @@ +#!/usr/bin/env bash +# Displays the default device, volume, and mute status for i3blocks + +AUDIO_HIGH_SYMBOL='🔊 ' + +AUDIO_MED_THRESH=50 +AUDIO_MED_SYMBOL='🔉 ' + +AUDIO_LOW_THRESH=0 +AUDIO_LOW_SYMBOL='🔈 ' + +AUDIO_MUTED_SYMBOL='🔇 ' + +AUDIO_INTERVAL=5 + +ACTIVE_COLOR="#ffffff" + +LONG_FORMAT=4 +SHORT_FORMAT=2 +USE_PERCENT=1 +USE_ALSA_NAME=0 +USE_DESCRIPTION=0 + +SUBSCRIBE=0 + +while getopts F:Sf:padH:M:L:X:T:t:C:c:i:m:s:h opt; do + case "$opt" in + S) SUBSCRIBE=1 ;; + F) LONG_FORMAT="$OPTARG" ;; + f) SHORT_FORMAT="$OPTARG" ;; + p) USE_PERCENT=0 ;; + a) USE_ALSA_NAME=1 ;; + d) USE_DESCRIPTION=1 ;; + H) AUDIO_HIGH_SYMBOL="$OPTARG" ;; + M) AUDIO_MED_SYMBOL="$OPTARG" ;; + L) AUDIO_LOW_SYMBOL="$OPTARG" ;; + X) AUDIO_MUTED_SYMBOL="$OPTARG" ;; + T) AUDIO_MED_THRESH="$OPTARG" ;; + t) AUDIO_LOW_THRESH="$OPTARG" ;; + i) AUDIO_INTERVAL="$OPTARG" ;; + m) MIXER="$OPTARG" ;; + s) SCONTROL="$OPTARG" ;; + h) printf \ +"Usage: volume-pulseaudio [-S] [-F format] [-f format] [-p] [-a|-d] [-H symb] [-M symb] + [-L symb] [-X symb] [-T thresh] [-t thresh] [-C color] [-c color] [-i inter] + [-m mixer] [-s scontrol] [-h] +Options: +-F, -f\tOutput format (-F long format, -f short format) to use, amongst: +\t0\t symb vol [index:name]\t (default long) +\t1\t symb vol [name] +\t2\t symb vol [index]\t (default short) +\t3\t symb vol +-S\tSubscribe to volume events (requires persistent block, always uses long format) +-p\tOmit the percent sign (%%) in volume +-a\tUse ALSA name if possible +-d\tUse device description instead of name if possible +-H\tSymbol to use when audio level is high. Default: '$AUDIO_HIGH_SYMBOL' +-M\tSymbol to use when audio level is medium. Default: '$AUDIO_MED_SYMBOL' +-L\tSymbol to use when audio level is low. Default: '$AUDIO_LOW_SYMBOL' +-X\tSymbol to use when audio is muted. Default: '$AUDIO_MUTED_SYMBOL' +-T\tThreshold for medium audio level. Default: $AUDIO_MED_THRESH +-t\tThreshold for low audio level. Default: $AUDIO_LOW_THRESH +-i\tInterval size of volume increase/decrease. Default: $AUDIO_INTERVAL +-m\tUse the given mixer. +-s\tUse the given scontrol. +-h\tShow this help text +" && exit 0;; + esac +done + +if [[ -z "$MIXER" ]] ; then + MIXER="default" + if amixer -D pulse info >/dev/null 2>&1 ; then + MIXER="pulse" + fi +fi + +if [[ -z "$SCONTROL" ]] ; then + SCONTROL=$(amixer -D "$MIXER" scontrols | sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" | head -n1) +fi + +CAPABILITY=$(amixer -D $MIXER get $SCONTROL | sed -n "s/ Capabilities:.*cvolume.*/Capture/p") + + +function move_sinks_to_new_default { + DEFAULT_SINK=$1 + pacmd list-sink-inputs | grep index: | grep -o '[0-9]\+' | while read SINK + do + pacmd move-sink-input $SINK $DEFAULT_SINK + done +} + +function set_default_playback_device_next { + inc=${1:-1} + num_devices=$(pacmd list-sinks | grep -c index:) + sink_arr=($(pacmd list-sinks | grep index: | grep -o '[0-9]\+')) + default_sink_index=$(( $(pacmd list-sinks | grep index: | grep -no '*' | grep -o '^[0-9]\+') - 1 )) + default_sink_index=$(( ($default_sink_index + $num_devices + $inc) % $num_devices )) + default_sink=${sink_arr[$default_sink_index]} + pacmd set-default-sink $default_sink + move_sinks_to_new_default $default_sink +} + +case "$BLOCK_BUTTON" in + 1) set_default_playback_device_next ;; + 2) amixer -q -D $MIXER sset $SCONTROL $CAPABILITY toggle ;; + 3) set_default_playback_device_next -1 ;; + 4) amixer -q -D $MIXER sset $SCONTROL $CAPABILITY $AUDIO_INTERVAL%+ ;; + 5) amixer -q -D $MIXER sset $SCONTROL $CAPABILITY $AUDIO_INTERVAL%- ;; +esac + +function print_format { + PERCENT="%" + [[ $USE_PERCENT == 0 ]] && PERCENT="" + + if [[ $MUTED =~ "no" ]]; then + BLOCK="$SYMBOL<span color='$ACTIVE_COLOR'>$VOL$PERCENT</span>" + else + BLOCK="$SYMBOL$VOL$PERCENT" + fi + + case "$1" in + 1) echo "$BLOCK [$NAME]" ;; + 2) echo "$BLOCK [$INDEX]";; + 3) echo "$BLOCK" ;; + *) echo "$BLOCK [$INDEX:$NAME]" ;; + esac +} + +function print_block { + for name in INDEX NAME VOL MUTED; do + read $name + done < <(pacmd list-sinks | grep "index:\|name:\|volume: front\|muted:" | grep -A3 '*') + INDEX=$(echo "$INDEX" | grep -o '[0-9]\+') + VOL=$(echo "$VOL" | grep -o "[0-9]*%" | head -1 ) + VOL="${VOL%?}" + + NAME=$(echo "$NAME" | sed \ +'s/.*<.*\.\(.*\)>.*/\1/; t;'\ +'s/.*<\(.*\)>.*/\1/; t;'\ +'s/.*/unknown/') + + if [[ $USE_ALSA_NAME == 1 ]] ; then + ALSA_NAME=$(pacmd list-sinks |\ +awk '/^\s*\*/{f=1}/^\s*index:/{f=0}f' |\ +grep "alsa.name\|alsa.mixer_name" |\ +head -n1 |\ +sed 's/.*= "\(.*\)".*/\1/') + NAME=${ALSA_NAME:-$NAME} + elif [[ $USE_DESCRIPTION == 1 ]] ; then + DESCRIPTION=$(pacmd list-sinks |\ +awk '/^\s*\*/{f=1}/^\s*index:/{f=0}f' |\ +grep "device.description" |\ +head -n1 |\ +sed 's/.*= "\(.*\)".*/\1/') + NAME=${DESCRIPTION:-$NAME} + fi + + if [[ $MUTED =~ "no" ]] ; then + SYMBOL=$AUDIO_HIGH_SYMBOL + [[ $VOL -le $AUDIO_MED_THRESH ]] && SYMBOL=$AUDIO_MED_SYMBOL + [[ $VOL -le $AUDIO_LOW_THRESH ]] && SYMBOL=$AUDIO_LOW_SYMBOL + else + SYMBOL=$AUDIO_MUTED_SYMBOL + fi + + if [[ $SUBSCRIBE == 1 ]] ; then + print_format "$LONG_FORMAT" + else + print_format "$LONG_FORMAT" + print_format "$SHORT_FORMAT" + fi +} + +print_block +if [[ $SUBSCRIBE == 1 ]] ; then + while read -r EVENT; do + print_block + done < <(pactl subscribe | stdbuf -oL grep change) +fi diff --git a/home-profiles/desktop/.config/qbar/blocks/wifi2 b/home-profiles/desktop/.config/qbar/blocks/wifi2 new file mode 100755 index 0000000000000000000000000000000000000000..9d13f9974ccddaf14d7a0dc5c34b16f2b636f8c7 --- /dev/null +++ b/home-profiles/desktop/.config/qbar/blocks/wifi2 @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +if [[ -n "${1}" ]] +then + INTERFACE="${1}" +else + INTERFACE="${BLOCK_INSTANCE:-wlan0}" +fi + +SSID=$(iwgetid -r) + +# don't display if there is no active wifi adapter +[[ ! -d /sys/class/net/${INTERFACE}/wireless ]] || + [[ "$(cat /sys/class/net/$INTERFACE/operstate)" = 'down' ]] && exit + +QUALITY=$(grep $INTERFACE /proc/net/wireless | awk '{ print int($3 * 100 / 70) }') + +# color +if (( $QUALITY <= 20 )); then + QUALITY="<span color='#ff0000'>$QUALITY%</span>" +elif (( $QUALITY <= 30 )); then + QUALITY="<span color='#ffae00'>$QUALITY%</span>" +elif (( $QUALITY <= 40 )); then + QUALITY="<span color='#fff600'>$QUALITY%</span>" +else + QUALITY="$QUALITY%" +fi + +# color-code specific ssids +[[ "$SSID" = 100111010110 ]] && SSID="<span color='#44ccff'>$SSID</span>" + +echo "${SSID} $QUALITY" # full text +echo "${SSID} $QUALITY" # short text