Skip to main content

unexpandDirectory.sh

0 likes • May 13, 2023 • 1 view
Shell
Loading...

More Shell Posts

makeHeaderTags.sh

0 likes • Feb 5, 2024 • 8 views
Shell
#!/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

Bash Basics

0 likes • Nov 19, 2022 • 1 view
Shell
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"

Symlink Desktop

0 likes • Nov 18, 2022 • 0 views
Shell
#
# Austin Leath
# checks for /Desktop symlink. Creates the symlink if it doesnt already exist
#
#Fetch the target user if desired, otherwise use the currently logged in user.
if [ "$4" != "" ]; then
TARGET_USER=$4
else
TARGET_USER=$3
fi
if [ "$5" != "" ]; then
DIRECTORY_NAME=$5
else
TARGET_USER="$3 Desktop"
fi
# Functions
CHECK_SYMLINK() {
if test -f "/Desktop"; then
echo "/Desktop exists"
else
echo "/Desktop does not exist"
fi
}
CHECK_SYNTHETIC_CONF() {
if test -f "/etc/synthetic.conf"; then
echo "/etc/synthetic.conf exists"
else
echo "/etc/synthetic.conf does not exist"
fi
}
CREATE_SYMLINK() {
if [[ $(CHECK_SYNTHETIC_CONF) != "/etc/synthetic.conf exists" ]]; then
echo "/etc/synthetic.conf does not exist. creating.."
touch /etc/synthetic.conf
chown -R root:wheel /etc/synthetic.conf
fi
if grep -q "$DIRECTORY_NAME" /etc/synthetic.conf; then
echo "$DIRECTORY_NAME already exists"
exit 1
else
echo "$DIRECTORY_NAME\t/Users/$TARGET_USER/Desktop" >> /etc/synthetic.conf
fi
echo "/Desktop symbolic link created"
}
if [[ $(CHECK_SYMLINK) != "/Desktop exists" ]]; then
CREATE_SYMLINK
fi
exit 0

checkAndPush.sh

0 likes • Nov 4, 2023 • 6 views
Shell
#!/bin/bash
git status
echo "Do you want to add all changed files?"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) exit 1;;
esac
done
git add -u
git status
echo "Does this look right?"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) exit 2;;
esac
done
git commit
echo "Do you want to push?"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) exit 2;;
esac
done
git push

watchLogins.sh

0 likes • Sep 30, 2021 • 0 views
Shell
touch /tmp/login1.txt /tmp/login2.txt
while [ true ]
do
who | gawk '{ print $1 }' > /tmp/login2.txt
comm -13 /tmp/login1.txt /tmp/login2.txt
#Just a bit easier to read
#diff /tmp/login1.txt /tmp/login2.txt
cat /tmp/login2.txt > /tmp/login1.txt
sleep 1
done

LeetCode #192: Word Frequency

0 likes • Oct 15, 2022 • 40 views
Shell
awk '\
{ for (i=1; i<=NF; i++) { ++D[$i]; } }\
END { for (i in D) { print i, D[i] } }\
' words.txt | sort -nr -k 2