summaryrefslogtreecommitdiff
path: root/dot-config/bspwm/themes/hack/polybar/scripts
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-06-03 19:56:39 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-06-03 19:56:39 +0800
commitca968c4e5040f1ff4b5b5e12d9312360d807dcc1 (patch)
tree9900920e8f566794560c1519678e344351d2803b /dot-config/bspwm/themes/hack/polybar/scripts
parent5f3deaff0bf006a1a353e57b82ad48c0e8f143bc (diff)
added submodules, change . -> dot (see man stow --dotfiles)
Diffstat (limited to 'dot-config/bspwm/themes/hack/polybar/scripts')
-rwxr-xr-xdot-config/bspwm/themes/hack/polybar/scripts/check-network21
-rwxr-xr-xdot-config/bspwm/themes/hack/polybar/scripts/checkupdates117
-rwxr-xr-xdot-config/bspwm/themes/hack/polybar/scripts/updates.sh47
3 files changed, 185 insertions, 0 deletions
diff --git a/dot-config/bspwm/themes/hack/polybar/scripts/check-network b/dot-config/bspwm/themes/hack/polybar/scripts/check-network
new file mode 100755
index 00000000..f7dd0a36
--- /dev/null
+++ b/dot-config/bspwm/themes/hack/polybar/scripts/check-network
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+## Copyright (C) 2020-2022 Aditya Shakya <adi1090x@gmail.com>
+
+count=0
+connected="說"
+disconnected="ﲁ"
+
+ID="$(ip link | awk '/state UP/ {print $2}')"
+
+while true; do
+ if (ping -c 1 archlinux.org || ping -c 1 google.com || ping -c 1 bitbucket.org || ping -c 1 github.com || ping -c 1 sourceforge.net) &>/dev/null; then
+ if [[ $ID == e* ]]; then
+ echo "$connected Online" ; sleep 25
+ else
+ echo "$connected Online" ; sleep 25
+ fi
+ else
+ echo "$disconnected Offline" ; sleep 5
+ fi
+done
diff --git a/dot-config/bspwm/themes/hack/polybar/scripts/checkupdates b/dot-config/bspwm/themes/hack/polybar/scripts/checkupdates
new file mode 100755
index 00000000..4d8a5e81
--- /dev/null
+++ b/dot-config/bspwm/themes/hack/polybar/scripts/checkupdates
@@ -0,0 +1,117 @@
+#!/usr/bin/bash
+#
+# checkupdates: Safely print a list of pending updates.
+#
+# Copyright (c) 2013 Kyle Keen <keenerd@gmail.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 2 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/>.
+#
+
+declare -r myname='checkupdates'
+declare -r myver='1.0.0'
+
+plain() {
+ (( QUIET )) && return
+ local mesg=$1; shift
+ printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1
+}
+
+msg() {
+ (( QUIET )) && return
+ local mesg=$1; shift
+ printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1
+}
+
+msg2() {
+ (( QUIET )) && return
+ local mesg=$1; shift
+ printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&1
+}
+
+ask() {
+ local mesg=$1; shift
+ printf "${BLUE}::${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}" "$@" >&1
+}
+
+warning() {
+ local mesg=$1; shift
+ printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+error() {
+ local mesg=$1; shift
+ printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+# check if messages are to be printed using color
+unset ALL_OFF BOLD BLUE GREEN RED YELLOW
+if [[ -t 2 && ! $USE_COLOR = "n" ]]; then
+ # prefer terminal safe colored and bold text when tput is supported
+ if tput setaf 0 &>/dev/null; then
+ ALL_OFF="$(tput sgr0)"
+ BOLD="$(tput bold)"
+ BLUE="${BOLD}$(tput setaf 4)"
+ GREEN="${BOLD}$(tput setaf 2)"
+ RED="${BOLD}$(tput setaf 1)"
+ YELLOW="${BOLD}$(tput setaf 3)"
+ else
+ ALL_OFF="\e[1;0m"
+ BOLD="\e[1;1m"
+ BLUE="${BOLD}\e[1;34m"
+ GREEN="${BOLD}\e[1;32m"
+ RED="${BOLD}\e[1;31m"
+ YELLOW="${BOLD}\e[1;33m"
+ fi
+fi
+readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
+
+
+if (( $# > 0 )); then
+ echo "${myname} v${myver}"
+ echo
+ echo "Safely print a list of pending updates"
+ echo
+ echo "Usage: ${myname}"
+ echo
+ echo 'Note: Export the "CHECKUPDATES_DB" variable to change the path of the temporary database.'
+ exit 0
+fi
+
+if ! type -P fakeroot >/dev/null; then
+ error 'Cannot find the fakeroot binary.'
+ exit 1
+fi
+
+if [[ -z $CHECKUPDATES_DB ]]; then
+ CHECKUPDATES_DB="${TMPDIR:-/tmp}/checkup-db-${USER}/"
+fi
+
+trap 'rm -f $CHECKUPDATES_DB/db.lck' INT TERM EXIT
+
+DBPath="$(pacman-conf DBPath)"
+if [[ -z "$DBPath" ]] || [[ ! -d "$DBPath" ]]; then
+ DBPath="/var/lib/pacman/"
+fi
+
+mkdir -p "$CHECKUPDATES_DB"
+ln -s "${DBPath}/local" "$CHECKUPDATES_DB" &> /dev/null
+if ! fakeroot -- pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null &> /dev/null; then
+ error 'Cannot fetch updates'
+ exit 1
+fi
+pacman -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]'
+
+exit 0
+
+# vim: set noet:
diff --git a/dot-config/bspwm/themes/hack/polybar/scripts/updates.sh b/dot-config/bspwm/themes/hack/polybar/scripts/updates.sh
new file mode 100755
index 00000000..105584a2
--- /dev/null
+++ b/dot-config/bspwm/themes/hack/polybar/scripts/updates.sh
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+
+## Copyright (C) 2020-2022 Aditya Shakya <adi1090x@gmail.com>
+
+NOTIFY_ICON=/usr/share/icons/Papirus/32x32/apps/system-software-update.svg
+
+get_total_updates() { UPDATES=$(checkupdates 2>/dev/null | wc -l); }
+
+while true; do
+ get_total_updates
+
+ # notify user of updates
+ if hash notify-send &>/dev/null; then
+ if (( UPDATES > 50 )); then
+ notify-send -u critical -i $NOTIFY_ICON \
+ "You really need to update!!" "$UPDATES New packages"
+ elif (( UPDATES > 25 )); then
+ notify-send -u normal -i $NOTIFY_ICON \
+ "You should update soon" "$UPDATES New packages"
+ elif (( UPDATES > 2 )); then
+ notify-send -u low -i $NOTIFY_ICON \
+ "$UPDATES New packages"
+ fi
+ fi
+
+ # when there are updates available
+ # every 10 seconds another check for updates is done
+ while (( UPDATES > 0 )); do
+ if (( UPDATES == 1 )); then
+ echo " $UPDATES"
+ elif (( UPDATES > 1 )); then
+ echo " $UPDATES"
+ else
+ echo " None"
+ fi
+ sleep 10
+ get_total_updates
+ done
+
+ # when no updates are available, use a longer loop, this saves on CPU
+ # and network uptime, only checking once every 30 min for new updates
+ while (( UPDATES == 0 )); do
+ echo " None"
+ sleep 1800
+ get_total_updates
+ done
+done