From cbfd974f652a12c601a95ea6d364549f45cb87e3 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Mon, 6 Apr 2020 02:30:09 +0300 Subject: improved script for pacman package download cron job; waybar improvements --- dotfiles/.local/bin/bards4battery | 15 +++++++++++++++ dotfiles/.local/bin/barpacstatus | 16 ++++++++++++++++ dotfiles/.local/bin/paccheck | 10 ---------- dotfiles/.local/bin/pacsync | 27 +++++++++++++++++++++++++++ dotfiles/.local/bin/pacupgrade | 13 +++++++++++++ dotfiles/.local/bin/setsessionenv | 21 +++++++++++++++++++++ dotfiles/.local/bin/swaykbd | 8 +++----- 7 files changed, 95 insertions(+), 15 deletions(-) create mode 100755 dotfiles/.local/bin/bards4battery create mode 100755 dotfiles/.local/bin/barpacstatus delete mode 100755 dotfiles/.local/bin/paccheck create mode 100755 dotfiles/.local/bin/pacsync create mode 100755 dotfiles/.local/bin/pacupgrade create mode 100755 dotfiles/.local/bin/setsessionenv (limited to 'dotfiles/.local/bin') diff --git a/dotfiles/.local/bin/bards4battery b/dotfiles/.local/bin/bards4battery new file mode 100755 index 0000000..15ffb99 --- /dev/null +++ b/dotfiles/.local/bin/bards4battery @@ -0,0 +1,15 @@ +#!/bin/sh + +if [ -f /sys/class/power_supply/sony_controller_battery_*/capacity ]; then + percentage=$(cat /sys/class/power_supply/sony_controller_battery_*/capacity) + + if [ percentage -lt 40 ]; then + printf "%s%%" "$percentage" + exit + fi + if [ percentage -lt 20 ]; then + printf "%s%%" "$percentage" + exit + fi + printf "%s%%" "$percentage" +fi diff --git a/dotfiles/.local/bin/barpacstatus b/dotfiles/.local/bin/barpacstatus new file mode 100755 index 0000000..3a05525 --- /dev/null +++ b/dotfiles/.local/bin/barpacstatus @@ -0,0 +1,16 @@ +#!/bin/sh + +if [ -f ~/.cache/pacsynclive ]; then + echo "syncing" + exit +fi +if [ -f ~/.cache/pacupgradelive ]; then + echo "installing" + exit +fi + +upno=$(pacman -Qu | wc -l) + +if [ $upno -gt 0 ]; then + echo $upno +fi diff --git a/dotfiles/.local/bin/paccheck b/dotfiles/.local/bin/paccheck deleted file mode 100755 index 1284134..0000000 --- a/dotfiles/.local/bin/paccheck +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -ping -q -c 1 1.1.1.1 > /dev/null || exit - -notify-send "⬆ Update check" "Checking for updates..." - -sudo pacman -Sy -upno=$(pacman -Qu | wc -l) - -notify-send "⬆ Update Check" "$upno updates are available" diff --git a/dotfiles/.local/bin/pacsync b/dotfiles/.local/bin/pacsync new file mode 100755 index 0000000..30fc98c --- /dev/null +++ b/dotfiles/.local/bin/pacsync @@ -0,0 +1,27 @@ +#!/bin/sh + +if pidof pacman; then + exit +fi + +ping -q -c 1 1.1.1.1 > /dev/null || exit + +# Source the needed env variables so that it can function properly from cron +. ~/.cache/sessionenv + +notify-send " System upgrade" "Syncing repositories and downloading packages..." + +touch ~/.cache/pacsynclive +killall -41 waybar + +sudo pacman -Syuw --noconfirm || notify-send " System upgrade" \ + "Error downloading updates. Check your internet connection or that you have the required permissions" + +rm -f ~/.cache/pacsynclive +killall -41 waybar + +upno=$(pacman -Qu | wc -l) + +if [ $upno -lt 0 ]; then + notify-send " System upgrade" "Repository sync finished. $upno updates are available" +fi diff --git a/dotfiles/.local/bin/pacupgrade b/dotfiles/.local/bin/pacupgrade new file mode 100755 index 0000000..4aa4512 --- /dev/null +++ b/dotfiles/.local/bin/pacupgrade @@ -0,0 +1,13 @@ +#!/bin/sh + +if pidof pacman; then + exit +fi + +touch ~/.cache/pacupdatelive +killall -41 waybar + +sudo pacman -Syu + +rm -f ~/.cache/pacupdatelive +killall -41 waybar diff --git a/dotfiles/.local/bin/setsessionenv b/dotfiles/.local/bin/setsessionenv new file mode 100755 index 0000000..8d8459d --- /dev/null +++ b/dotfiles/.local/bin/setsessionenv @@ -0,0 +1,21 @@ +#!/bin/sh + +# Create a file with the env variables of the current wayland session so that +# cron scripts can source it and function properly + +printf "export DISPLAY=%s +export WAYLAND_DISPLAY=%s +export XDG_SESSION_ID=%s +export XDG_SESSION_CLASS=%s +export XDG_SEAT=%s +export XDG_RUNTIME_DIR=%s +export I3SOCK=%s +export SWAYSOCK=%s"\ + "$DISPLAY" \ + "$WAYLAND_DISPLAY" \ + "$XDG_SESSION_ID" \ + "$XDG_SESSION_CLASS" \ + "$XDG_SEAT" \ + "$XDG_RUNTIME_DIR" \ + "$I3SOCK" \ + "$SWAYSOCK" > ~/.cache/sessionenv diff --git a/dotfiles/.local/bin/swaykbd b/dotfiles/.local/bin/swaykbd index d90f78c..2ec42c3 100755 --- a/dotfiles/.local/bin/swaykbd +++ b/dotfiles/.local/bin/swaykbd @@ -3,7 +3,7 @@ swaymsg -r -t get_inputs | \ grep "xkb_active_layout_name" | \ awk -F '"' '{print $4}' | \ - sed 's/English (US)/🇺🇸 English/g;s/Spanish/🇲🇽 Español/g;s/Russian/🇷🇺 Русский/g' | head -1 + sed --unbuffered 's/English (US)/🇺🇸 EN/g;s/Spanish/🇲🇽 ES/g;s/Russian/🇷🇺 RU/g'| head -1 swaymsg \ --type subscribe \ @@ -14,8 +14,6 @@ swaymsg \ --raw-output \ --unbuffered \ ' select(.change == "xkb_layout") | - .input.xkb_active_layout_name | - sub(" \\(US\\)"; "") - ' | \ - sed --unbuffered 's/English/🇺🇸 English/g;s/Spanish/🇲🇽 Español/g;s/Russian/🇷🇺 Русский/g' + .input.xkb_active_layout_name' | \ + sed --unbuffered 's/English (US)/🇺🇸 EN/g;s/Spanish/🇲🇽 ES/g;s/Russian/🇷🇺 RU/g' -- cgit v1.2.3