Add new scripts for system monitoring and remove deprecated scripts

This commit is contained in:
2025-03-14 09:13:55 +00:00
parent d29b44e783
commit bde27ebfb1
20 changed files with 7 additions and 1740 deletions

View File

@@ -111,6 +111,7 @@ if [[ "$OSTYPE" != "darwin"* ]]; then
sudo ufw limit 22/tcp
fi
sudo ufw enable
sudo ss -tupln | tee "$HOME/dotfiles/logs/open_ports.log"
sudo ufw status numbered | tee "$HOME/dotfiles/logs/ufw_status.log"
if [ $? -ne 0 ]; then
printf "${RED}Error setting up UFW.${NC}\n"

View File

@@ -1 +0,0 @@
upower -i /org/freedesktop/UPower/devices/* | grep "capacity:"

View File

@@ -1,412 +0,0 @@
#!/usr/bin/env bash
# _ _ _ _ _ _
# __| |_ __ ___ ___ _ __ _ _ | |__ | |_ _ ___| |_ ___ ___ | |_ | |__
# / _` | '_ ` _ \ / _ \ '_ \| | | |_____| '_ \| | | | |/ _ \ __/ _ \ / _ \| __|| '_ \
# | (_| | | | | | | __/ | | | |_| |_____| |_) | | |_| | __/ || (_) | (_) | |_ | | | |
# \__,_|_| |_| |_|\___|_| |_|\__,_| |_.__/|_|\__,_|\___|\__\___/ \___/ \__||_| |_|
#
# Author: Nick Clyde (clydedroid)
# dmenu support by: Layerex
# Original script: https://github.com/nickclyde/rofi-bluetooth
#
# A script that generates a dmenu menu that uses bluetoothctl to
# connect to bluetooth devices and display status info.
#
# Inspired by networkmanager-dmenu (https://github.com/firecat53/networkmanager-dmenu)
# Thanks to x70b1 (https://github.com/polybar/polybar-scripts/tree/master/polybar-scripts/system-bluetooth-bluetoothctl)
#
# Depends on:
# Arch repositories: dmenu, bluez-utils (contains bluetoothctl)
# Constants
divider="---------"
goback="Back"
exit="Exit"
connected_icon=""
# Checks if bluetooth controller is powered on
power_on() {
if bluetoothctl show | grep -F -q "Powered: yes"; then
return 0
else
return 1
fi
}
# Toggles power state
toggle_power() {
if power_on; then
bluetoothctl power off
show_menu
else
if rfkill list bluetooth | grep -F -q 'blocked: yes'; then
rfkill unblock bluetooth && sleep 3
fi
bluetoothctl power on
show_menu
fi
}
# Checks if controller is scanning for new devices
scan_on() {
if bluetoothctl show | grep -F -q "Discovering: yes"; then
echo "Scan: on"
return 0
else
echo "Scan: off"
return 1
fi
}
# Toggles scanning state
toggle_scan() {
if scan_on; then
kill "$(pgrep -f "bluetoothctl scan on")"
bluetoothctl scan off
show_menu
else
bluetoothctl scan on &
echo "Scanning..."
sleep 5
show_menu
fi
}
# Checks if controller is able to pair to devices
pairable_on() {
if bluetoothctl show | grep -F -q "Pairable: yes"; then
echo "Pairable: on"
return 0
else
echo "Pairable: off"
return 1
fi
}
# Toggles pairable state
toggle_pairable() {
if pairable_on; then
bluetoothctl pairable off
show_menu
else
bluetoothctl pairable on
show_menu
fi
}
# Checks if controller is discoverable by other devices
discoverable_on() {
if bluetoothctl show | grep -F -q "Discoverable: yes"; then
echo "Discoverable: on"
return 0
else
echo "Discoverable: off"
return 1
fi
}
# Toggles discoverable state
toggle_discoverable() {
if discoverable_on; then
bluetoothctl discoverable off
show_menu
else
bluetoothctl discoverable on
show_menu
fi
}
# Checks if a device is connected
device_connected() {
if bluetoothctl info "$1" | grep -F -q "Connected: yes"; then
return 0
else
return 1
fi
}
# Toggles device connection
toggle_connection() {
if device_connected "$1"; then
bluetoothctl disconnect "$1"
# device_menu "$device"
else
bluetoothctl connect "$1"
# device_menu "$device"
fi
}
# Checks if a device is paired
device_paired() {
if bluetoothctl info "$1" | grep -F -q "Paired: yes"; then
echo "Paired: yes"
return 0
else
echo "Paired: no"
return 1
fi
}
# Toggles device paired state
toggle_paired() {
if device_paired "$1"; then
bluetoothctl remove "$1"
device_menu "$device"
else
bluetoothctl pair "$1"
device_menu "$device"
fi
}
# Checks if a device is trusted
device_trusted() {
if bluetoothctl info "$1" | grep -F -q "Trusted: yes"; then
echo "Trusted: yes"
return 0
else
echo "Trusted: no"
return 1
fi
}
# Toggles device connection
toggle_trust() {
if device_trusted "$1"; then
bluetoothctl untrust "$1"
device_menu "$device"
else
bluetoothctl trust "$1"
device_menu "$device"
fi
}
# Prints a short string with the current bluetooth status
# Useful for status bars like polybar, etc.
print_status() {
if power_on; then
printf ''
mapfile -t paired_devices < <(bluetoothctl paired-devices | grep -F Device | cut -d ' ' -f 2)
counter=0
for device in "${paired_devices[@]}"; do
if device_connected "$device"; then
device_alias="$(bluetoothctl info "$device" | grep -F "Alias" | cut -d ' ' -f 2-)"
if [ $counter -gt 0 ]; then
printf ", %s" "$device_alias"
else
printf " %s" "$device_alias"
fi
((counter++))
fi
done
printf "\n"
else
echo ""
fi
}
# A submenu for a specific device that allows connecting, pairing, and trusting
device_menu() {
device="$1"
# Get device name and mac address
device_name="$(echo "$device" | cut -d ' ' -f 3-)"
mac="$(echo "$device" | cut -d ' ' -f 2)"
# Build options
if device_connected "$mac"; then
connected="Connected: yes"
else
connected="Connected: no"
fi
paired="$(device_paired "$mac")"
trusted="$(device_trusted "$mac")"
options="$connected\n$paired\n$trusted\n$divider\n$goback\n$exit"
# Open dmenu menu, read chosen option
chosen="$(echo -e "$options" | run_dmenu "$device_name")"
# Match chosen option to command
case $chosen in
"" | "$divider")
echo "No option chosen."
;;
"$connected")
toggle_connection "$mac"
;;
"$paired")
toggle_paired "$mac"
;;
"$trusted")
toggle_trust "$mac"
;;
"$goback")
show_menu
;;
esac
}
# Opens a dmenu menu with current bluetooth status and options to connect
show_menu() {
# Get menu options
if power_on; then
power="Power: on"
# Human-readable names of devices, one per line
# If scan is off, will only list paired devices
if [[ -n "$connected_icon" ]]; then
devices="$(bluetoothctl devices | grep -F Device | while read -r device; do
device_name="$(echo "$device" | cut -d ' ' -f 3-)"
mac="$(echo "$device" | cut -d ' ' -f 2)"
icon=""
if device_connected "$mac" && [[ -n $connected_icon ]]; then
icon=" $connected_icon"
fi
echo "$device_name${icon}"
done)"
else
devices="$(bluetoothctl devices | grep -F Device | cut -d ' ' -f 3-)"
fi
# Get controller flags
scan="$(scan_on)"
pairable="$(pairable_on)"
discoverable="$(discoverable_on)"
# Options passed to dmenu
[[ -n $devices ]] && devices_part="$devices\n$divider\n"
options="$devices_part$power\n$scan\n$pairable\n$discoverable\n$exit"
else
power="Power: off"
options="$power\n$exit"
fi
# Open dmenu menu, read chosen option
chosen="$(echo -e "$options" | run_dmenu "Bluetooth")"
# Match chosen option to command
case $chosen in
"" | "$divider")
echo "No option chosen."
;;
"$power")
toggle_power
;;
"$scan")
toggle_scan
;;
"$discoverable")
toggle_discoverable
;;
"$pairable")
toggle_pairable
;;
*)
if [[ -n "$connected_icon" ]]; then
chosen="${chosen%% ${connected_icon}}"
fi
device="$(bluetoothctl devices | grep -F "$chosen")"
# Open a submenu if a device is selected
if [[ -n "$device" ]]; then device_menu "$device"; fi
;;
esac
}
# dmenu command to pipe into. Extra arguments to dmenu-bluetooth are passed through to dmenu. This
# allows the user to set fonts, sizes, colours, etc.
DMENU_BLUETOOTH_LAUNCHER="${DMENU_BLUETOOTH_LAUNCHER:-dmenu}"
run_dmenu() {
case "$DMENU_BLUETOOTH_LAUNCHER" in
rofi)
DMENU_BLUETOOTH_LAUNCHER="rofi -dmenu"
;;
fuzzel)
DMENU_BLUETOOTH_LAUNCHER="fuzzel --dmenu"
;;
esac
$DMENU_BLUETOOTH_LAUNCHER -i -p "$DMENU_BLUETOOTH_PROMPT" "-l" "20" "${dmenu_args[@]}"
}
print_help() {
echo "usage: $0 [--help] [--status] [--connected-icon [ICON]] [PROMPT] DMENU_ARGS..."
echo ""
echo "A script that generates a dmenu menu that uses bluetoothctl to connect to bluetooth devices and display status info."
echo ""
echo "positional arguments:"
echo " PROMPT dmenu prompt"
echo " DMENU_ARGS... arguments passed to dmenu"
echo ""
echo "options:"
echo "--help show this help message and exit"
echo "--status print a short string about current bluetooth status and exit"
echo "--connected-icon [ICON] add icon on device list next to connected devices"
echo ""
echo "environment variables:"
echo " DMENU_BLUETOOTH_PROMPT dmenu prompt"
echo " DMENU_BLUETOOTH_LAUNCHER command to use instead of 'dmenu'"
echo ""
echo "Positional arguments have to be placed after all other arguments."
echo "A PROMPT positional argument will be interpreted as part of DMENU_ARGS if it starts with '-'. It won't be parsed if the DMENU_BLUETOOTH_PROMPT environment variable is set."
echo "Use the DMENU_BLUETOOTH_LAUNCHER environment variable to use launchers other than dmenu. Rofi, fuzzel, and any dmenu-compatible launchers are supported."
}
command_present() {
command -v "$1" >/dev/null 2>&1
}
error() {
echo "$1. $2." >&2
command_present notify-send && notify-send "$1" "$2."
}
# Check if bluetooth daemon is running. Start it if possible.
if command_present systemctl; then
systemctl is-active --quiet bluetooth
case $? in
3)
error "Bluetooth daemon is not running" "Start it to use this script"
systemctl start bluetooth || exit 3
;;
4)
error "Bluetooth daemon is not present" "On Arch Linux install bluez and bluez-utils packages"
exit 4
;;
esac
fi
dmenu_args=("$@")
case "$1" in
--help)
print_help
exit
;;
--status)
print_status
exit
;;
--connected-icon)
if [[ "$2" == "--" ]]; then
connected_icon=""
else
connected_icon="$2"
fi
dmenu_args=("${dmenu_args[@]:2}")
;;
esac
case "${dmenu_args[0]}" in
-*)
;;
*)
if [[ -z "$DMENU_BLUETOOTH_PROMPT" ]]; then
DMENU_BLUETOOTH_PROMPT="${dmenu_args[0]}"
dmenu_args=("${dmenu_args[@]:1}")
fi
;;
esac
show_menu

View File

@@ -1,23 +0,0 @@
#!/usr/bin/env bash
# dmenu theming
lines="-l 20"
selected="$(ps -a -u $USER | \
dmenu -i -p "Type to search and select process to kill" \
$lines | \
awk '{print $1" "$4}')";
if [[ ! -z $selected ]]; then
answer="$(echo -e "Yes\nNo" | \
dmenu -i -p "$selected will be killed, are you sure?" \
$lines )"
if [[ $answer == "Yes" ]]; then
selpid="$(awk '{print $1}' <<< $selected)";
kill -9 $selpid
fi
fi
exit 0

View File

@@ -1,18 +0,0 @@
#!/usr/bin/env bash
prompt="-p Manual:"
# terminal to open manual
terminal="st"
# list all manuals
manual="$(man -k . | dmenu $prompt | awk '{print $1}')"
# open selected manual with terminal
if [[ ! -z "$manual" ]]; then
eval "$($terminal -e man $manual)"
fi
exit 0

View File

@@ -1,76 +0,0 @@
#!/bin/bash
all_name='[ALL]'
mode=library
d_artist() {
mpc list artist | sort -f | dmenu -p artist "${dmenu_args[@]}"
}
d_album() {
local artist="$1"
local albums
mapfile -t albums < <(mpc list album artist "$artist")
if (( ${#albums[@]} > 1 )) ; then
{
printf '%s\n' "$all_name"
printf '%s\n' "${albums[@]}" | sort -f
} | dmenu -p album "${dmenu_args[@]}"
else
# We only have one album, so just use that.
printf '%s\n' "${albums[0]}"
fi
}
d_playlist() {
local format="%position% %title%"
local extra_format="(%artist% - %album%)"
local track
local num_extras
# If all tracks are from the same artist and album, no need to display that
num_extras=$(mpc playlist -f "$extra_format" | sort | uniq | wc -l)
(( num_extras == 1 )) || format+=" $extra_format"
track=$(mpc playlist -f "$format" | dmenu -p track "${dmenu_args[@]}")
printf '%s' "${track%% *}"
}
i=2
for arg do
if [[ $arg == :: ]]; then
dmenu_args=( "${@:$i}" )
break
fi
case "$arg" in
-l) mode=library ;;
-p) mode=playlist ;;
esac
let i++
done
case "$mode" in
library)
artist=$(d_artist)
[[ $artist ]] || exit 1
album=$(d_album "$artist")
[[ $album ]] || exit 2
mpc clear
if [[ $album == "$all_name" ]]; then
mpc find artist "$artist" | sort | mpc add
else
mpc find artist "$artist" album "$album" | sort | mpc add
fi
mpc play >/dev/null
;;
playlist)
mpc play "$(d_playlist)" >/dev/null
;;
esac

View File

@@ -1,60 +0,0 @@
#!/usr/bin/env bash
shopt -s nullglob globstar
typeit=0
if [[ $1 == "--type" ]]; then
typeit=1
shift
fi
STARTDIR=${PASSWORD_STORE_DIR-~/.password-store}
BASEDIR=$STARTDIR
DONE=0
LEVEL=0
PREVSELECTION=""
SELECTION=""
while [ "$DONE" -eq 0 ] ; do
password_files=( "$STARTDIR"/* )
password_files=( "${password_files[@]#"$STARTDIR"/}" )
password_files=( "${password_files[@]%.gpg}" )
if [ "$LEVEL" -ne 0 ] ; then
password_files=(".." "${password_files[@]}")
fi
entry=$(printf '%s\n' "${password_files[@]}" | dmenu "$@" -l 15)
echo "entry: $entry"
if [ -z "$entry" ] ; then
DONE=1
exit
fi
if [ "$entry" != ".." ] ; then
PREVSELECTION=$SELECTION
SELECTION="$SELECTION/$entry"
# check if another dir
if [ -d "$STARTDIR/$entry" ] ; then
STARTDIR="$STARTDIR/$entry"
LEVEL=$((LEVEL+1))
else
# not a directory so it must be a real password entry
if [[ $typeit -eq 0 ]]; then
pass show -c "$SELECTION" 2>/dev/null
else
xdotool - <<<"type --clearmodifiers -- $(pass show "$SELECTION" | head -n 1)"
fi
DONE=1
fi
else
LEVEL=$((LEVEL-1))
SELECTION=$PREVSELECTION
STARTDIR="$BASEDIR/$SELECTION"
fi
done

View File

@@ -1,28 +0,0 @@
#!/bin/sh
#
# Write/remove a task to do later.
#
# Select an existing entry to remove it from the file, or type a new entry to
# add it.
#
file="$HOME/.todo"
touch "$file"
height=$(wc -l "$file" | awk '{print $1}')
prompt="Add/delete a task: "
cmd=$(dmenu -l "$height" -p "$prompt" "$@" < "$file")
while [ -n "$cmd" ]; do
if grep -q "^$cmd\$" "$file"; then
grep -v "^$cmd\$" "$file" > "$file.$$"
mv "$file.$$" "$file"
height=$(( height - 1 ))
else
echo "$cmd" >> "$file"
height=$(( height + 1 ))
fi
cmd=$(dmenu -l "$height" -p "$prompt" "$@" < "$file")
done
exit 0

View File

@@ -1,4 +0,0 @@
#!/bin/sh
udisksctl mount -b $(lsblk -lp | awk '/part/ {print $1, "(" $4 ")"}' | dmenu -p mount)

View File

@@ -1,3 +0,0 @@
#!/bin/sh
udisksctl power-off -b $(lsblk -lp | awk '/part/ {print $1, "(" $4 ")"}' | dmenu -p poweroff)

View File

@@ -1,3 +0,0 @@
#!/bin/sh
udisksctl unmount -b $(lsblk -lp | awk '/part/ {print $1, "(" $4 ")"}' | dmenu -p unmount)

View File

@@ -1,28 +0,0 @@
#!/bin/bash
engine="https://www.google.com/search?q="
declare -A bookmarks=(
["YouTube"]="https://www.youtube.com/"
["GitHub"]="https://github.com/TrudeEH/dotfiles"
["TrudeWeb"]="https://trudeeh.github.io/web/"
["Gemini"]="https://gemini.google.com/app"
["Element"]="https://app.element.io/#/home"
["Gmail"]="https://mail.google.com/mail/u/0/#inbox"
["Google Messages"]="https://messages.google.com/web/conversations"
["WOL"]="https://wol.jw.org/pt-PT/"
["Discord"]="https://discord.com/app"
)
choice=$(printf "%s\n" "${!bookmarks[@]}" | dmenu -i -p "Search:")
if [[ -n "$choice" ]]; then
# Find the matching URL
url=${bookmarks[$choice]}
if [[ -n "$url" ]]; then
xdg-open $url
else
xdg-open $engine$choice
fi
fi

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,9 @@
#!/bin/sh
# Show wifi 📶 and percent strength or 📡 if none.
# Show 🌐 if connected to ethernet or ❎ if none.
# Show 🔒 if a vpn connection is active
# Wifi
if [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'up' ] ; then
if [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'up' ]; then
wifiicon="$(awk '/^[[:space:]]*w/ { gsub(/[[:space:]]+/, " "); print " ", int($3 * 100 / 70) "% " }' /proc/net/wireless)"
elif [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'down' ] ; then
elif [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'down' ]; then
wifiicon=" "
fi

View File

@@ -1,11 +0,0 @@
echo "PUBLIC IP:"
wget -qO - https://api.ipify.org
echo
echo
# echo "TOR PUBLIC IP:"
# torsocks wget -qO - https://api.ipify.org; echo
# echo
echo "OPEN PORTS:"
sudo ss -tupln

View File

@@ -1,25 +0,0 @@
#!/bin/sh
# Prints all batteries, their percentage remaining and an emoji corresponding
# to charge status (🔌 for plugged up, 🔋 for discharging on battery, etc.).
# Loop through all attached batteries and format the info
# for battery in /sys/class/power_supply/BAT?*; do # For standard devices, use this line instead.
for battery in /sys/class/power_supply/?*; do
# If non-first battery, print a space separator.
[ -n "${capacity+x}" ] && [ -f "$battery/status" ] && printf " "
# Sets up the status and capacity
case "$(cat "$battery/status" 2>&1)" in
"Full") status="󰁹 " ;;
"Discharging") status="󰂌 " ;;
"Charging") status="󰂄 " ;;
"Not charging") status="󰂃 " ;;
"Unknown") status="󰂑 " ;;
*) exit 1 ;;
esac
capacity="$(cat "$battery/capacity" 2>&1)"
# Will make a warn variable if discharging and low
[ "$status" = "󰂌 " ] && [ "$capacity" -le 25 ] && warn=" "
# Prints the info
printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn
done && printf "\\n"

View File

@@ -19,10 +19,10 @@ split() {
vol="$(printf "%.0f" "$(split "$vol" ".")")"
case 1 in
$((vol >= 70)) ) icon=" " ;;
$((vol >= 30)) ) icon=" " ;;
$((vol >= 1)) ) icon=" " ;;
* ) echo " " && exit ;;
$((vol >= 70))) icon=" " ;;
$((vol >= 30))) icon=" " ;;
$((vol >= 1))) icon=" " ;;
*) echo " " && exit ;;
esac
echo "$icon$vol%"