Skip to main content

Bash Basics

0 likes • Nov 19, 2022 • 1 view
Shell
Loading...

More Shell Posts

pinger.sh

0 likes • Mar 21, 2021 • 0 views
Shell
#pinger.sh by Leif Messinger
#./pinger.sh [ADDRESS] to search
#./pinger.sh [ADDRESS] & to search in the background
#https://serverfault.com/a/42382
ping_cancelled=false # Keep track of whether the loop was cancelled, or succeeded
until ping -c1 "$1" >/dev/null 2>&1; do :; done & # The "&" backgrounds it
trap "kill $!; ping_cancelled=true" SIGINT
wait $! # Wait for the loop to exit, one way or another
trap - SIGINT # Remove the trap, now we're done with it
if [ "$ping_cancelled" == true ] #https://stackoverflow.com/a/21210966/10141528
then
printf "The pinger for $1 just closed bro.\n"
else
printf "$1 IS UP BROOO\a\n"
fi

githubSetSSH.sh

0 likes • Sep 9, 2023 • 2 views
Shell
#!/bin/bash
#Changes the remote url from https to ssh.
#Only works for github, because I'd have to store a dictionary of every https to ssh url otherwise.
#Made using Bing Chat
# Get the remote URL from the console
REPO_URL=$(git config --get remote.origin.url)
# Check that REPO_URL contains https://github.com
if [[ $REPO_URL == *"https://github.com"* ]]; then
# Replace https with ssh in the URL
REPO_URL=${REPO_URL/https:\/\/github.com\//[email protected]:}
# Change the remote URL to the SSH version
git remote set-url origin "$REPO_URL"
else
echo "Error: REPO_URL does not contain https://github.com" >&2
exit 1
fi

Useful NVM Commands

CHS
0 likes • Mar 20, 2023 • 0 views
Shell
// check version
node -v || node --version
// list installed versions of node (via nvm)
nvm ls
// install specific version of node
nvm install 6.9.2
// set default version of node
nvm alias default 6.9.2
// switch version of node
nvm use 6.9.1

makefileMaker.sh

0 likes • Mar 7, 2021 • 1 view
Shell
#!/bin/bash
#makefileMaker.sh by Leif Messinger
#Needs getDependencies.sh
CC="gcc"
#I have no idea why it's called CXX when it's a c++ compiler
#I know that cpp is c pre processor, but still, why X?
CXX="g++"
CXXFLAGS="-std=c++17 -O2"
#CFLAGS="-std=c17"
LIBRARIES="$@"
#Vulkan Flags for me
#LIBRARIES="-lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi"
function compileAllFiles(){
#output: bruh.o yeet.o
# CXX $CXXFLAGS bruh.o yeet.o -o output $LIBRARIES
echo -n "output:"
if compgen -G "*.cpp" &> /dev/null; then
for f in *.cpp; do
echo -n " ${f%.cpp}.o"
done
fi
if compgen -G "*.c" &> /dev/null; then
for f in *.c; do
echo -n " ${f%.c}.o"
done
fi
echo ""
if compgen -G "*.cpp" &> /dev/null; then
echo -e -n "\t$CXX $CXXFLAGS "
else
echo -e -n "\t$CC $CFLAGS "
fi
if compgen -G "*.cpp" &> /dev/null; then
for f in *.cpp; do
echo -n " ${f%.cpp}.o"
done
fi
if compgen -G "*.c" &> /dev/null; then
for f in *.c; do
echo -n " ${f%.c}.o"
done
fi
echo " -o output $LIBRARIES"
echo ""
}
function compileAllObjectFiles(){
#bruh.o: bruh.cpp yeet.h
# CXX $CXXFLAGS -c bruh.cpp $LIBRARIES
if compgen -G "*.cpp" &> /dev/null; then
for f in *.cpp; do
echo -n "${f%.cpp}.o: $f"
getDependencies.sh < $f
echo ""
echo -e "\t$CXX $CXXFLAGS -c $f"
echo ""
done
fi
#yeet.o: yeet.c
# CC $CFLAGS -c yeet.c $LIBRARIES
if compgen -G "*.c" &> /dev/null; then
for f in *.c; do
echo -n "${f%.c}.o: $f"
getDependencies.sh < $f
echo ""
echo -e "\t$CC $CFLAGS -c $f"
echo ""
done
fi
}
compileAllFiles
compileAllObjectFiles
#does not work on windows
echo "clean:"
echo -e "\trm -f -v *.o output"
echo ""
echo "run:"
echo -e "\t./output"
echo ""
echo "debug:"
if compgen -G "*.cpp" &> /dev/null; then
echo -e -n "\t$CXX $CXXFLAGS -g "
else
echo -e -n "\t$CC $CFLAGS -g "
fi
if compgen -G "*.cpp" &> /dev/null; then
for f in *.cpp; do
echo -n " ${f}"
done
fi
if compgen -G "*.c" &> /dev/null; then
for f in *.c; do
echo -n " ${f}"
done
fi
echo " $LIBRARIES -o output"
echo ""

credit.sh

0 likes • Oct 26, 2021 • 0 views
Shell
#!/bin/bash
#Leif Messinger lsm0147
#credit.sh FILES
cred="Leif Messinger lsm0147"
for bruh; do
if [[ $bruh =~ \.cpp|\.c|\.java|\.js ]]; then
comment="//$cred"
else
#Basically everything else gets a pound sign comment
#Pound signs are standard across linux. bash, sed, gawk, python etc
#Speaking of which, I need to escape it because of that.
comment="\#$cred"
fi
if [ -s $bruh ]; then
#If the file has a shebang
if egrep -q '^#!/' $bruh; then
sed -i "/^\#!\//a$comment" $bruh
else
sed -i "1i$comment" $bruh
fi
else
echo "$comment" > $bruh
fi
done

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