Skip to content

Instantly share code, notes, and snippets.

@adrianodias8
Created July 2, 2020 00:06
Show Gist options
  • Select an option

  • Save adrianodias8/d83577a3974d1cd4d8f0f3c97b5db9d3 to your computer and use it in GitHub Desktop.

Select an option

Save adrianodias8/d83577a3974d1cd4d8f0f3c97b5db9d3 to your computer and use it in GitHub Desktop.
projects turbo v1
#!/bin/bash
# This is the turbo mode for my dev enviroment.
# This creates ~/ramdisk dir mounts a tmpfs partion for current project location.
# Props to Stavros Kounis for idea.
# ===== Functions START =====
func_hello()
{
echo ""
echo "====== TURBO START ======"
# make sure that we have the ~/ramdisk folder;
mkdir -p ~/ramdisk
}
func_exit()
{
echo "====== TURBO END ======"
exit 0
}
func_check_project_size()
{
PROJECT_LOCATION=$(pwd)
PROJECT=$(basename $PROJECT_LOCATION)
PROJECT_SIZE=$(du -hs -BM . | cut -f1 | grep -Eo '[+-]?[0-9]+([.][0-9]+)?')
AVAILABLE_MEM=$(free -m | grep -oP '\d+' | head -n 1)
echo " PROJECT ==> ${PROJECT}"
echo " RAM NEEDED ==> ${PROJECT_SIZE}M"
echo " RAM AVAILABLE ==> ${AVAILABLE_MEM}M"
if [ $(expr $AVAILABLE_MEM / 3) \> $PROJECT_SIZE ];
then
echo " MUCH RAM SUCH WOW";
echo " READY TO FEEL THE BOOST";
else
echo "NO RAM NO FUN";
func_exit
fi;
}
func_mount_tmpfs()
{
SIZE="$(echo $PROJECT_SIZE + 500 | bc)M"
echo " ALOCATING $SIZE"
sudo mount -t tmpfs -o rw,size=$SIZE tmpfs ~/ramdisk
cp $PROJECT_LOCATION ~/ramdisk -R
}
# ===== Functions END =====
# ===== Execute START =====
func_hello
func_check_project_size
func_mount_tmpfs
func_exit
# ===== Execute END =====
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment