added scripts (.local/bin)

This commit is contained in:
Matthieu Fortin [CPC/CCP] 2024-10-25 16:26:02 -04:00
parent d61576a160
commit 321b645504
29 changed files with 575 additions and 0 deletions

2
scripts/.local/bin/$ Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
"$@"

25
scripts/.local/bin/aliases Executable file
View file

@ -0,0 +1,25 @@
#!/bin/bash
#set -euo pipefail
# Use 'declare -p' to list all aliases in a more parseable format
# alias_output=$(declare -p alias | sed 's/^alias \([^=]\+\)='\''\([^'\'']*\)'\''$/\1='\''\2/' | sed "s/'/'\''/g")
list_aliases() {
shopt -s expand_aliases
alias
}
# Print header for the table
printf "%-20s\t%s\n" "Alias" "Command"
printf "%-20s\t%s\n" "-----" "-------"
# Iterate over each alias and extract its name and definition
list_aliases | while IFS='=' read -r alias_name alias_command; do
# Extract alias name and definition
#alias_name=$(echo "$line" | cut -d '=' -f 1)
#alias_command=$(echo "$line" | cut -d '=' -f 2- | sed "s/'//g")
alias_command="$(echo -e "${alias_command}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
# Print alias name and corresponding command in tabular format
printf "%-20s\t%s\n" "$alias_name" "$alias_command"
done

15
scripts/.local/bin/archman Executable file
View file

@ -0,0 +1,15 @@
#!/bin/bash
set -euo pipefail
browser="librewolf"
nc -z 1.1.1.1 53 >/dev/null 2>&1
online=$?
if [ $online -eq 0 ]; then
read -rep $'What applications?\n: ' application
"$browser" https://wiki.archlinux.org/title/"$application"
else
echo "No Internet connection..."
fi

21
scripts/.local/bin/autoscript Executable file
View file

@ -0,0 +1,21 @@
#!/bin/bash
if [[ "$1" == "" ]]; then
echo "Usage: ${0##*/} <script-name>"; exit 2
fi
SCRIPT_FOLDER="$HOME/.local/bin"
SCRIPT_FILE="$SCRIPT_FOLDER/$1"
set -euo pipefail
if [[ ! -f $SCRIPT_FILE ]]; then
cat > $SCRIPT_FILE << EOM
#!/bin/bash
set -euo pipefail
EOM
chmod +x $SCRIPT_FILE
fi
$EDITOR $SCRIPT_FILE

View file

@ -0,0 +1,6 @@
#!/bin/bash
set -euo pipefail
#selected=$(ls "$HOME/.local/bin" | tofi --prompt-text "Select script")
selected=$(find "$HOME/.local/bin" -maxdepth 1 -type f -exec basename {} \; | sort | wofi --dmenu --sort-order=alphabetical -p "Select Script: ")
autoscript "$selected"

21
scripts/.local/bin/banner Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
clear=$'\033[2J'
curoff=$'\033[?25h'
curon=$'\033[?25h'
top=$'\033[H'
trap 'echo "${curon}"; echo "${clear}"; exit; trap -- - SIGINT SIGTERM' SIGTERM SIGINT
what="$*"
if [ -z "${what}" ]; then
read -rp "Text: " what
fi
echo "${clear}"
while true; do
echo "${top}"
figl <<<"$what" | lolcat
echo "${curoff}"
sleep 2
done

1
scripts/.local/bin/bunx Symbolic link
View file

@ -0,0 +1 @@
/home/mfortin/.cache/paru/clone/bun-bin/src/bun-linux-x64/bun

55
scripts/.local/bin/clock Executable file
View file

