first update

This commit is contained in:
Greg Gauthier 2023-07-15 20:21:25 +01:00
commit b87984ccce
20 changed files with 470 additions and 0 deletions

0
.gitignore vendored Normal file
View File

10
README.md Normal file
View File

@ -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

13
app/apps Executable file
View File

@ -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

12
app/contacts Executable file
View File

@ -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 '[^ ]+$'

18
app/def Executable file
View File

@ -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

8
app/forecast Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
if ! [[ -n $1 ]]; then
loc="Cowley,UK"
else
loc=$1
fi
curl wttr.in/$loc?u

112
app/menu Executable file
View File

@ -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

43
app/spchk Executable file
View File

@ -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="<b>ERROR</b> 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="<b>CORRECT!</b> " \
--icon-name=info \
--window-icon="/home/gmgauthier/.local/bin/img/check-mark-11-16.png" 2> /dev/null
else
parseResults "${FIXED}"
message="<b>There are ${LISTCOUNT} suggested corrections for '${QUERYTERM}':</b> ${WORDLIST}"
zenity --info --text="${message}"\
--icon-name=warning \
--window-icon="/home/gmgauthier/.local/bin/img/caution-48.png" 2> /dev/null
fi

8
app/wx Executable file
View File

@ -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

39
app/yootoob Executable file
View File

@ -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

89
scripting/cecho Executable file
View File

@ -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 "$@"

4
scripting/mvsprt Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env zsh
#lpr -p -o media=11x17 -o orientation-requested=5 "$@"
lpr -p -o media=17x11 "$@"

BIN
scripting/passwdgen Executable file

Binary file not shown.

5
sys/birthdate Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
statout=$(stat -c %W --terse /)
birthdate=$(date --date="@$statout")
echo $birthdate

3
sys/checkit Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env zsh
vale --config=/home/gmgauthier/.config/vale/.vale.ini --no-wrap "$@"

3
sys/dirsz Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env zsh
du -mhac "$@" --exclude .git|sort -h

10
sys/ifcheck Executable file
View File

@ -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

11
sys/netcheck Executable file
View File

@ -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

28
sys/status Executable file
View File

@ -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

54
sys/usedisk Executable file
View File

@ -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