Created
February 25, 2021 18:45
-
-
Save bobymicroby/c4a1d50cc4a27fecb9a473f4d1ed5709 to your computer and use it in GitHub Desktop.
Move Idea Caches to Ram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -x | |
# The RAM amount you want to allocate for RAM disk. One of | |
# 1024 2048 3072 4096 5120 6144 7168 8192 | |
# By default will use 1/4 of your RAM | |
ramfs_size_mb=2048 | |
mount_point=/Users/${USER}/ramdisk | |
ramfs_size_sectors=$((ramfs_size_mb*1024*1024/512)) | |
ramdisk_device=$(hdid -nomount ram://${ramfs_size_sectors} | xargs) | |
USERRAMDISK="${mount_point}" | |
MSG_MOVE_CACHE=". Do you want me to move its cache? Note: It will close the app." | |
MSG_PROMPT_FOUND="I found " | |
# | |
# Checks for the user response. | |
# | |
user_response() | |
{ | |
echo -ne "$@" "[Y/n] " | |
read -r response | |
case ${response} in | |
[yY][eE][sS]|[yY]|"") | |
true | |
;; | |
[nN][oO]|[nN]) | |
false | |
;; | |
*) | |
user_response "$@" | |
;; | |
esac | |
} | |
# | |
# Closes passed as arg app by name | |
# | |
close_app() | |
{ | |
osascript -e "quit app \"${1}\"" | |
} | |
# | |
# Creates RAM Disk. | |
# | |
mk_ram_disk() | |
{ | |
# unmount if exists and mounts if doesn't | |
umount -f "${mount_point}" | |
newfs_hfs -v 'ramdisk' "${ramdisk_device}" | |
mkdir -p "${mount_point}" | |
mount -o noatime -t hfs "${ramdisk_device}" "${mount_point}" | |
echo "created RAM disk." | |
# Hide RAM disk - we don't really need it to be annoiyng in finder. | |
# comment out should you need it. | |
echo "RAM disk hidden" | |
} | |
# Checks that we have | |
# all required utils before proceeding | |
check_requirements() | |
{ | |
hash newfs_hfs 2>/dev/null || { echo >&2 "No newfs_hfs has been found. Aborting."; exit 1; } | |
} | |
# | |
# Check existence of the string in a file. | |
# | |
check_string_in_file() | |
{ | |
if grep "${1}" "${2}" == 0; then | |
return 0; | |
else | |
return 1; | |
fi | |
} | |
# | |
# Intellij Idea | |
# | |
move_idea_cache() | |
{ | |
if [ -d "/Applications/IntelliJ IDEA.app" ]; then | |
if user_response "${MSG_PROMPT_FOUND}" 'IntelliJ IDEA'"${MSG_MOVE_CACHE}" ; then | |
close_app "IntelliJ Idea" | |
# make a backup of config - will need it when uninstalling | |
cp -f /Applications/IntelliJ\ IDEA.app/Contents/bin/idea.properties /Applications/IntelliJ\ IDEA.app/Contents/bin/idea.properties.back | |
# Idea will create those dirs | |
echo "idea.system.path=${USERRAMDISK}/Idea" >> /Applications/IntelliJ\ IDEA.app/Contents/bin/idea.properties | |
echo "idea.log.path=${USERRAMDISK}/Idea/logs" >> /Applications/IntelliJ\ IDEA.app/Contents/bin/idea.properties | |
echo "Moved IntelliJ cache." | |
fi | |
fi | |
} | |
# | |
# Creates intelliJ intermediate output folder | |
# to be used by java/scala projects. | |
# | |
create_intermediate_folder_for_intellij_projects() | |
{ | |
[ -d /Volumes/ramdisk/"${USER}"/compileroutput ] || mkdir -p /Volumes/ramdisk/"${USER}"/compileroutput | |
} | |
# ----------------------------------------------------------------------------------- | |
# The entry point | |
# ----------------------------------------------------------------------------------- | |
main() { | |
check_requirements | |
# and create our RAM disk | |
mk_ram_disk | |
# move the caches | |
move_idea_cache | |
# create intermediate folder for intellij projects output | |
create_intermediate_folder_for_intellij_projects | |
echo "echo use \"${mount_point}/compileroutput\" for intelliJ project output directory." | |
echo "All good - I have done my job. Your apps should fly." | |
} | |
main "$@" | |
# ----------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment