Skip to main content

Outputs list of $PATH dirs sorted by line length

0 likes • Nov 18, 2022 • 0 views
Shell
Loading...

More Shell Posts

Check For File

CHS
0 likes • Aug 7, 2023 • 2 views
Shell
# 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

Delete Git Branches

0 likes • Mar 10, 2023 • 0 views
Shell
#!/bin/bash
for branch in $(git branch | cut -c 3-); do
read -p "Delete local branch $branch? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
git branch -D $branch
fi
done

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 ""

installVulkan.sh

0 likes • Nov 8, 2021 • 0 views
Shell
#!/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

codecatch.sh

0 likes • Nov 14, 2021 • 0 views
Shell
#!/bin/bash
#Takes all the c and h files in the current directory and prints them
#Yup, it's that easy
for file in *.h *.hpp *.c *.cpp; do
#If it exists
if [ -f "$file" ]; then
echo "//===============$file==============="
cat $file
fi
done

cpcmd.sh

0 likes • Sep 29, 2021 • 19 views
Shell
#!/bin/bash
#cpcmd.sh [file1 [file2...]]
#Prints out the commands needed to copy the file to your local machine
#This will work on any server that also has the same hostname as in your hosts file.
#I should update this to detect if a file is a directory, and enable recursion for those commands. If you do it now, it will probably just warn you.
if [ -n "$1" ]; then
while [ -n "$1" ]; do
printf "scp \"$(whoami)@$(hostname):"
printf `readlink -f $1`
printf "\" .\n"
shift
done
else
echo "scp \"$(whoami)@$(hostname):$PWD/*\" ."
fi
#-----------EDIT:
#On the UNT cell machines, you have to do this script instead
#if [ -n "$1" ]; then
# while [ -n "$1" ]; do
# printf "scp $(whoami)@$(hostname).eng.unt.edu:"
# printf `readlink -f $1`
# printf " .\n"
# shift
# done
#else
# echo "scp $(whoami)@$(hostname).eng.unt.edu:$PWD/* ."
#fi