Skip to content

Commit

Permalink
A Dynamic Collection of Shell Scripts with Educational Purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
felipefacundes committed Feb 17, 2025
1 parent 4c3173b commit b41044f
Show file tree
Hide file tree
Showing 18 changed files with 253 additions and 7,874 deletions.
7,777 changes: 0 additions & 7,777 deletions books/Expressões Regulares - 5ª edição Uma Abordagem Divertida.txt

This file was deleted.

Binary file removed books/mapa-mundi.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion scripts/all_bright
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ fi

set -e

bright_file="/tmp/variable_brightness.value"
TMPDIR="${TMPDIR:-/tmp}"
bright_file="${TMPDIR}/variable_brightness.value"
connected=$(xrandr | grep -w connected | awk '{print $1}')

if [ ! -s "$bright_file" ]; then
Expand Down
5 changes: 3 additions & 2 deletions scripts/bing_wallpaper
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ DOCUMENTATION

# Bing Random Wallpaper

#set -x
TMPDIR="${TMPDIR:-/tmp}"

script="${0##*/}"
declare -A resolution
resolution[hd]='1280x720'
resolution[hd2]='1366x768'
resolution[fullhd]='1920x1080'

WP_DIR="/tmp/wallpapers"
WP_DIR="${TMPDIR}/wallpapers"
WP_FILE="$WP_DIR/bing_wallpaper.jpg"

# Create the wallpapers directory if it does not exist
Expand Down
6 changes: 4 additions & 2 deletions scripts/bing_wallpaper_simple
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ DOCUMENTATION

# Bing Random Wallpaper

WP_DIR="/tmp/wallpapers"
TMPDIR="${TMPDIR:-/tmp}"

WP_DIR="${TMPDIR}/wallpapers"
WP_FILE="$WP_DIR/bing_wallpaper.jpg"

# Create the wallpapers directory if it doesn't exist
mkdir -p $WP_DIR
mkdir -p "$WP_DIR"

# Generate a random number between 0 and 7
IDX=$((RANDOM % 8))
Expand Down
131 changes: 82 additions & 49 deletions scripts/books
Original file line number Diff line number Diff line change
Expand Up @@ -21,71 +21,104 @@ Capabilities:
- Provides a clean exit option for users.
DOCUMENTATION

clear -T "$TERM"
#!/bin/bash

export books_folder="${HOME}/.shell_utils/books"
cd "${books_folder}" || exit
clear

# Allowed formats: pdf, txt, epub
books_list=(*.*)
cd - >/dev/null || exit
TMPDIR="${TMPDIR:-/tmp}"
XDG_DOCUMENTS_DIR=${XDG_DOCUMENTS_DIR:-$(xdg-user-dir DOCUMENTS 2>/dev/null || echo "$HOME/Documents")}

