You are not logged in.
Pages: 1
I was trying to customize the i3bar and i am using i3blocks. I will post all the steps because i might be dumber than i think so everything will be put on diplay
What i have in the i3blocks.conf is
# Global properties
24 #
25 # The top properties below are applied to every bl>
26 # Each block command defaults to the script name t>
27 #command=/usr/lib/i3blocks/$BLOCK_NAME
28 #command=~/codes/i3blocks/$BLOCK_NAME
29 separator_block_width=15
30 markup=none
31
32 [cpu_usage]
33 command=~/codes/i3blocks/cpu_usage
34 interval=10
35 LABEL=CPU
36 #min_width=CPU: 100.00%
37 #T_WARN=50
38 #T_CRIT=80
39 #DECIMALS=2
40
41 [volume]
42 command=~/codes/i3blocks/volume
43 interval=persist
44 signal=1
45 MIXER=[determined automatically]
46 SCONTROL=[determined automatically]
47 exposed format variables: ${SYMB}, ${VOL}, ${INDEX>
48 LONG_FORMAT="${SYMB} ${VOL}% [${INDEX}:${NAME}]"
49 SHORT_FORMAT="${SYMB} ${VOL}% [${INDEX}]"
50 AUDIO_HIGH_SYMBOL=' '
51 AUDIO_MED_THRESH=50
52 AUDIO_MED_SYMBOL=' '
53 AUDIO_LOW_THRESH=0
54 AUDIO_LOW_SYMBOL=' '
55 AUDIO_DELTA=5
56 DEFAULT_COLOR="#ffffff"
57 MUTED_COLOR="#a0a0a0"
58 USE_ALSA_NAME=0
59 USE_DESCRIPTION=0
60 SUBSCRIBE=1 requires interval=persist and always u>
61 #SUBSCRIBE=0The cpu_usage scipt is the following
#!/bin/bash
#
# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
# Copyright 2014 Vivien Didelot <vivien@didelot.org>
# Copyright 2014 Andreas Guldstrand <andreas.guldstra>
#
# Licensed under the terms of the GNU GPL v3, or any >
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 <warning>] [-c <criti>
print "-w <percent>: warning threshold to become >
print "-c <percent>: critical threshold to become>
print "-d <decimals>: Use <decimals> decimals fo>
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>
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
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;This is what's in the volume script
#!/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\|mono\)\|muted:")
[ -z "$ACTIVE" ] && ACTIVE=$(pacmd list-sinks | grep "index:\|name:\|volume: \(front\|mono\)\|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)
fiIn the logs it says
04/21/2021 03:13:38 PM - ../src/commands.c:cmd_criteria_init:148 - Initializing criteria, current_match = 0x555b0b032680
04/21/2021 03:13:38 PM - ../src/handlers.c:handle_event:1271 - event type 28, xkb_base 85I got the logs by using
DISPLAY=:0 i3-dump-log | bzip2 -c | curl --data-binary @- [url]https://logs.i3wm.org[/url]Last edited by BadMed (2021-04-21 13:25:16)
Offline
Try running i3bar/i3blocks from an interactive shell, it'll likely yell an error.
I don't use i3blocks but this looks bad
60 SUBSCRIBE=1 requires interval=persist and always u>Like, "really bad".
Offline
I used fish for this
For the cpu_usage script it says:
cpu_usage (line 55): Missing end to balance this if statement
if ($cpu_usage >= $t_crit) {
^
warning: Error while reading file cpu_usageAnd for volume it says this
volume (line 7): Unsupported use of '='. In fish, please use 'set AUDIO_HIGH_SYMBOL ${AUDIO_HIGH_SYMBOL:-' '}'.
warning: Error while reading file volumeFo the i3blocks.conf it says
i3blocks.conf (line 28): Unsupported use of '='. In fish, please use 'set command ~/codes/i3blocks/$BLOCK_NAME'.
warning: Error while reading file i3blocks.confIt's strange seeing that these scripts are faulty, because i downloaded them from the i3blocks github page
Last edited by BadMed (2021-04-21 17:05:23)
Offline
- "elsif" is wrong, it's "elif"
- fish isn't bash and the "foo=bar" syntax is not supported, that should not matter because the script has a bash shebang.
- You're not supposed to run the config file in an interactive shell, but i3blocks - it'll parse the config and hopefully tell you what's bad
Offline
Sorry about the last post
I ran i3blocks and it didn't give any error
AN error appeard when i ran i3bar
[../i3bar/src/main.c:139] ERROR: No bar_id passed. Please let i3 start i3bar or specify --bar_idOffline
Did you fix the "elsif" in cpu_usage?
What is the "60 SUBSCRIBE=1 requires interval=persist and always u>" line supposed to do/be?
Offline
Pages: 1