From b769e5c08da0d6b4e2cc62d9c5b2ea988f78f79c Mon Sep 17 00:00:00 2001 From: David Luevano <55825613+luevano@users.noreply.github.com> Date: Wed, 12 Feb 2020 02:37:21 -0700 Subject: Debug for no booting pc --- .local/bin/blocklets/calendar | 41 ---------- .local/bin/blocklets/cpu | 62 --------------- .local/bin/blocklets/gpu | 71 ----------------- .local/bin/blocklets/memory | 69 ----------------- .local/bin/blocklets/time | 100 ------------------------ .local/bin/blocklets/volume | 175 ------------------------------------------ .local/bin/blocks/calendar | 41 ++++++++++ .local/bin/blocks/cpu | 62 +++++++++++++++ .local/bin/blocks/gpu | 71 +++++++++++++++++ .local/bin/blocks/memory | 69 +++++++++++++++++ .local/bin/blocks/time | 100 ++++++++++++++++++++++++ .local/bin/blocks/volume | 175 ++++++++++++++++++++++++++++++++++++++++++ .local/bin/color_test | 41 ++++++++++ .local/bin/py/xcolors.py | 55 ------------- .local/bin/pys/xcolors.py | 55 +++++++++++++ 15 files changed, 614 insertions(+), 573 deletions(-) delete mode 100755 .local/bin/blocklets/calendar delete mode 100755 .local/bin/blocklets/cpu delete mode 100755 .local/bin/blocklets/gpu delete mode 100755 .local/bin/blocklets/memory delete mode 100755 .local/bin/blocklets/time delete mode 100755 .local/bin/blocklets/volume create mode 100755 .local/bin/blocks/calendar create mode 100755 .local/bin/blocks/cpu create mode 100755 .local/bin/blocks/gpu create mode 100755 .local/bin/blocks/memory create mode 100755 .local/bin/blocks/time create mode 100755 .local/bin/blocks/volume create mode 100755 .local/bin/color_test delete mode 100644 .local/bin/py/xcolors.py create mode 100644 .local/bin/pys/xcolors.py (limited to '.local/bin') diff --git a/.local/bin/blocklets/calendar b/.local/bin/blocklets/calendar deleted file mode 100755 index eb8e210..0000000 --- a/.local/bin/blocklets/calendar +++ /dev/null @@ -1,41 +0,0 @@ -#! /bin/sh - -WIDTH=${WIDTH:-200} -HEIGHT=${HEIGHT:-200} -DATEFMT=${DATEFMT:-"+%a %d.%m.%Y %H:%M:%S"} -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 - # The size is hardcoded for a 1080p monitor. - posX=$((1899 - $WIDTH)) - posY=$((35)) - - 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/.local/bin/blocklets/cpu b/.local/bin/blocklets/cpu deleted file mode 100755 index 44c1189..0000000 --- a/.local/bin/blocklets/cpu +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/perl -# -# Copyright 2014 Pierre Mavro -# Copyright 2014 Vivien Didelot -# Copyright 2014 Andreas Guldstrand -# -# 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 = $ENV{T_WARN} // 50; -my $t_crit = $ENV{T_CRIT} // 80; -my $cpu_usage = -1; -my $decimals = $ENV{DECIMALS} // 2; -my $label = $ENV{LABEL} // ""; - -sub help { - print "Usage: cpu_usage [-w ] [-c ] [-d ]\n"; - print "-w : warning threshold to become yellow\n"; - print "-c : critical threshold to become red\n"; - print "-d : Use 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 () { - 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 -print "${label}"; -printf "%.${decimals}f%%\n", $cpu_usage; -print "${label}"; -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/.local/bin/blocklets/gpu b/.local/bin/blocklets/gpu deleted file mode 100755 index e5e460b..0000000 --- a/.local/bin/blocklets/gpu +++ /dev/null @@ -1,71 +0,0 @@ -#! /usr/bin/perl - -# 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; - -# default values -my $t_warn = $ENV{T_WARN} || 70; -my $t_crit = $ENV{T_CRIT} || 90; -my $gpu_usage = -1; -my $gpu_mem = -1; -my $gpu_video = -1; -my $gpu_pcie = -1; -my $label = $ENV{LABEL} // ""; - -sub help { - print "Usage: gpu-load [-w ] [-c ]\n"; - print "-w : warning threshold to become amber\n"; - print "-c : critical threshold to become red\n"; - exit 0; -} - -GetOptions("help|h" => \&help, - "w=i" => \$t_warn, - "c=i" => \$t_crit); - -# Get GPU usage from nvidia-settings -open (NVS, 'nvidia-settings -q GPUUtilization -t |') or die; -while () { - if (/^[a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+)$/) { - $gpu_usage = $1; - $gpu_mem = $2; - $gpu_video = $3; - $gpu_pcie = $4; - last; - } -} -close(NVS); - -$gpu_usage eq -1 and die 'Can\'t find GPU information'; - -# I edited this to only show the gpu_usage and gpu_mem. -# Also fixed the label thing. -# Print full_text, short_text -# printf "%.0f%% %.0f%% %.0f%% %.0f%%\n", $gpu_usage, $gpu_mem, $gpu_video, $gpu_pcie; -# printf "%.0f%%\n", $gpu_usage; -printf "${label} %.0f%% %.0f%%\n", $gpu_usage, $gpu_mem; - -# Print color, if needed -if ($gpu_usage >= $t_crit || $gpu_mem >= $t_crit || $gpu_video >= $t_crit || $gpu_pcie >= $t_crit) { - print "#FF0000\n"; - exit 33; -} elsif ($gpu_usage >= $t_warn || $gpu_mem >= $t_warn || $gpu_video >= $t_warn || $gpu_pcie >= $t_warn) { - print "#FFBF00\n"; -} - -exit 0; diff --git a/.local/bin/blocklets/memory b/.local/bin/blocklets/memory deleted file mode 100755 index 90eb2c6..0000000 --- a/.local/bin/blocklets/memory +++ /dev/null @@ -1,69 +0,0 @@ -#!/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 { - 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("%.1fG/%.1fG (%.f%%)\n", used, total, pct) - - # short text - printf("%.f%%\n", pct) - - # color - if (pct > 90) { - print("#FF0000") - } else if (pct > 80) { - print("#FFAE00") - } else if (pct > 70) { - print("#FFF600") - } -} -' /proc/meminfo diff --git a/.local/bin/blocklets/time b/.local/bin/blocklets/time deleted file mode 100755 index 725fc68..0000000 --- a/.local/bin/blocklets/time +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -use POSIX qw/strftime/; - -my $click = $ENV{BLOCK_BUTTON} || 0; -my $format = $ENV{BLOCK_INSTANCE} || $ENV{STRFTIME_FORMAT} || "%H:%M"; -my $tz_file = shift || $ENV{TZ_FILE} || "$ENV{HOME}/.tz"; -$tz_file = glob($tz_file); -my $default_tz = get_default_tz(); - -my $tzones = $ENV{TZONES} || '$DEFAULT_TZ'; -$tzones =~ s/\$DEFAULT_TZ/$default_tz/g; -my @tz_list = split(/,/, $tzones); -my @tz_labels = split(/,/, $ENV{TZ_LABELS} || ""); -if (scalar(@tz_list) != scalar(@tz_labels)) { - @tz_labels = @tz_list; -} - -my $current_tz; -if ($click == 1) { - $current_tz = get_tz(); - - my %tzmap; - $tzmap{""} = $tz_list[0]; - my $prev = $tz_list[0]; - foreach my $tz (@tz_list) { - $tzmap{$prev} = $tz; - $prev = $tz; - } - $tzmap{$prev} = $tz_list[0]; - - if (exists $tzmap{$current_tz}) { - set_tz($tzmap{$current_tz}); - $current_tz = $tzmap{$current_tz}; - } -} - -# How each timezone will be displayed in the bar. -my %display_map; -for (my $i=0; $i < scalar(@tz_list); $i++) { - $display_map{$tz_list[$i]} = $tz_labels[$i]; -} - -if (!defined $current_tz) { - $current_tz = get_tz(); - set_tz($current_tz); -} -$ENV{TZ} = $current_tz; -my $tz_display = ""; -if (!exists $display_map{$ENV{TZ}}) { - $ENV{TZ} = $tz_list[0]; - set_tz($tz_list[0]); -} -$tz_display = $display_map{$ENV{TZ}}; - -my $time = strftime($format, localtime()); -if ($tz_display eq "") { - print "$time\n"; -} else { - print "$time ($tz_display)\n"; -} - -sub get_tz { - my $current_tz; - - if (-f $tz_file) { - open my $fh, '<', $tz_file || die "Couldn't open file: $tz_file"; - $current_tz = <$fh>; - chomp $current_tz; - close $fh; - } - - return $current_tz || get_default_tz(); -} - -sub set_tz { - my $tz = shift; - - open my $fh, '>', $tz_file || die "Couldn't open file: $tz_file"; - print $fh $tz; - close $fh; -} - -sub get_default_tz { - my $tz = "Europe/London"; - - if (-f "/etc/timezone") { - open my $fh, '<', "/etc/timezone" || die "Couldn't open file: /etc/timezone"; - $tz = <$fh>; - chomp $tz; - close $fh; - } elsif (-l "/etc/localtime") { - $tz = readlink "/etc/localtime"; - $tz = (split /zoneinfo\//, $tz)[-1]; - } - - return $tz; -} diff --git a/.local/bin/blocklets/volume b/.local/bin/blocklets/volume deleted file mode 100755 index ad1b2d1..0000000 --- a/.local/bin/blocklets/volume +++ /dev/null @@ -1,175 +0,0 @@ -#!/bin/bash -# Displays the default device, volume, and mute status for i3blocks - -set -a - -AUDIO_HIGH_SYMBOL=${AUDIO_HIGH_SYMBOL:-' '} - -AUDIO_MED_THRESH=${AUDIO_MED_THRESH:-50} -AUDIO_MED_SYMBOL=${AUDIO_MED_SYMBOL:-' '} - -AUDIO_LOW_THRESH=${AUDIO_LOW_THRESH:-0} -AUDIO_LOW_SYMBOL=${AUDIO_LOW_SYMBOL:-' '} - -AUDIO_MUTED_SYMBOL=${AUDIO_MUTED_SYMBOL:-' '} - -AUDIO_DELTA=${AUDIO_DELTA:-5} - -DEFAULT_COLOR=${DEFAULT_COLOR:-"#ffffff"} -MUTED_COLOR=${MUTED_COLOR:-"#a0a0a0"} - -LONG_FORMAT=${LONG_FORMAT:-'${SYMB} ${VOL}% [${INDEX}:${NAME}]'} -SHORT_FORMAT=${SHORT_FORMAT:-'${SYMB} ${VOL}% [${INDEX}]'} -USE_ALSA_NAME=${USE_ALSA_NAME:-0} -USE_DESCRIPTION=${USE_DESCRIPTION:-0} - -SUBSCRIBE=${SUBSCRIBE:-0} - -MIXER=${MIXER:-""} -SCONTROL=${SCONTROL:-""} - -while getopts F:Sf:adH: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" ;; - 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" ;; - C) DEFAULT_COLOR="$OPTARG" ;; - c) MUTED_COLOR="$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, with exposed variables: -\${SYMB}, \${VOL}, \${INDEX}, \${NAME} --S\tSubscribe to volume events (requires persistent block, always uses long format) --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 --C\tColor for non-muted audio. Default: $DEFAULT_COLOR --c\tColor for muted audio. Default: $MUTED_COLOR --i\tInterval size of volume increase/decrease. Default: $AUDIO_DELTA --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_DELTA%+ ;; - 5) amixer -q -D $MIXER sset $SCONTROL $CAPABILITY $AUDIO_DELTA%- ;; -esac - -function print_format { - echo "$1" | envsubst '${SYMB}${VOL}${INDEX}${NAME}' -} - -function print_block { - ACTIVE=$(pacmd list-sinks | grep "state\: RUNNING" -B4 -A7 | grep "index:\|name:\|volume: front\|muted:") - [ -z "$ACTIVE" ] && ACTIVE=$(pacmd list-sinks | grep "index:\|name:\|volume: front\|muted:" | grep -A3 '*') - for name in INDEX NAME VOL MUTED; do - read $name - done < <(echo "$ACTIVE") - 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 - SYMB=$AUDIO_HIGH_SYMBOL - [[ $VOL -le $AUDIO_MED_THRESH ]] && SYMB=$AUDIO_MED_SYMBOL - [[ $VOL -le $AUDIO_LOW_THRESH ]] && SYMB=$AUDIO_LOW_SYMBOL - COLOR=$DEFAULT_COLOR - else - SYMB=$AUDIO_MUTED_SYMBOL - COLOR=$MUTED_COLOR - fi - - if [[ $SUBSCRIBE == 1 ]] ; then - print_format "$LONG_FORMAT" - else - print_format "$LONG_FORMAT" - print_format "$SHORT_FORMAT" - echo "$COLOR" - 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/.local/bin/blocks/calendar b/.local/bin/blocks/calendar new file mode 100755 index 0000000..eb8e210 --- /dev/null +++ b/.local/bin/blocks/calendar @@ -0,0 +1,41 @@ +#! /bin/sh + +WIDTH=${WIDTH:-200} +HEIGHT=${HEIGHT:-200} +DATEFMT=${DATEFMT:-"+%a %d.%m.%Y %H:%M:%S"} +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 + # The size is hardcoded for a 1080p monitor. + posX=$((1899 - $WIDTH)) + posY=$((35)) + + 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/.local/bin/blocks/cpu b/.local/bin/blocks/cpu new file mode 100755 index 0000000..44c1189 --- /dev/null +++ b/.local/bin/blocks/cpu @@ -0,0 +1,62 @@ +#!/usr/bin/perl +# +# Copyright 2014 Pierre Mavro +# Copyright 2014 Vivien Didelot +# Copyright 2014 Andreas Guldstrand +# +# 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 = $ENV{T_WARN} // 50; +my $t_crit = $ENV{T_CRIT} // 80; +my $cpu_usage = -1; +my $decimals = $ENV{DECIMALS} // 2; +my $label = $ENV{LABEL} // ""; + +sub help { + print "Usage: cpu_usage [-w ] [-c ] [-d ]\n"; + print "-w : warning threshold to become yellow\n"; + print "-c : critical threshold to become red\n"; + print "-d : Use 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 () { + 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 +print "${label}"; +printf "%.${decimals}f%%\n", $cpu_usage; +print "${label}"; +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/.local/bin/blocks/gpu b/.local/bin/blocks/gpu new file mode 100755 index 0000000..e5e460b --- /dev/null +++ b/.local/bin/blocks/gpu @@ -0,0 +1,71 @@ +#! /usr/bin/perl + +# 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; + +# default values +my $t_warn = $ENV{T_WARN} || 70; +my $t_crit = $ENV{T_CRIT} || 90; +my $gpu_usage = -1; +my $gpu_mem = -1; +my $gpu_video = -1; +my $gpu_pcie = -1; +my $label = $ENV{LABEL} // ""; + +sub help { + print "Usage: gpu-load [-w ] [-c ]\n"; + print "-w : warning threshold to become amber\n"; + print "-c : critical threshold to become red\n"; + exit 0; +} + +GetOptions("help|h" => \&help, + "w=i" => \$t_warn, + "c=i" => \$t_crit); + +# Get GPU usage from nvidia-settings +open (NVS, 'nvidia-settings -q GPUUtilization -t |') or die; +while () { + if (/^[a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+), [a-zA-Z]*=(\d+)$/) { + $gpu_usage = $1; + $gpu_mem = $2; + $gpu_video = $3; + $gpu_pcie = $4; + last; + } +} +close(NVS); + +$gpu_usage eq -1 and die 'Can\'t find GPU information'; + +# I edited this to only show the gpu_usage and gpu_mem. +# Also fixed the label thing. +# Print full_text, short_text +# printf "%.0f%% %.0f%% %.0f%% %.0f%%\n", $gpu_usage, $gpu_mem, $gpu_video, $gpu_pcie; +# printf "%.0f%%\n", $gpu_usage; +printf "${label} %.0f%% %.0f%%\n", $gpu_usage, $gpu_mem; + +# Print color, if needed +if ($gpu_usage >= $t_crit || $gpu_mem >= $t_crit || $gpu_video >= $t_crit || $gpu_pcie >= $t_crit) { + print "#FF0000\n"; + exit 33; +} elsif ($gpu_usage >= $t_warn || $gpu_mem >= $t_warn || $gpu_video >= $t_warn || $gpu_pcie >= $t_warn) { + print "#FFBF00\n"; +} + +exit 0; diff --git a/.local/bin/blocks/memory b/.local/bin/blocks/memory new file mode 100755 index 0000000..90eb2c6 --- /dev/null +++ b/.local/bin/blocks/memory @@ -0,0 +1,69 @@ +#!/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 { + 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("%.1fG/%.1fG (%.f%%)\n", used, total, pct) + + # short text + printf("%.f%%\n", pct) + + # color + if (pct > 90) { + print("#FF0000") + } else if (pct > 80) { + print("#FFAE00") + } else if (pct > 70) { + print("#FFF600") + } +} +' /proc/meminfo diff --git a/.local/bin/blocks/time b/.local/bin/blocks/time new file mode 100755 index 0000000..725fc68 --- /dev/null +++ b/.local/bin/blocks/time @@ -0,0 +1,100 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use POSIX qw/strftime/; + +my $click = $ENV{BLOCK_BUTTON} || 0; +my $format = $ENV{BLOCK_INSTANCE} || $ENV{STRFTIME_FORMAT} || "%H:%M"; +my $tz_file = shift || $ENV{TZ_FILE} || "$ENV{HOME}/.tz"; +$tz_file = glob($tz_file); +my $default_tz = get_default_tz(); + +my $tzones = $ENV{TZONES} || '$DEFAULT_TZ'; +$tzones =~ s/\$DEFAULT_TZ/$default_tz/g; +my @tz_list = split(/,/, $tzones); +my @tz_labels = split(/,/, $ENV{TZ_LABELS} || ""); +if (scalar(@tz_list) != scalar(@tz_labels)) { + @tz_labels = @tz_list; +} + +my $current_tz; +if ($click == 1) { + $current_tz = get_tz(); + + my %tzmap; + $tzmap{""} = $tz_list[0]; + my $prev = $tz_list[0]; + foreach my $tz (@tz_list) { + $tzmap{$prev} = $tz; + $prev = $tz; + } + $tzmap{$prev} = $tz_list[0]; + + if (exists $tzmap{$current_tz}) { + set_tz($tzmap{$current_tz}); + $current_tz = $tzmap{$current_tz}; + } +} + +# How each timezone will be displayed in the bar. +my %display_map; +for (my $i=0; $i < scalar(@tz_list); $i++) { + $display_map{$tz_list[$i]} = $tz_labels[$i]; +} + +if (!defined $current_tz) { + $current_tz = get_tz(); + set_tz($current_tz); +} +$ENV{TZ} = $current_tz; +my $tz_display = ""; +if (!exists $display_map{$ENV{TZ}}) { + $ENV{TZ} = $tz_list[0]; + set_tz($tz_list[0]); +} +$tz_display = $display_map{$ENV{TZ}}; + +my $time = strftime($format, localtime()); +if ($tz_display eq "") { + print "$time\n"; +} else { + print "$time ($tz_display)\n"; +} + +sub get_tz { + my $current_tz; + + if (-f $tz_file) { + open my $fh, '<', $tz_file || die "Couldn't open file: $tz_file"; + $current_tz = <$fh>; + chomp $current_tz; + close $fh; + } + + return $current_tz || get_default_tz(); +} + +sub set_tz { + my $tz = shift; + + open my $fh, '>', $tz_file || die "Couldn't open file: $tz_file"; + print $fh $tz; + close $fh; +} + +sub get_default_tz { + my $tz = "Europe/London"; + + if (-f "/etc/timezone") { + open my $fh, '<', "/etc/timezone" || die "Couldn't open file: /etc/timezone"; + $tz = <$fh>; + chomp $tz; + close $fh; + } elsif (-l "/etc/localtime") { + $tz = readlink "/etc/localtime"; + $tz = (split /zoneinfo\//, $tz)[-1]; + } + + return $tz; +} diff --git a/.local/bin/blocks/volume b/.local/bin/blocks/volume new file mode 100755 index 0000000..ad1b2d1 --- /dev/null +++ b/.local/bin/blocks/volume @@ -0,0 +1,175 @@ +#!/bin/bash +# Displays the default device, volume, and mute status for i3blocks + +set -a + +AUDIO_HIGH_SYMBOL=${AUDIO_HIGH_SYMBOL:-' '} + +AUDIO_MED_THRESH=${AUDIO_MED_THRESH:-50} +AUDIO_MED_SYMBOL=${AUDIO_MED_SYMBOL:-' '} + +AUDIO_LOW_THRESH=${AUDIO_LOW_THRESH:-0} +AUDIO_LOW_SYMBOL=${AUDIO_LOW_SYMBOL:-' '} + +AUDIO_MUTED_SYMBOL=${AUDIO_MUTED_SYMBOL:-' '} + +AUDIO_DELTA=${AUDIO_DELTA:-5} + +DEFAULT_COLOR=${DEFAULT_COLOR:-"#ffffff"} +MUTED_COLOR=${MUTED_COLOR:-"#a0a0a0"} + +LONG_FORMAT=${LONG_FORMAT:-'${SYMB} ${VOL}% [${INDEX}:${NAME}]'} +SHORT_FORMAT=${SHORT_FORMAT:-'${SYMB} ${VOL}% [${INDEX}]'} +USE_ALSA_NAME=${USE_ALSA_NAME:-0} +USE_DESCRIPTION=${USE_DESCRIPTION:-0} + +SUBSCRIBE=${SUBSCRIBE:-0} + +MIXER=${MIXER:-""} +SCONTROL=${SCONTROL:-""} + +while getopts F:Sf:adH: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" ;; + 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" ;; + C) DEFAULT_COLOR="$OPTARG" ;; + c) MUTED_COLOR="$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, with exposed variables: +\${SYMB}, \${VOL}, \${INDEX}, \${NAME} +-S\tSubscribe to volume events (requires persistent block, always uses long format) +-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 +-C\tColor for non-muted audio. Default: $DEFAULT_COLOR +-c\tColor for muted audio. Default: $MUTED_COLOR +-i\tInterval size of volume increase/decrease. Default: $AUDIO_DELTA +-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_DELTA%+ ;; + 5) amixer -q -D $MIXER sset $SCONTROL $CAPABILITY $AUDIO_DELTA%- ;; +esac + +function print_format { + echo "$1" | envsubst '${SYMB}${VOL}${INDEX}${NAME}' +} + +function print_block { + ACTIVE=$(pacmd list-sinks | grep "state\: RUNNING" -B4 -A7 | grep "index:\|name:\|volume: front\|muted:") + [ -z "$ACTIVE" ] && ACTIVE=$(pacmd list-sinks | grep "index:\|name:\|volume: front\|muted:" | grep -A3 '*') + for name in INDEX NAME VOL MUTED; do + read $name + done < <(echo "$ACTIVE") + 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 + SYMB=$AUDIO_HIGH_SYMBOL + [[ $VOL -le $AUDIO_MED_THRESH ]] && SYMB=$AUDIO_MED_SYMBOL + [[ $VOL -le $AUDIO_LOW_THRESH ]] && SYMB=$AUDIO_LOW_SYMBOL + COLOR=$DEFAULT_COLOR + else + SYMB=$AUDIO_MUTED_SYMBOL + COLOR=$MUTED_COLOR + fi + + if [[ $SUBSCRIBE == 1 ]] ; then + print_format "$LONG_FORMAT" + else + print_format "$LONG_FORMAT" + print_format "$SHORT_FORMAT" + echo "$COLOR" + 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/.local/bin/color_test b/.local/bin/color_test new file mode 100755 index 0000000..e89f24e --- /dev/null +++ b/.local/bin/color_test @@ -0,0 +1,41 @@ +#!/bin/sh +# +# This file echoes a bunch of color codes to the +# terminal to demonstrate what's available. Each +# line is the color code of one forground color, +# out of 17 (default + 16 escapes), followed by a +# test use of that color on all nine background +# colors (default + 8 escapes). +# +# Author: Giles Orr +# URL: http://gilesorr.com/bashprompt/howto/c350.html +# License: GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; +# http://gilesorr.com/bashprompt/howto/a1004.html + + +T='gYw' # The test text + +echo -e "\n 40m 41m 42m 43m\ + 44m 45m 46m 47m"; + +for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \ + '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \ + ' 36m' '1;36m' ' 37m' '1;37m'; + do FG=${FGs// /} + echo -en " $FGs \033[$FG $T " + for BG in 40m 41m 42m 43m 44m 45m 46m 47m; + do echo -en "$EINS \033[$FG\033[$BG $T \033[0m"; + done + echo; +done +echo + +echo -e "\e[0mCOLOR_NC (No color)" +echo -e "\e[1;37mCOLOR_WHITE\t\e[0;30mCOLOR_BLACK" +echo -e "\e[0;34mCOLOR_BLUE\t\e[1;34mCOLOR_LIGHT_BLUE" +echo -e "\e[0;32mCOLOR_GREEN\t\e[1;32mCOLOR_LIGHT_GREEN" +echo -e "\e[0;36mCOLOR_CYAN\t\e[1;36mCOLOR_LIGHT_CYAN" +echo -e "\e[0;31mCOLOR_RED\t\e[1;31mCOLOR_LIGHT_RED" +echo -e "\e[0;35mCOLOR_PURPLE\t\e[1;35mCOLOR_LIGHT_PURPLE" +echo -e "\e[0;33mCOLOR_YELLOW\t\e[1;33mCOLOR_LIGHT_YELLOW" +echo -e "\e[1;30mCOLOR_GRAY\t\e[0;37mCOLOR_LIGHT_GRAY" diff --git a/.local/bin/py/xcolors.py b/.local/bin/py/xcolors.py deleted file mode 100644 index 39010c7..0000000 --- a/.local/bin/py/xcolors.py +++ /dev/null @@ -1,55 +0,0 @@ -import os - -HOME=os.environ['HOME'] + '/' -XCDIR=f'{HOME}.config/xcolors/' -CSLIST=os.listdir(XCDIR) -XRPATH=f'{HOME}.Xresources' -ALPATH=f'{HOME}.config/alacritty/alacritty.yml' - - -def update_xresources(csname): - """ - Updates the ~/.Xresources file with new color scheme. - """ - if csname not in CSLIST: - return f"{csname} not in {XCDIR}" - - with open(XRPATH, 'r') as infile: - lines = infile.readlines() - - with open(file_dir, 'w') as outfile: - for i, line in enumerate(lines): - if i == 4: - nline = line.split('/') - nline[-1] = csname + '"\n' - nline = '/'.join(nline) - outfile.write(nline) - else: - outfile.write(line) - - -def update_alacritty(csname): - """ - Updates the ~/.config/alacritty/alacritty.yml file with new color scheme. - """ - if csname not in CSLIST: - return f"{csname} not in {XCDIR}" - - with open(ALPATH, 'r') as infile: - lines = infile.readlines() - - for line in lines: - if 'background' in line: - print(line) - - return None - - with open(file_dir, 'w') as outfile: - for i, line in enumerate(lines): - if i == 4: - nline = line.split('/') - nline[-1] = csname + '"\n' - nline = '/'.join(nline) - outfile.write(nline) - else: - outfile.write(line) diff --git a/.local/bin/pys/xcolors.py b/.local/bin/pys/xcolors.py new file mode 100644 index 0000000..39010c7 --- /dev/null +++ b/.local/bin/pys/xcolors.py @@ -0,0 +1,55 @@ +import os + +HOME=os.environ['HOME'] + '/' +XCDIR=f'{HOME}.config/xcolors/' +CSLIST=os.listdir(XCDIR) +XRPATH=f'{HOME}.Xresources' +ALPATH=f'{HOME}.config/alacritty/alacritty.yml' + + +def update_xresources(csname): + """ + Updates the ~/.Xresources file with new color scheme. + """ + if csname not in CSLIST: + return f"{csname} not in {XCDIR}" + + with open(XRPATH, 'r') as infile: + lines = infile.readlines() + + with open(file_dir, 'w') as outfile: + for i, line in enumerate(lines): + if i == 4: + nline = line.split('/') + nline[-1] = csname + '"\n' + nline = '/'.join(nline) + outfile.write(nline) + else: + outfile.write(line) + + +def update_alacritty(csname): + """ + Updates the ~/.config/alacritty/alacritty.yml file with new color scheme. + """ + if csname not in CSLIST: + return f"{csname} not in {XCDIR}" + + with open(ALPATH, 'r') as infile: + lines = infile.readlines() + + for line in lines: + if 'background' in line: + print(line) + + return None + + with open(file_dir, 'w') as outfile: + for i, line in enumerate(lines): + if i == 4: + nline = line.split('/') + nline[-1] = csname + '"\n' + nline = '/'.join(nline) + outfile.write(nline) + else: + outfile.write(line) -- cgit v1.2.3-54-g00ecf