books_list(){
# Setting the eBook folders
books_folder="${HOME}/.shell_utils/books"
xdg_books_folder="${XDG_DOCUMENTS_DIR}/Books"

number=0
echo 'Books available:'
[[ ! -d "${xdg_books_folder}" ]] && mkdir -p "${xdg_books_folder}"

for list in "${books_list[@]}";
do
let number++
echo -e "${number}) ${list}\n"
done
# Combining the two folders to get all ebooks
books_list=("${books_folder}"/*.* "${xdg_books_folder}"/*.*)

echo -e "\n"'Enter "q" for exit'"\n"
echo 'And choose the book you want in the next step'
# ANSI color for highlighting the selected book
highlight="\033[44;1;32m" # Cyan background, bold green text
nc="\033[0m" # Reset

# Function to display books list
books_list_func() {
number=0
for list in "${books_list[@]}"; do
if [[ $number -eq $selected ]]; then
# Highlight the selected book
echo -e "$highlight$number) ${list}$nc"
else
# Display other books normally
echo -e "$number) ${list}"
fi
((number++)) || true
done
}

# Interactive book selection
select_book(){

read -r book
#re='^[0-9]+$'

#if ! [[ "${book}" =~ $re ]] ; then
if [ "${book}" -ge 0 ] > /dev/null 2>&1; then
#read -r book

if [[ "${book}" -ge 0 && "${book}" -lt "${#books_list[@]}" ]]; then
declare -l ext_test
ext_test=$(echo "${books_folder}/${books_list[book]}" | awk -F. '{print $NF}')

if [ "${ext_test}" = txt ]; then
cat "${books_folder}/${books_list[book]}" | less -i -R

elif [ "${ext_test}" = epub ]; then
epr "${books_folder}/${books_list[book]}"

elif [ "${ext_test}" = pdf ]; then
rm -f /tmp/temp_book.txt
pdftotext -layout -nopgbrk "${books_folder}/${books_list[book]}" /tmp/temp_book.txt
cat /tmp/temp_book.txt | less -i -R


# Uses `awk` to split the string by the dot and capture the last part (extension).
#ext_test=$(echo "${books_list[book]}" | awk -F. '{print $NF}')

# Uses Bash parameter expansion to capture everything after the last dot, without external utilities.
#ext_test="${books_list[book]##*.}"

# Ensures the value of the variable is handled correctly with spaces, using quotes to preserve the full filename.
ext_test="${books_list[$selected]##*.}"

if [[ "${ext_test}" == [Tt][Xx][Tt] ]]; then
cat "${books_list[$selected]}" | less -i -R
elif [[ "${ext_test}" == [Ee][Pp][Uu][Bb] ]]; then
epr "${books_list[$selected]}"
elif [[ "${ext_test}" == [Pp][Dd][Ff] ]]; then
rm -f "${TMPDIR}/temp_book.txt"
pdftotext -layout -nopgbrk "${books_list[$selected]}" "${TMPDIR}/temp_book.txt"
cat "${TMPDIR}/temp_book.txt" | less -i -R
else
echo 'Unrecognized format'
fi

else
echo -e "\nerror: \"${book}\" not is number!"

echo -e "\nerror: \"${selected}\" is not a valid number!"
fi

}

if [ "${#books_list[@]}" -gt 0 ]; then

books_list | less -i -R
echo -e "Enter the number corresponding to the book. And then press ENTER.\n"
select_book

else
echo "books not found"

fi
# Interactive navigation with w/s for selecting a book
selected=0
while true; do
clear
echo -e "\nUse w/s to navigate, enter to select a book.\n"
books_list_func
echo -e "\nEnter the number corresponding to the book. And then press ENTER.\n"

read -r -n 1 -s key

case $key in
w|W) # W key to move up
if [[ $selected -gt 0 ]]; then
selected=$((selected - 1))
fi
;;
s|S) # S key to move down
if [[ $selected -lt $((${#books_list[@]} - 1)) ]]; then
selected=$((selected + 1))
fi
;;
"") # Enter to select
break
;;
*) # Any other key
echo -e "\nInvalid key!"
;;
esac
done

# Display the selected book with highlight
clear
echo -e "$highlight You selected: ${books_list[$selected]} $nc"
select_book
54 changes: 28 additions & 26 deletions scripts/cartoonize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ else
)
fi

TMPDIR="${TMPDIR:-/tmp}"

help() {
cat << EOF
${MESSAGES[USAGE]}
Expand All @@ -94,15 +96,15 @@ EOF
# Cartoonization functions
cartoonize() {
for i in *.[jJpP][nNpP][gG]; do
convert "$i" -colors 64 -paint 4 -compose over -compose multiply \
magick "$i" -colors 64 -paint 4 -compose over -compose multiply \
-modulate 100,150,100 -posterize 24 -blur 0x2 -set filename:base "%[basename]" \
"%[filename:base]-cartoon.png"
done
}

cartoonize2() {
for i in *.[jJpP][nNpP][gG]; do
convert "$i" \( -clone 0 -blur 0x5 \) \( -clone 0 -fill black -colorize 100 \) \
magick "$i" \( -clone 0 -blur 0x5 \) \( -clone 0 -fill black -colorize 100 \) \
\( -clone 0 -define convolve:scale="!" -define morphology:compose=Lighten \
-morphology Convolve "Sobel:>" -negate -evaluate pow 5 -negate -level 30x100% \) \
-delete 0 -compose over -composite -set filename:base "%[basename]" \
Expand All @@ -112,7 +114,7 @@ cartoonize2() {

cartoonize3() {
for i in *.[jJpP][nNpP][gG]; do
convert "$i" -colors 64 -paint 4 -compose over -compose multiply \
magick "$i" -colors 64 -paint 4 -compose over -compose multiply \
-modulate 100,150,100 -posterize 24 -blur 0x2 -define morphology:compose=Lighten \
-morphology Convolve "Sobel:>" -negate -evaluate pow 5 -negate -level 30x100% \
-set filename:base "%[basename]" "%[filename:base]-cartoon.png"
Expand All @@ -121,23 +123,23 @@ cartoonize3() {

cartoonize4() {
for i in *.[jJpP][nNpP][gG]; do
convert -quiet "$i" +repage -depth 8 -selective-blur 0x5+10% /tmp/pre-cartoon1.mpc
convert /tmp/pre-cartoon1.mpc -level 0x60% -colorspace gray -posterize 6 -depth 8 \
-gamma 2.2 /tmp/pre-cartoon2.mpc
PreCartoon1=/tmp/pre-cartoon1.mpc
PreCartoon2=/tmp/pre-cartoon2.mpc
convert "$PreCartoon1" \( "$PreCartoon2" -blur 0x1 \) \( -clone 0 -clone 1 -compose over \
magick -quiet "$i" +repage -depth 8 -selective-blur 0x5+10% "${TMPDIR}/pre-cartoon1.mpc"
magick "${TMPDIR}/pre-cartoon1.mpc" -level 0x60% -colorspace gray -posterize 6 -depth 8 \
-gamma 2.2 "${TMPDIR}/pre-cartoon2.mpc"
PreCartoon1=${TMPDIR}/pre-cartoon1.mpc
PreCartoon2=${TMPDIR}/pre-cartoon2.mpc
magick "$PreCartoon1" \( "$PreCartoon2" -blur 0x1 \) \( -clone 0 -clone 1 -compose over \
-compose multiply -composite -modulate 100,150,100 \) \( -clone 0 -colorspace gray \) \
\( -clone 3 -negate -blur 0x2 \) \( -clone 3 -clone 4 -compose over -compose colordodge \
-composite -evaluate pow 4 -threshold 90% -statistic median 3x3 \) -delete 0,1,3,4 \
-compose over -compose multiply -composite "${i/.[jJpP][nNpP][gG]/-cartoon.png}"
rm /tmp/pre-cartoon1.mpc /tmp/pre-cartoon2.mpc
rm "${TMPDIR}/pre-cartoon1.mpc" "${TMPDIR}/pre-cartoon2.mpc"
done
}

cartoonize4_other_method() {
for i in *.[jJpP][pPnN][gG]; do
convert "$i" +repage -depth 8 -selective-blur 0x5+10%% \( -clone 0 -level 0x60%% -colorspace gray \
magick "$i" +repage -depth 8 -selective-blur 0x5+10%% \( -clone 0 -level 0x60%% -colorspace gray \
-posterize 6 -depth 8 -gamma 2.2 -blur 0x1 \) \( -clone 0 -clone 1 -compose multiply -composite \
-modulate 100,150,100 \) \( -clone 0 -colorspace gray \) \( -clone 3 -negate -blur 0x2 \) \( -clone 3 \
-clone 4 -compose colordodge -composite -evaluate pow 4 -threshold 90%% -statistic median 3x3 \) -delete 0,1,3,4 \
Expand All @@ -150,45 +152,45 @@ cartoonize5() {
dx="-$convolution,0,$convolution,-$convolution,0,$convolution,-$convolution,0,$convolution"
dy="$convolution,$convolution,$convolution,0,0,0,-$convolution,-$convolution,-$convolution"
for i in *.[jJpP][nNpP][gG]; do
convert "$i" -quiet -regard-warnings -colorspace RGB +repage /tmp/pre-cartoon1.jpg
convert \( /tmp/pre-cartoon1.jpg -median 2 \) \( -size 1x256 gradient: -rotate 90 \
-fx "floor(u*10+0.5)/10" \) -clut /tmp/pre-cartoon2.jpg
convert \( /tmp/pre-cartoon1.jpg -colorspace gray -median 2 \) \( -clone 0 -bias 50% \
magick "$i" -quiet -regard-warnings -colorspace RGB +repage "${TMPDIR}/pre-cartoon1.jpg"
magick \( "${TMPDIR}/pre-cartoon1.jpg" -median 2 \) \( -size 1x256 gradient: -rotate 90 \
-fx "floor(u*10+0.5)/10" \) -clut "${TMPDIR}/pre-cartoon2.jpg"
magick \( "${TMPDIR}/pre-cartoon1.jpg" -colorspace gray -median 2 \) \( -clone 0 -bias 50% \
-convolve "$dx" -solarize 50% \) \( -clone 0 -bias 50% -convolve "$dy" -solarize 50% \) \
\( -clone 1 -clone 1 -compose multiply -composite -gamma 2 \) \( -clone 2 -clone 2 \
-compose multiply -composite -gamma 2 \) -delete 0-2 -compose plus -composite \
-threshold 75% /tmp/pre-cartoon3.jpg
convert /tmp/pre-cartoon2.jpg /tmp/pre-cartoon3.jpg -compose multiply -composite \
-threshold 75% "${TMPDIR}/pre-cartoon3.jpg"
magick "${TMPDIR}/pre-cartoon2.jpg" "${TMPDIR}/pre-cartoon3.jpg" -compose multiply -composite \
"${i/.[jJpP][nNpP][gG]/-cartoon.png}"
rm /tmp/pre-cartoon1.jpg /tmp/pre-cartoon2.jpg /tmp/pre-cartoon3.jpg
rm "${TMPDIR}/pre-cartoon1.jpg" "${TMPDIR}/pre-cartoon2.jpg" "${TMPDIR}/pre-cartoon3.jpg"
done
}

cartoonize6() {
for i in *.[jJpP][nNpP][gG]; do
convert -quiet "$i" +repage -depth 8 -selective-blur 0x5+10% /tmp/pre-cartoon1.jpg
convert /tmp/pre-cartoon1.jpg -level 0x60 -set colorspace RGB -colorspace gray \
-posterize 6 -depth 8 -colorspace sRGB /tmp/pre-cartoon2.jpg
export PreCartoon1=/tmp/pre-cartoon1.jpg; export PreCartoon2=/tmp/pre-cartoon2.jpg
convert "$PreCartoon1" \( "$PreCartoon2" -blur 0x1 \) \( -clone 0 -clone 1 -compose over \
magick -quiet "$i" +repage -depth 8 -selective-blur 0x5+10% "${TMPDIR}/pre-cartoon1.jpg"
magick "${TMPDIR}/pre-cartoon1.jpg" -level 0x60 -set colorspace RGB -colorspace gray \
-posterize 6 -depth 8 -colorspace sRGB "${TMPDIR}/pre-cartoon2.jpg"
export PreCartoon1=${TMPDIR}/pre-cartoon1.jpg; export PreCartoon2=${TMPDIR}/pre-cartoon2.jpg
magick "$PreCartoon1" \( "$PreCartoon2" -blur 0x1 \) \( -clone 0 -clone 1 -compose over \
-compose multiply -composite -modulate 100,150,100 \) \( -clone 0 -set colorspace RGB \
-colorspace gray \) \( -clone 3 -negate -blur 0x4 \) \( -clone 3 -clone 4 -compose over \
-compose colordodge -composite -evaluate pow 4 -threshold 4 -statistic median 3x3 \) \
-delete 0,1,3,4 -compose over -compose multiply -composite "${i/.[jJpP][nNpP][gG]/-cartoon.png}"
rm /tmp/pre-cartoon1.jpg /tmp/pre-cartoon2.jpg
rm "${TMPDIR}/pre-cartoon1.jpg" "${TMPDIR}/pre-cartoon2.jpg"
done
}

cartoonize7() {
for i in *.[jJpP][nNpP][gG]; do
convert "$i" -colorspace gray -kuwahara 3 -unsharp 0x2+4+0 \
magick "$i" -colorspace gray -kuwahara 3 -unsharp 0x2+4+0 \
\( xc:blue xc:red xc:yellow +append \) -clut "${i/.[jJpP][nNpP][gG]/-cartoon.png}"
done
}

cartoonize8() {
for i in *.[jJpP][nNpP][gG]; do
convert "$i" -kuwahara 3 -unsharp 0x2+4+0 "${i/.[jJpP][nNpP][gG]/-cartoon.png}"
magick "$i" -kuwahara 3 -unsharp 0x2+4+0 "${i/.[jJpP][nNpP][gG]/-cartoon.png}"
done
}

Expand Down
6 changes: 4 additions & 2 deletions scripts/kernel_check_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ DOCUMENTATION
# Define a signal handler to capture SIGINT (Ctrl+C)
trap 'kill $(jobs -p)' SIGTERM #SIGHUP #SIGINT #SIGQUIT #SIGABRT #SIGKILL #SIGALRM #SIGTERM

TMPDIR="${TMPDIR:-/tmp}"

delay=10
kernel_booted_temp_file=/tmp/kernel_booted.temp_file
kernel_booted_temp_file=${TMPDIR}/kernel_booted.temp_file

if [[ ! -f "${kernel_booted_temp_file}" ]]; then
touch "${kernel_booted_temp_file}"
Expand Down Expand Up @@ -60,7 +62,7 @@ has_the_kernel_been_updated() {
do sleep "$delay"
installed_kernel="$(LC_ALL=en pacman -Si linux | grep -i "^Version" | awk '{print $3}' | sed 's|-|.|g')"
kernel_updated="$(LC_ALL=c ls -l /boot/initramfs-linux.img | awk '{print $6 $7 $8}')"
lock_file=/tmp/has_the_kernel_been_updated.lock_file
lock_file="${TMPDIR}/has_the_kernel_been_updated.lock_file"
icon=~/.shell_utils/icons/exclamation.png

if [[ "$kernel_initiated" != "$installed_kernel" ]]; then
Expand Down
4 changes: 3 additions & 1 deletion scripts/quake_terminal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# Credits: noctuid
# Script Name: tdrop

MUTDROP_PATH=/tmp/tdrop_"$USER"_"$DISPLAY"
TMPDIR="${TMPDIR:-/tmp}"

MUTDROP_PATH="${TMPDIR}/tdrop_${USER}_${DISPLAY}"
LOG_FILE="$MUTDROP_PATH"/log
NOAUTOHIDE_FILE="$MUTDROP_PATH"/no_autohide
GEO_DIR="$MUTDROP_PATH"/geometries
Expand Down
8 changes: 5 additions & 3 deletions scripts/sign.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Font: https://www.zimuel.it/blog/sign-and-verify-a-file-using-openssl
https://gist.github.com/ezimuel/3cb601853db6ebc4ee49
DOCUMENTATION

TMPDIR="${TMPDIR:-/tmp}"

filename=$1
privatekey=$2

Expand All @@ -27,6 +29,6 @@ if [[ $# -lt 2 ]] ; then
exit 1
fi

openssl dgst -sha256 -sign "$privatekey" -out /tmp/"$filename".sha256 "$filename"
openssl base64 -in /tmp/"$filename".sha256 -out signature.sha256
rm /tmp/"$filename".sha256
openssl dgst -sha256 -sign "$privatekey" -out "${TMPDIR}/${filename}.sha256" "$filename"
openssl base64 -in "${TMPDIR}/${filename}.sha256" -out signature.sha256
rm "${TMPDIR}/${filename}.sha256"
4 changes: 3 additions & 1 deletion scripts/simple_battery_manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ DOCUMENTATION
# Define a signal handler to capture SIGINT (Ctrl+C)
trap 'kill $(jobs -p)' SIGTERM #SIGHUP #SIGINT #SIGQUIT #SIGABRT #SIGKILL #SIGALRM #SIGTERM

TMPDIR="${TMPDIR:-/tmp}"

icon=~/.shell_utils/icons/exclamation.png
log_file=~/.battery_check_unplugged.log
lock_file=/tmp/battery_check_unplugged.lock_file
lock_file="${TMPDIR}/battery_check_unplugged.lock_file"
shutdown=false

while true
Expand Down
Loading

0 comments on commit b41044f

Please sign in to comment.