@ -0,0 +1,55 @@
#!/usr/bin/bash
hours=("zero" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "ten" "eleven" "twelve")
hour=$(date +'%I')
minute=$(date +'%M')
# strips leading zero to prevent octal number assumption
hour=$(( "10#$hour" ))
minute=$(( "10#$minute" ))
# if the hour is more than half done, we make reference to the next hour, set adverb to "to" and subract 30 from minutes
if (( minute >= 33 ))
then
if (( hour == 12 ))
then
hour=1
else
hour=$(( hour + 1 ))
fi
minute=$(( 60 - minute ))
adverb="to"
else
adverb="past"
fi
hour_as_text=${hours[$hour]}
if (( minute < 3 ))
then
time_as_text="$hour_as_text o'clock"
elif (( minute < 8 ))
then
time_as_text="five $adverb $hour_as_text"
elif (( minute < 13 ))
then
time_as_text="ten $adverb $hour_as_text"
elif (( minute < 18 ))
then
time_as_text="quarter $adverb $hour_as_text"
elif (( minute < 23 ))
then
time_as_text="twenty $adverb $hour_as_text"
elif (( minute < 28 ))
then
time_as_text="twenty-five $adverb $hour_as_text"
elif (( minute < 33 ))
then
time_as_text="half past $hour_as_text"
else
exit 1
fi
echo "$time_as_text"

17
scripts/.local/bin/color10bit Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
set -euo pipefail
awk -v term_cols="${width:-$(tput cols || echo 80)}" 'BEGIN{
s="/\\";
for (colnum = 0; colnum<term_cols; colnum++) {
r = 255-(colnum*255/term_cols);
g = (colnum*510/term_cols);
b = (colnum*255/term_cols);
if (g>255) g = 510-g;
printf "\033[48;2;%d;%d;%dm", r,g,b;
printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
printf "%s\033[0m", substr(s,colnum%2+1,1);
}
printf "\n";
}'

9
scripts/.local/bin/color256 Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash
set -euo pipefail
for i in {0..255} ; do
printf "\x1b[48;5;%sm%3d\e[0m " "$i" "$i"
if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then
printf "\n";
fi
done

21
scripts/.local/bin/colorballs Executable file
View file

@ -0,0 +1,21 @@
#!/bin/bash
set -euo pipefail
f=3 b=4
for j in f b; do
for i in {0..7}; do
printf -v $j$i %b "\e[${!j}${i}m"
done
done
d=$'\e[1m'
t=$'\e[0m'
v=$'\e[7m'
# Symbol
s=
# s=
cat << EOF
$f0$s$d$s$t $f1$s$d$s$t $f2$s$d$s$t $f3$s$d$s$t
$f4$s$d$s$t $f5$s$d$s$t $f6$s$d$s$t $f7$s$d$s$t
EOF

24
scripts/.local/bin/colorpanes Executable file
View file

@ -0,0 +1,24 @@
#!/bin/bash
# Author: GekkoP
# Source: http://linuxbbq.org/bbs/viewtopic.php?f=4&t=1656#p33189
f=3 b=4
for j in f b; do
for i in {0..7}; do
printf -v $j$i %b "\e[${!j}${i}m"
done
done
d=$'\e[1m'
t=$'\e[0m'
v=$'\e[7m'
cat << EOF
$f0████$d▄$t $f1████$d▄$t $f2████$d▄$t $f3████$d▄$t $f4████$d▄$t $f5████$d▄$t $f6████$d▄$t $f7████$d▄$t
$f0████$d█$t $f1████$d█$t $f2████$d█$t $f3████$d█$t $f4████$d█$t $f5████$d█$t $f6████$d█$t $f7████$d█$t
$f0████$d█$t $f1████$d█$t $f2████$d█$t $f3████$d█$t $f4████$d█$t $f5████$d█$t $f6████$d█$t $f7████$d█$t
$d$f0 ▀▀▀▀ $d$f1 ▀▀▀▀ $f2▀▀▀▀ $f3▀▀▀▀ $f4▀▀▀▀ $f5▀▀▀▀ $f6▀▀▀▀ $f7▀▀▀▀$t
EOF

96
scripts/.local/bin/colors Executable file
View file

