From eaf92a34bb40d364405c823baa4047466e7c2217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Tue, 17 Nov 2015 19:51:11 +0100 Subject: [PATCH 1/2] Add some i3bar options. --- i3/i3/config | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/i3/i3/config b/i3/i3/config index 6f893a0..f518db2 100644 --- a/i3/i3/config +++ b/i3/i3/config @@ -283,6 +283,11 @@ bar { position top tray_output primary + tray_padding 3 + + strip_workspace_numbers no + + binding_mode_indicator yes workspace_buttons yes @@ -299,6 +304,7 @@ bar { active_workspace #000000 #5f676a #ffffff inactive_workspace #000000 #000000 #dddddd urgent_workspace #D00000 #D00000 #000000 + binding_mode #000000 #e16b40 #000000 } i3bar_command i3bar From acbb6b327579d48ab81dd4482d8883ea4c2a50ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Mon, 30 Nov 2015 23:38:00 +0100 Subject: [PATCH 2/2] Refactor battery script. --- i3/i3/scripts/battery | 151 +++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 77 deletions(-) diff --git a/i3/i3/scripts/battery b/i3/i3/scripts/battery index db8febe..59b9ff8 100755 --- a/i3/i3/scripts/battery +++ b/i3/i3/scripts/battery @@ -1,99 +1,96 @@ #!/bin/bash -# shitty. this is used for both creating a part of the status conkyrc AND for -# creating nice output if you click on the status bar -# what i done depends on the first paramter - rundir="$RUNDIR/batwarn" logfile="$LOGDIR/batwarn.log" -[[ ! -d "$rundir" ]] && mkdir -p "$rundir" +_PATH_WARN_1="$rundir/batwarn1" +_PATH_WARN_2="$rundir/batwarn2" -PATH_WARN_1="$rundir/batwarn1" -PATH_WARN_2="$rundir/batwarn2" - -THRESHOLD1=25 -THRESHOLD2=5 +_THRESHOLD1=25 +_THRESHOLD2=5 acpi_output=$(acpi -b) + +log() { + printf '%s\n' "[$(date +%FT%T)] $*" >> $logfile +} + +charging() { + [[ "$status" == "C" ]] +} + +discharging() { + [[ "$status" == "D" ]] +} + +threshold1() { + (( $percent <= $_THRESHOLD1 )) +} + +threshold2() { + (( $percent <= $_THRESHOLD2 )) +} + +notify_threshold1() { + notify-send --icon dialog-warning "Battery below ${_THRESHOLD2}%" --expire-time 0 +} + +notify_threshold2() { + notify-send --icon dialog-warning "Battery below ${_THRESHOLD1}%" --expire-time 30000 +} + if [[ -n "$acpi_output" ]] ; then has_battery=1 - percent="$(echo "$acpi_output" | grep -oP '\d+(?=%)')" + percent="$(printf '%s' "$acpi_output" | grep -oP '\d+(?=%)')" if [[ $percent == 100 ]] ; then - status="Full" + status="F" else - status="$(echo "$acpi_output" | grep -oP '(?<=: )\w+(?=,)' )" + status="$(printf '%s' "$acpi_output" | grep -oP '(?<=: )\w+(?=,)' | cut -c 1 )" fi - shortstatus="$(echo $status | cut -c 1)" else has_battery=0 fi -log() { - echo [$(date +%FT%T)] "$*" >> $logfile -} - -charging() { - [[ "$shortstatus" == "C" ]] -} - -discharging() { - [[ "$shortstatus" == "D" ]] -} - -threshold1() { - (( $percent <= $THRESHOLD1 )) -} - -threshold2() { - (( $percent <= $THRESHOLD2 )) -} - -short() { - if (( has_battery )) ; then - if discharging ; then - if threshold2 ; then - if [[ ! -f "$PATH_WARN_2" ]] ; then - log "battery fell below $THRESHOLD2 percent. issuing warning." - echo > "$PATH_WARN_2" - notify-send --icon dialog-warning "Battery below ${THRESHOLD2}%" --expire-time 0 - fi - elif threshold1 ; then - if [[ ! -f "$PATH_WARN_1" ]] ; then - log "battery fell below $THRESHOLD1 percent. issuing warning." - echo > "$PATH_WARN_1" - notify-send --icon dialog-warning "Battery below ${THRESHOLD1}%" --expire-time 30000 - fi - fi - fi - - if charging ; then - if [[ -f "$PATH_WARN_1" ]] ; then - log "charging now. resetting warnings." - rm "$PATH_WARN_1" - fi - [[ -f "$PATH_WARN_2" ]] && rm "$PATH_WARN_2" - fi - +if (( has_battery )) ; then + if discharging ; then if threshold2 ; then - color="#FF0000" # red - urgent=1 + if [[ ! -f "$_PATH_WARN_2" ]] ; then + log "battery fell below $_THRESHOLD2 percent. issuing warning." + touch "$_PATH_WARN_2" + notify_threshold1 + fi elif threshold1 ; then - color="#FFFF00" # yellow - urgent=0 - else - color="#FFFFFF" # white - urgent=0 + if [[ ! -f "$_PATH_WARN_1" ]] ; then + log "battery fell below $_THRESHOLD1 percent. issuing warning." + touch "$_PATH_WARN_1" + notify_threshold2 + fi fi - - echo "${shortstatus} ${percent}%" - echo - echo $color - (( $urgent )) && exit 33 - exit 0 - else - echo "no battery" + elif charging ; then + if [[ -f "$_PATH_WARN_1" ]] ; then + log "charging now. resetting warnings." + rm "$_PATH_WARN_1" + fi + [[ -f "$_PATH_WARN_2" ]] && rm "$_PATH_WARN_2" fi -} -short + if threshold2 ; then + color="#FF0000" # red + urgent=1 + elif threshold1 ; then + color="#FFFF00" # yellow + urgent=0 + else + color="#FFFFFF" # white + urgent=0 + fi + + printf '%s\n' "${status} ${percent}%" + printf '%s\n' + printf '%s\n' $color + (( $urgent )) && exit 33 +else + printf '%s\n' "no battery" + printf '%s\n' + printf '%s\n' "#FFFFFF" +fi