• Aug 7, 2023 •C S
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
• Nov 8, 2021 •LeifMessinger
0 likes • 1 view
#!/bin/bash #Installs the Vulkan library and other goodies. Works on Arch and Arch based distros. Needs pacman and makepkg installVulkan(){ #Tries installing every linux package in existence packages=( vulkan-tools libvulkan-dev vulkan-loader-devel vulkan-validation-layers spirv-tools mesa-vulkan-devel vulkan-validation-layers-devel ) for package in ${packages[*]}; do sudo pacman --noconfirm -S $package done } installLibraries(){ #All of these packages don't exist, so we have to download and install the AUR packages #packages=( libglfw3-dev glfw-devel libglm glm-devel ) #for package in ${packages[*]}; do # sudo pacman --noconfirm -S $package #done sudo git clone https://aur.archlinux.org/glfw-git.git /tmp/glfw-git sudo chmod 777 /tmp/glfw-git cd /tmp/glfw-git makepkg -si sudo git clone https://aur.archlinux.org/glm-git.git /tmp/glm-git sudo chmod 777 /tmp/glm-git cd /tmp/glm-git makepkg -si } installShaderCompiler(){ #Basically installs glslc sudo pacman -S shaderc } while true; do select bruh in installVulkan installLibraries installShaderCompiler "exit"; do $bruh done done
• Nov 19, 2022 •CodeCatch
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"
• Sep 9, 2023 •LeifMessinger
0 likes • 3 views
#!/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
• Apr 21, 2021 •LeifMessinger
0 likes • 6 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
• Mar 7, 2021 •LeifMessinger
0 likes • 10 views
#!/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 ""