@ -0,0 +1,96 @@
#!/bin/bash
# Tom Hale, 2016. MIT Licence.
# Print out 256 colours, with each number printed in its corresponding colour
# See http://askubuntu.com/questions/821157/print-a-256-color-test-pattern-in-the-terminal/821163#821163
set -eu # Fail on errors or undeclared variables
printable_colours=256
# Return a colour that contrasts with the given colour
# Bash only does integer division, so keep it integral
function contrast_colour {
local r g b luminance
colour="$1"
if (( colour < 16 )); then # Initial 16 ANSI colours
(( colour == 0 )) && printf "15" || printf "0"
return
fi
# Greyscale # rgb_R = rgb_G = rgb_B = (number - 232) * 10 + 8
if (( colour > 231 )); then # Greyscale ramp
(( colour < 244 )) && printf "15" || printf "0"
return
fi
# All other colours:
# 6x6x6 colour cube = 16 + 36*R + 6*G + B # Where RGB are [0..5]
# See http://stackoverflow.com/a/27165165/5353461
# r=$(( (colour-16) / 36 ))
g=$(( ((colour-16) % 36) / 6 ))
# b=$(( (colour-16) % 6 ))
# If luminance is bright, print number in black, white otherwise.
# Green contributes 587/1000 to human perceived luminance - ITU R-REC-BT.601
(( g > 2)) && printf "0" || printf "15"
return
# Uncomment the below for more precise luminance calculations
# # Calculate percieved brightness
# # See https://www.w3.org/TR/AERT#color-contrast
# # and http://www.itu.int/rec/R-REC-BT.601
# # Luminance is in range 0..5000 as each value is 0..5
# luminance=$(( (r * 299) + (g * 587) + (b * 114) ))
# (( $luminance > 2500 )) && printf "0" || printf "15"
}
# Print a coloured block with the number of that colour
function print_colour {
local colour="$1" contrast
contrast=$(contrast_colour "$1")
printf "\e[48;5;%sm" "$colour" # Start block of colour
printf "\e[38;5;%sm%3d" "$contrast" "$colour" # In contrast, print number
printf "\e[0m " # Reset colour
}
# Starting at $1, print a run of $2 colours
function print_run {
local i
for (( i = "$1"; i < "$1" + "$2" && i < printable_colours; i++ )) do
print_colour "$i"
done
printf " "
}
# Print blocks of colours
function print_blocks {
local start="$1" i
local end="$2" # inclusive
local block_cols="$3"
local block_rows="$4"
local blocks_per_line="$5"
local block_length=$((block_cols * block_rows))
# Print sets of blocks
for (( i = start; i <= end; i += (blocks_per_line-1) * block_length )) do
printf "\n" # Space before each set of blocks
# For each block row
for (( row = 0; row < block_rows; row++ )) do
# Print block columns for all blocks on the line
for (( block = 0; block < blocks_per_line; block++ )) do
print_run $(( i + (block * block_length) )) "$block_cols"
done
(( i += block_cols )) # Prepare to print the next row
printf "\n"
done
done
}
print_run 0 16 # The first 16 colours are spread over the whole spectrum
printf "\n"
print_blocks 16 231 6 6 3 # 6x6x6 colour cube between 16 and 231 inclusive
print_blocks 232 255 12 2 1 # Not 50, but 24 Shades of Grey

7
scripts/.local/bin/datepath Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
# Prints the current date as a path for use when creating content within
# a directory file structure that models chronological data. Accepts
# anything that can be passed to `date -d`.
date +%4Y/%m/%d "-d $@"

16
scripts/.local/bin/f Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/env bash
clear=$'\033[2J'
top=$'\033[H'
trap "setterm --cursor on; stty echo; echo ${clear}; exit; trap -- - SIGINT SIGTERM" SIGTERM SIGINT
echo "${clear}"
while true; do
echo "${top}"
stty -echo
setterm --cursor off
echo -e "$@" | figl | lolcat
setterm --cursor off
sleep 2
done

21
scripts/.local/bin/figl Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Set the figlet default font, font directory, and centering as well as
# defaults to passing it to lolcat for coloring.
figl() {
#font=${FIGL_FONT:-ansi-shadow}
font=${FIGL_FONT:-future}
#font=${FIGL_FONT:-calvin-s}
#clear
declare -a buf
while IFS= read -r line; do
buf+=("$line")
done
#clear
for line in "${buf[@]}"; do
figlet -d "$REPOS/github.com/rwxrob/fonts/figlet" -f "$font" -c "${line}" | head -6
done
}
figl "$*"

