Skip to main content

makefileMaker.sh

Mar 7, 2021LeifMessinger
Loading...

More Shell Posts

diskRipper.sh

Apr 21, 2021LeifMessinger

0 likes • 0 views

#diskRipper.sh by Leif Messinger
#For use on debian, where your cds aren't immediately mounted
wall "CD inserted boss"
set -x #echo on
cdDrivePath=$(ls -l /dev/cdrom | awk '{print $NF}')
#CD could have no label, so that's why I need awk
cdLabel=$(lsblk -n "/dev/$cdDrivePath" -o label)
if [[ ! -z "$cdLabel" ]]; then #CD has label
folderName=$cdLabel
echo "The cd label is ${folderName}"
if mkdir ./cds/"${folderName}"; then #Folder didn't exist before
sudo mount /dev/cdrom ./.cdmountpoint
sudo cp -r ./.cdmountpoint/* "./cds/${folderName}"
sudo chmod -R 777 "./cds/${folderName}"
sudo umount ./.cdmountpoint
eject
wall "CD done and ejecting"
else
wall "Already read that cd, skipped"
fi
else
wall "CD had no label, skipped"
fi

makeHeaderTags.sh

Feb 5, 2024LeifMessinger

0 likes • 8 views

#!/bin/bash
# Recursively find all .svelte files in the current directory and its subdirectories
find . -type f -name "*.svelte" -o -name "*.html" -o -name "*.htm" | while read file; do
# Replace all h1 tags with the specified format
sed -i 's/<h1>\(.*\)<\/h1>/<h1 id="\1">\1<\/h1>/g' "$file"
# Replace all h2 tags with the specified format
sed -i 's/<h2>\(.*\)<\/h2>/<h2 id="\1">\1<\/h2>/g' "$file"
# Remove whitespace from the id attribute value
for i in {0..10} ; do
sed -i 's/\(id="[^"]*\)\W\([^"]*"\)/\1\2/g' "$file"
done
done

unexpandDirectory.sh

May 13, 2023LeifMessinger

0 likes • 1 view

#!/bin/bash
# Turns 4 spaces into tabs.
# Mostly stolen from AI
# Define the directory to process
DIRECTORY=$1
TabCount=${2:-'4'} #Defaults to 4
# Check if directory is specified
if [ -z "$DIRECTORY" ]; then
echo "Error: Directory not specified."
exit 1
fi
# Check if directory exists
if [ ! -d "$DIRECTORY" ]; then
echo "Error: Directory does not exist."
exit 1
fi
# Find all files in directory and subdirectories
FILES=$(find "$DIRECTORY" -type f)
# Loop through each file and unexpand it
for FILE in $FILES; do
unexpand -t "$TabCount" "$FILE" > "$FILE.tmp"
mv "$FILE.tmp" "$FILE"
done
echo "Done!"

Check For File

Aug 7, 2023CHS

0 likes • 2 views

# Three ways of checking if a file exists in a shell script
FILE=/etc/resolv.conf
if test -f "$FILE"; then
echo "$FILE exists."
fi
if [ -f "$FILE" ]; then
echo "$FILE exists."
fi
if [[ -f "$FILE" ]]; then
echo "$FILE exists."
fi

getDependencies.sh

Oct 30, 2020LeifMessinger

0 likes • 2 views

#!/bin/bash
#getDependencies.sh by Leif Messinger
grep -Po '#include\s*"\K.+(?=")' | while read -r line ; do
echo -n " $line"
./getDependencies.sh < $line
done

Bash Basics

Nov 19, 2022CodeCatch

0 likes • 1 view

name="John"
echo ${name}
echo ${name/J/j} #=> "john" (substitution)
echo ${name:0:2} #=> "Jo" (slicing)
echo ${name::2} #=> "Jo" (slicing)
echo ${name::-1} #=> "Joh" (slicing)
echo ${name:(-1)} #=> "n" (slicing from right)
echo ${name:(-2):1} #=> "h" (slicing from right)
echo ${food:-Cake} #=> $food or "Cake"