commit b87984cccedc23c59d36f7a915e8fcbc2d77899d Author: Greg Gauthier Date: Sat Jul 15 20:21:25 2023 +0100 first update diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..cfbb33f --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# My Shell Utilities + +Various shell scripts that do various things. + +## Categories + +- sys: all the shell scripts related to system monitoring and manipulation +- app: convenience scripts that make it easier to use applications +- scripting: tools to improve scripting or serve as a reference + diff --git a/app/apps b/app/apps new file mode 100755 index 0000000..54a5ba6 --- /dev/null +++ b/app/apps @@ -0,0 +1,13 @@ +#!/usr/bin/env zsh +set -eo pipefail + +_stopnow() { + test -f stopnow && echo "Stopping!" && rm stopnow && exit 0 || return 0 +} + +while true +do + _stopnow + menu +done + diff --git a/app/contacts b/app/contacts new file mode 100755 index 0000000..8da4037 --- /dev/null +++ b/app/contacts @@ -0,0 +1,12 @@ +#!/usr/bin/env zsh + +addressbook="/home/gmgauthier/.local/share/addrbook/contacts.txt" + +## Simple record retrieval by any known value +#awk 'BEGIN { RS = "<->" } /'$*'/' $addressbook + +## Get record by search for substring in email +#awk 'BEGIN { RS = "<->"; FS = "email: " } ($2 ~ "'${*}'") { print $0 }' $addressbook + +## Get email addresses in a specific contact class +awk 'BEGIN { RS = "<->"; FS = "category: " } ($2 ~ "'${1}'") { print }' $addressbook | grep '^email:' | egrep -o '[^ ]+$' diff --git a/app/def b/app/def new file mode 100755 index 0000000..cd38c0f --- /dev/null +++ b/app/def @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +dict -h localhost -d gcide "$@" > /home/gmgauthier/.local/tmp/"${1}".txt 2>&1 + +content=$(cat /home/gmgauthier/.local/tmp/"${1}".txt); + +if [[ "${content}" == *"No definitions found"* ]]; then + icon="/home/gmgauthier/.local/bin/img/caution-48.png" +else + icon="/home/gmgauthier/.local/bin/img/checkmark-32.png" +fi + +zenity --text-info \ + --window-icon="${icon}" \ + --filename=/home/gmgauthier/.local/tmp/"${1}".txt \ + --font="IBM Plex Mono Medium 11" \ + --width=750 \ + --height=600 2> /dev/null diff --git a/app/forecast b/app/forecast new file mode 100755 index 0000000..04604a5 --- /dev/null +++ b/app/forecast @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +if ! [[ -n $1 ]]; then + loc="Cowley,UK" +else + loc=$1 +fi + +curl wttr.in/$loc?u diff --git a/app/menu b/app/menu new file mode 100755 index 0000000..ce8a7e9 --- /dev/null +++ b/app/menu @@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +# while-menu-dialog: a menu driven system information program +export ME="/home/gmgauthier" + +DIALOG_CANCEL=1 +DIALOG_ESC=255 +HEIGHT=17 +WIDTH=0 + +tmemo() { + tmp=$(date +"memo-%Y.%m.%d-%k.%M.%S") + timestamp="${tmp// /}" + filename="$HOME/memos/${timestamp}.md" + exec tilde $filename +} + +output_panel() { + dialog --title "$1" \ + --no-collapse \ + --msgbox "$result" 0 0 +} + +_stopnow() { + test -f stopnow && echo "Stopping!" && rm stopnow && exit 0 || return 0 +} + +menu() { + exec 3>&1 + selection=$(dialog \ + --backtitle "TUI Command Center" \ + --title "Menu" \ + --clear \ + --cancel-label "Exit" \ + --menu "Please select:" $HEIGHT $WIDTH 4 \ + "1" "Mutt Email" \ + "2" "Calcurse Calendar" \ + "3" "Abook Contacts" \ + "4" "Tudu Tasks" \ + "5" "Tilde Notepad" \ + "6" "CLI Calculator" \ + "7" "MC File Manager" \ + "8" "IRC Client" \ + "9" "Castero Podcasts" \ + "0" "VLC Music Player" \ + 2>&1 1>&3) + exit_status=$? + exec 3>&- + + case $exit_status in + $DIALOG_CANCEL) + clear + echo "Exiting Apps Menu." + exit 1 + ;; + $DIALOG_ESC) + clear + echo "Terminating Apps Menu." >&2 + exit 1 + ;; + esac + + clear + + case $selection in + 1 ) + clear + exec neomutt -F ${ME}/.config/mutt/.protonmuttrc + ;; + 2 ) + clear + exec calcurse -c ${ME}/.local/share/calcurse/calendar -C ${ME}/.config/calcurse + ;; + 3 ) + clear + exec abook --datafile ${ME}/.local/share/abook/addressbook + ;; + 4 ) + clear + exec tudu -f ${ME}/.local/share/tudu/tasks.xml -c ${ME}/.config/tudu/config + ;; + 5 ) + clear + tmemo + ;; + 6 ) + clear + exec calc + ;; + 7 ) + clear + exec mc + ;; + 8 ) + clear + exec weechat + ;; + 9 ) + clear + exec castero + ;; + 0 ) + clear + exec vlc -Z -L -I ncurses --no-video --recursive expand ${ME}/Music + ;; + esac +} + +while true; do + _stopnow + menu +done diff --git a/app/spchk b/app/spchk new file mode 100755 index 0000000..07e6eb3 --- /dev/null +++ b/app/spchk @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +function parseResults() { + oIFS=$IFS + IFS=":" + declare -a fields=($1) + + export QUERYTERM=$(echo "${fields[0]}"|awk '{print $1}'); + export LISTCOUNT=$(echo "${fields[0]}"|awk '{print $2}'); + export WORDLIST=$(echo "${fields[1]}"|sed 's/^\s*\|\s*$//g'); + + IFS=$oIFS + unset oIFS +} + +if [ $# -eq 0 ]; then + >&2 echo "No arguments provided" + exit 1 +fi + +if [[ "$1" =~ ^[0-9]+$ ]]; then + zenity --info --text="ERROR only words, please!"\ + --icon-name=error \ + --window-icon="/home/gmgauthier/.local/bin/img/xmark.png" 2> /dev/null + exit 1; +fi + +export RESULT=$(echo "$@"|aspell -a|sed "1 d"); # Deletes the header line +export FIXED="${RESULT/& }" # Removes ampersand causing parsing errors. + +if [[ "${FIXED}" == *"*"* ]]; then + zenity --info --text="CORRECT! " \ + --icon-name=info \ + --window-icon="/home/gmgauthier/.local/bin/img/check-mark-11-16.png" 2> /dev/null + +else + parseResults "${FIXED}" + message="There are ${LISTCOUNT} suggested corrections for '${QUERYTERM}': ${WORDLIST}" + zenity --info --text="${message}"\ + --icon-name=warning \ + --window-icon="/home/gmgauthier/.local/bin/img/caution-48.png" 2> /dev/null + +fi diff --git a/app/wx b/app/wx new file mode 100755 index 0000000..f902b8f --- /dev/null +++ b/app/wx @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +if ! [[ -n $1 ]]; then + loc="Cowley,UK" +else + loc=$1 +fi + +ansiweather -l $loc -u imperial -s true -i false diff --git a/app/yootoob b/app/yootoob new file mode 100755 index 0000000..3e0026b --- /dev/null +++ b/app/yootoob @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +$cecho = '/gmgauthier/.local/bin/cecho'; + +function border () { + local str="$*" # Put all arguments into single string + local len=${#str} + local i + for ((i = 0; i < len + 4; ++i)); do + printf '-' + done + printf '\n| %s |\n' "$str" + for ((i = 0; i < len + 4; ++i)); do + printf '-' + done + echo +} + +clear +border "Internet Video Console" +echo +read -p "Search For: " searchphrase + +ytfzf --detach --notify-playing --ytdl-pref="[height <=? 720]" --sort-by="upload_date" --pages=3 "${searchphrase}" + +if [[ $? -ne 0 ]]; then + /home/gmgauthier/.local/bin/cecho "IYellow" "There are no results for '${searchphrase}'"; + read -p "Press any key to exit... " -n1 -s +else + # needed because immediate exit was destroying the handshake between alacritty and ytfzf + /home/gmgauthier/.local/bin/cecho "Green" "Your video will play momentarily..." + sleep 4 + #This only works if the query window is the only open terminal + #xdotool search --onlyvisible --classname alacritty windowminimize + #sleep 5 + #this only works if mpv doesn't become the active window + #xdotool windowminimize getactivewindow +fi +exit 0 diff --git a/scripting/cecho b/scripting/cecho new file mode 100755 index 0000000..0563abe --- /dev/null +++ b/scripting/cecho @@ -0,0 +1,89 @@ +#!/usr/bin/env bash + +function cecho(){ + # Reset + Color_Off='\033[0m' # Text Reset + + # Regular Colors + Black='\033[0;30m' # Black + Red='\033[0;31m' # Red + Green='\033[0;32m' # Green + Yellow='\033[0;33m' # Yellow + Blue='\033[0;34m' # Blue + Purple='\033[0;35m' # Purple + Cyan='\033[0;36m' # Cyan + White='\033[0;37m' # White + + # Bold + BBlack='\033[1;30m' # Black + BRed='\033[1;31m' # Red + BGreen='\033[1;32m' # Green + BYellow='\033[1;33m' # Yellow + BBlue='\033[1;34m' # Blue + BPurple='\033[1;35m' # Purple + BCyan='\033[1;36m' # Cyan + BWhite='\033[1;37m' # White + + # Underline + UBlack='\033[4;30m' # Black + URed='\033[4;31m' # Red + UGreen='\033[4;32m' # Green + UYellow='\033[4;33m' # Yellow + UBlue='\033[4;34m' # Blue + UPurple='\033[4;35m' # Purple + UCyan='\033[4;36m' # Cyan + UWhite='\033[4;37m' # White + + # Background + On_Black='\033[40m' # Black + On_Red='\033[41m' # Red + On_Green='\033[42m' # Green + On_Yellow='\033[43m' # Yellow + On_Blue='\033[44m' # Blue + On_Purple='\033[45m' # Purple + On_Cyan='\033[46m' # Cyan + On_White='\033[47m' # White + + # High Intensity + IBlack='\033[0;90m' # Black + IRed='\033[0;91m' # Red + IGreen='\033[0;92m' # Green + IYellow='\033[0;93m' # Yellow + IBlue='\033[0;94m' # Blue + IPurple='\033[0;95m' # Purple + ICyan='\033[0;96m' # Cyan + IWhite='\033[0;97m' # White + + # Bold High Intensity + BIBlack='\033[1;90m' # Black + BIRed='\033[1;91m' # Red + BIGreen='\033[1;92m' # Green + BIYellow='\033[1;93m' # Yellow + BIBlue='\033[1;94m' # Blue + BIPurple='\033[1;95m' # Purple + BICyan='\033[1;96m' # Cyan + BIWhite='\033[1;97m' # White + + # High Intensity backgrounds + On_IBlack='\033[0;100m' # Black + On_IRed='\033[0;101m' # Red + On_IGreen='\033[0;102m' # Green + On_IYellow='\033[0;103m' # Yellow + On_IBlue='\033[0;104m' # Blue + On_IPurple='\033[0;105m' # Purple + On_ICyan='\033[0;106m' # Cyan + On_IWhite='\033[0;107m' # White + + RED="\033[0;31m" + GREEN="\033[0;32m" # <-- [0 means not bold + YELLOW="\033[1;33m" # <-- [1 means bold + CYAN="\033[1;36m" + # ... Add more colors if you like + + NC="\033[0m" # No Color + + # printf "${(P)1}${2} ${NC}\n" # <-- zsh + printf "${!1}${2} ${NC}\n" # <-- bash +} + +cecho "$@" diff --git a/scripting/mvsprt b/scripting/mvsprt new file mode 100755 index 0000000..0d0f6e6 --- /dev/null +++ b/scripting/mvsprt @@ -0,0 +1,4 @@ +#!/usr/bin/env zsh + +#lpr -p -o media=11x17 -o orientation-requested=5 "$@" +lpr -p -o media=17x11 "$@" diff --git a/scripting/passwdgen b/scripting/passwdgen new file mode 100755 index 0000000..0c0d218 Binary files /dev/null and b/scripting/passwdgen differ diff --git a/sys/birthdate b/sys/birthdate new file mode 100755 index 0000000..7ff6095 --- /dev/null +++ b/sys/birthdate @@ -0,0 +1,5 @@ +#!/bin/sh + +statout=$(stat -c %W --terse /) +birthdate=$(date --date="@$statout") +echo $birthdate diff --git a/sys/checkit b/sys/checkit new file mode 100755 index 0000000..8b40da6 --- /dev/null +++ b/sys/checkit @@ -0,0 +1,3 @@ +#!/usr/bin/env zsh + +vale --config=/home/gmgauthier/.config/vale/.vale.ini --no-wrap "$@" diff --git a/sys/dirsz b/sys/dirsz new file mode 100755 index 0000000..8340620 --- /dev/null +++ b/sys/dirsz @@ -0,0 +1,3 @@ +#!/usr/bin/env zsh + +du -mhac "$@" --exclude .git|sort -h diff --git a/sys/ifcheck b/sys/ifcheck new file mode 100755 index 0000000..01d29ae --- /dev/null +++ b/sys/ifcheck @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +iface=$(ip -br -4 -iec -o -c address show dev wlp0s20f3) +if=$(echo $iface|awk '{print $1}') +ifstatus=$(echo $iface|awk '{print $2}') +ifaddr=$(echo $iface|awk '{print $3}') + +echo $if $ifstatus $ifaddr + +exit diff --git a/sys/netcheck b/sys/netcheck new file mode 100755 index 0000000..85878aa --- /dev/null +++ b/sys/netcheck @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +nchk=$(/home/gmgauthier/.local/bin/ifcheck) + + +ping -q -n -c1 "1.1.1.1" &>"/dev/null" +if [[ "${?}" -ne 0 ]]; then + /home/gmgauthier/.local/bin/cecho "BRed" "UNAVAILABLE" +elif [[ "${#args[@]}" -eq 0 ]]; then + /home/gmgauthier/.local/bin/cecho "IGreen" "AVAILABLE" +fi diff --git a/sys/status b/sys/status new file mode 100755 index 0000000..458e5f5 --- /dev/null +++ b/sys/status @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +numlines=$(tput lines) +numcols=$(tput cols) +numcols=$(expr $numcols - 1) +separator_line=$(for i in $(seq 0 $numcols);do printf "%s"═"";done;printf "\n") +/usr/bin/clear +tput cup 0 + +status=$(/home/gmgauthier/.local/bin/ifcheck) +if=$(echo $status|awk '{print $1}') +ifstatus=$(echo $status|awk '{print $2}') +ifaddr=$(echo $status|awk '{print $3}') + +if [[ "${status}" == *"UP"* ]]; then + echo -e " $(/home/gmgauthier/.local/bin/wx)" + echo -e "$(/home/gmgauthier/.local/bin/cecho ICyan Wifi:) ${ifstatus}\t\t $(/home/gmgauthier/.local/bin/cecho ICyan Inet:) $(/home/gmgauthier/.local/bin/netcheck)\t\t\t\t\t $(date +%R)" +else + iface=$(ip -br -o -c address show dev wlp0s20f3) + ifstatus=$(echo $iface|awk '{print $2}') + ifaddr=$(echo $iface|awk '{print $3}') + echo -e "$(/home/gmgauthier/.local/bin/cecho ICyan Wifi:) ${ifstatus} ${ifaddr} $(/home/gmgauthier/.local/bin/cecho ICyan Inet:) $(/home/gmgauthier/.local/bin/netcheck) $(date +%R)" +fi +echo $separator_line +mpstat +echo $separator_line +dfrs +echo $separator_line +acpi diff --git a/sys/usedisk b/sys/usedisk new file mode 100755 index 0000000..7f02532 --- /dev/null +++ b/sys/usedisk @@ -0,0 +1,54 @@ +#/usr/bin/env bash + +MEDIADIR="/media/gmgauthier" +format=0 # Don't format disk images that already exist + +# get name of freshly created blank disk, or create one +if [ $# -eq 0 ]; then + echo ">>> NEW DISK IS BEING CREATED..." + PREFIX="floppy" + RANDO=$(od -An -N4 -i < /dev/urandom|sed 's/[ -]//g') + DISK="$PREFIX$RANDO" + dd if=/dev/zero of=$DISK.img bs=1k count=1440 + format=1 +else + DISK=$1 + if ! [ -f $DISK.img ]; then + dd if=/dev/zero of=$DISK.img bs=1k count=1440 + format=1 + fi +fi + +# Find the next available loop device on the system +echo ">>> LOOP DEVICE IS BEING IDENTIFIED..." +list=$(losetup -O name|sed 's/\/dev\/loop//g'|sed 's/NAME//g'|sort - --sort=human-numeric) +### listarr=(${(@s: :)list}) # zsh version of the array generator +listarr=($(echo $list | tr " " "\n")) #bash version of array generator +lastdev=${listarr[-1]} +lastdevnum=$((lastdev)) +nextdev=$((lastdevnum+1)) + +# allocate the next available loop device, format the disk, and mount it. +nextdevname="/dev/loop$nextdev" +echo ">>> LOOP DEVICE $nextdevname RESERVED FOR DISK: $DISK.img" + +sudo losetup $nextdevname $DISK.img + +if [ $format -eq 1 ]; then + echo ">>> DISK IMAGE IS RAW AND WILL BE FORMATTED" + sudo mkfs -t vfat $nextdevname +fi + +if ! [ -d $MEDIADIR/$DISK ]; then + echo ">>> MOUNT DIRECTORY NOT FOUND. CREATING DIRECTORY NOW." + sudo mkdir $MEDIADIR/$DISK +fi + +echo ">>> DISK $DISK.img MOUNTING AT LOCATION: $MEDIADIR/$DISK" +sudo mount $DISK.img $MEDIADIR/$DISK + +if [ $format -eq 1 ]; then + echo ">>> DISK INFORMATION BEING COPIED TO $DISK.img" + sudo fdisk -l $nextdevname >> $DISK-fdisk.txt + sudo cp $DISK-fdisk.txt $MEDIADIR/$DISK/$DISK.txt && rm $DISK-fdisk.txt +fi