22
scripts/.local/bin/figlet.sh Executable file
View file

@ -0,0 +1,22 @@
#!/bin/bash
figlet -f smslant "Figlet"
echo
read -p "Enter the text for ascii encoding: " mytext
if [ ! -f ~/figlet.txt ]; then
touch ~/figlet.txt
fi
echo "cat <<\"EOF\"" > ~/figlet.txt
figlet -f smslant "$mytext" >> ~/figlet.txt
echo "" >> ~/figlet.txt
echo "EOF" >> ~/figlet.txt
lines=$( cat ~/figlet.txt )
wl-copy "$lines"
xclip -sel clip ~/figlet.txt
echo "Text copied to clipboard!"

67
scripts/.local/bin/funclock Executable file
View file

@ -0,0 +1,67 @@
#!/bin/bash
set -euo pipefail
# Created By: Jake@Linux
# Created On: Tue 19 Jul 2022 12:38:28 PM CDT
# Project: fuzzy clock
box() {
title=" $1 "
edge=$(echo "$title" | sed 's/./*/g')
echo "$edge"
echo -e "\e[1;31m$title\e[0m"
echo "$edge"
}
txttime=("zero" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "ten" "eleven" "twelve")
hr=$(date +'%I')
min=$(date +'%M')
hr=$(( "10#$hr" ))
min=$(( "10#$min" ))
if (( min >= 33 ))
then
if (( "$hr" == 12 ));
then
hr=1
else
hr=$(( "$hr" + 1 ))
fi
min=$(( 60 - $min ));
adverb="til"
else
adverb="after"
fi
txthour=${txttime[$hr]}
if (( min < 3 ))
then
written_time="it is $txthour o'clock"
elif (( min < 8 ))
then
written_time="it is five min $adverb $txthour"
elif (( min < 13 ))
then
written_time="it is ten min $adverb $txthour"
elif (( min < 18 ))
then
written_time="it is fifteen $adverb $txthour"
elif (( min < 23 ))
then
written_time="it is twenty $adverb $txthour"
elif (( min < 28 ))
then
written_time="it is twenty-five $adverb $txthour"
elif (( min < 33 ))
then
written_time="it is half past $txthour"
else
exit 1
fi
box "$written_time"

9
scripts/.local/bin/getpid Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash
set -euo pipefail
srch="$1"
ps -ef | awk -v this="$0" -v search="$srch" '{
if($NF~search && $0!~this){print $2}
}'

28
scripts/.local/bin/hows-my-gpu Executable file
View file

@ -0,0 +1,28 @@
#!/bin/bash
#set -x
echo "Loaded Graphics Cards Kernel Drivers:"
nvidia_output=$(lspci -nnk | grep -A 3 -P '^(\d{4}:)?\d{2}:\d{2}\.\d\s+VGA compatible controller.*NVIDIA')
if [ ! -z "$nvidia_output" ]; then
echo "-------------------------------------"
echo "NVIDIA Graphics:"
echo "$nvidia_output" | grep "Kernel driver in use"
echo
fi
intel_output=$(lspci -nnk | grep -A 3 -P '^(\d{4}:)?\d{2}:\d{2}\.\d\s+VGA compatible controller.*Intel')
if [ ! -z "$intel_output"]; then
echo "-------------------------------------"
echo "Intel Graphics:"
echo "$intel_output" | grep "Kernel driver in use"
echo
fi
amd_output=$(lspci -nnk | grep -A 3 -P '^(\d{4}:)?\d{2}:\d{2}\.\d\s+VGA compatible controller.*AMD')
if [ ! -z "$amd_output"]; then
echo "-------------------------------------"
echo "AMD Graphics:"
echo "$amd_output" | grep "Kernel driver in use"
echo
fi

3
scripts/.local/bin/lollo Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
toilet -f bigmono12.tlf "$1" | lolcat

3
scripts/.local/bin/mountbackup Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
sshfs matthieu.fortin@172.31.180.4:/home/matthieu.fortin/backups /home/matt/backups_remote

18
scripts/.local/bin/mounttcli Executable file
View file

@ -0,0 +1,18 @@
#!/bin/bash
SMB_SHARE="//172.31.180.4/TCLI-Data-Repo"
MOUNT_POINT="/home/mfortin/TCLI-Data-Repo"
USER="matthieu.fortin"
PASSWORD="New42d@y"
if [ ! -d "$MOUNT_POINT" ]; then
mkdir -p "$MOUNT_POINT"
fi
sudo mount -t cifs "$SMB_SHARE" "$MOUNT_POINT" -o username="$USER",password="$PASSWORD"
if mountpoint -q "$MOUNT_POINT"; then
echo "Successfully mounted $SMB_SHARE at $MOUNT_POINT"
else
echo "Failed to mount $SMB_SHARE"
fi

View file

@ -0,0 +1,9 @@
#!/bin/bash
sudo virsh nodedev-reattach pci_0000_01_00_0
echo "GPU reattached (now host ready)"
sudo rmmod vfio_pci vfio_pci_core vfio_iommu_type1
echo "VFIO drivers removed"
sudo modprobe -i nvidia_modeset nvidia_uvm nvidia
echo "NVIDIA drivers added"
echo "COMPLETED!"

View file

@ -0,0 +1,9 @@
#!/bin/bash
sudo rmmod nvidia_modeset nvidia_uvm nvidia
echo "NVIDIA drivers removed"
sudo modprobe -i vfio_pci vfio_pci_core vfio_iommu_type1
echo "VFIO drivers added"
sudo virsh nodedev-detach pci_0000_01_00_0
echo "GPU detached (now vfio ready)"
echo "COMPLETED!"

BIN
scripts/.local/bin/oh-my-posh Executable file

Binary file not shown.

22
scripts/.local/bin/wallpaper Executable file
View file

@ -0,0 +1,22 @@
#!/bin/bash
# Check if the user provided an image file
if [ $# -eq 0 ]; then
echo "Usage: $0 <image_file>"
exit 1
fi
INPUT_IMAGE="$1"
# Generate PNG file
WALLPAPER="$HOME/.cache/images/wallpaper.png"
magick "$INPUT_IMAGE" "$WALLPAPER"
# Generate a blurred wallpaper with blur settings (50x30)
BLURRED_WALLPAPER="$HOME/.cache/images/blurred_wallpaper.png"
magick "$INPUT_IMAGE" -blur 50x30 "$BLURRED_WALLPAPER"
# Generate a square image (resize while maintaining aspect ratio)
SQUARE_WALLPAPER="$HOME/.cache/images/square_wallpaper.png"
magick "$INPUT_IMAGE" -gravity center -extent 1:1 "$SQUARE_WALLPAPER"
echo "Generated $BLURRED_WALLPAPER and $SQUARE_WALLPAPER"

28
scripts/.local/bin/weather Executable file
View file

@ -0,0 +1,28 @@
#!/bin/bash
set -euo pipefail
infoweather=$(curl -s 'wttr.in/Ottawa?format=%C:%t&period=60')
IFS=':' read -r condition temperature <<<"$infoweather"
case ${condition} in
"Clear" | "Sunny") condition="" ;;
"Cloudy") condition="" ;;
"Mist" | "Fog") condition="" ;;
"Heavy Rain") condition="" ;;
"HeavyShowers") condition="" ;;
"HeavySnow") condition="" ;;
"HeavySnowShowers") condition="" ;;
"Rain" | "Light Rain") condition="" ;;
"LightShowers") condition="" ;;
"LightSleet") condition="" ;;
"LightSleetShowers") condition="" ;;
"LightSnow") condition="" ;;
"LightSnowShowers") condition="" ;;
"Overcast") condition="" ;;
"Partly cloudy") condition="" ;;
"ThunderyHeavyRain") condition="" ;;
"ThunderyShowers") condition="" ;;
"ThunderySnowShowers") condition="" ;;
"VeryCloudy") condition="" ;;
*) condition=" ${condition}" ;;
esac
echo -ne "${condition} ${temperature}"

BIN
scripts/.local/bin/zoxide Executable file

Binary file not shown.