Skip to content

Instantly share code, notes, and snippets.

@smhmic
Last active August 29, 2015 14:16
Show Gist options
  • Save smhmic/6ca283af6a5284b1e642 to your computer and use it in GitHub Desktop.
Save smhmic/6ca283af6a5284b1e642 to your computer and use it in GitHub Desktop.
For Mac. Consolidates PhpStorm configuration and plugins into single folder (like on Linux and Windows). Also allows config/plugins to be synced via Dropbox or other cloud service.
#
# DESC:
# Will move ~/Library/Preferences/.WebIdeXX (config)
# and ~/Library/Application Support/.WebIdeXX (plugins)
# to ~/G/G/etc/.phpstormX
# /config
# /plugins
# and updates PhpStorm.app/Contents/bin/idea.properties to point to new location.
#
# REF:
# https://intellij-support.jetbrains.com/entries/23358108
#
# USAGE:
# . move_phpstorm_config_to_single_folder.sh PHPSTORM_VERSION_NUMBER [IS_EAP]
#
# IMPORTANT:
# This requires that full app is 1) in user Applications folder, and 2) is titled in format: "PhpStorm VERSION_NUMBER[ EAP].app"
#
function move_phpstorm_config_to_single_folder()
{
echo
ARG_PHPSTORM_VERSION_NUMBER="$1"
ARG_IS_EAP="$2"
if [[ -z "$ARG_PHPSTORM_VERSION_NUMBER" ]]; then
echo "Please pass PhpStorm version" && echo
return 1
fi
if [[ -n "$ARG_IS_EAP" ]]; then
ARG_PHPSTORM_VERSION="$ARG_PHPSTORM_VERSION_NUMBER EAP"
else
ARG_PHPSTORM_VERSION="$ARG_PHPSTORM_VERSION_NUMBER"
fi
PATH_PHPSTORM_APP="$HOME/Applications/PhpStorm $ARG_PHPSTORM_VERSION.app"
PATH_APP_PROPERTIES="$PATH_PHPSTORM_APP/Contents/bin/idea.properties"
PATH_SRC_CONFIG_DIR="$HOME/Library/Preferences/WebIde${ARG_PHPSTORM_VERSION_NUMBER}0"
PATH_SRC_PLUGINS_DIR="$HOME/Library/Application Support/WebIde${ARG_PHPSTORM_VERSION_NUMBER}0"
PATH_TARGET_DIR="$HOME/G/G/etc/.phpstorm${ARG_PHPSTORM_VERSION// /_}"
PATH_TARGET_CONFIG_DIR="$PATH_TARGET_DIR/config"
PATH_TARGET_PLUGINS_DIR="$PATH_TARGET_DIR/plugins"
#echo $PATH_TARGET_DIR; echo $PATH_SRC_CONFIG_DIR; echo $PATH_SRC_PLUGINS_DIR; return 0
#TODO: confirmation prompt
if [ ! -e "$PATH_PHPSTORM_APP" ]; then
echo "Cannot find app." && echo "Make sure app is writable at: $PATH_PHPSTORM_APP" && echo
return 1
elif [ ! -d "$PATH_PHPSTORM_APP" ]; then
echo "App cannot be a link." && echo "Make sure full app is writable at: $PATH_PHPSTORM_APP" && echo
return 1
fi
if [ -e "$PATH_TARGET_DIR" ]; then
#if [[ -d "$PATH_TARGET_DIR" ]]; then
#TODO if is empty, is okay to proceed
echo "Target path already exists: $PATH_TARGET_DIR" && echo
#return 1
else
#TODO check that app is not currently open
mkdir "$PATH_TARGET_DIR"
#mkdir "$PATH_TARGET_CONFIG_DIR"
#mkdir "$PATH_TARGET_PLUGINS_DIR"
if [ ! -d "$PATH_TARGET_DIR" ]; then
echo "Failed to create target path: $PATH_TARGET_DIR" && echo
return 1
fi
#TODO: bak for testing
cp -rpi "$PATH_SRC_CONFIG_DIR" "${PATH_SRC_CONFIG_DIR}.bak"
echo "Backed up config."
cp -rpi "$PATH_SRC_PLUGINS_DIR" "${PATH_SRC_PLUGINS_DIR}.bak"
echo "Backed up plugins."
echo "To restore:"
echo "mv '${PATH_SRC_CONFIG_DIR}.bak' '$PATH_SRC_CONFIG_DIR'"
echo "mv '${PATH_SRC_PLUGINS_DIR}.bak' '$PATH_SRC_PLUGINS_DIR'"
echo
# move config and plugins
mv "$PATH_SRC_CONFIG_DIR" "$PATH_TARGET_CONFIG_DIR"
mv "$PATH_SRC_PLUGINS_DIR" "$PATH_TARGET_PLUGINS_DIR"
#TODO check that move was successful
echo "Moved config and plugin folders."
echo "ls -lAh '$PATH_TARGET_DIR'/*"
ls -lAh "$PATH_TARGET_DIR"/*
echo
fi
# tell PHPstorm new paths to look in
# config: configuration (idea.config.path) - ~/Library/Preferences/.WebIde80
# config\plugins: plugins (idea.plugins.path) - ~/Library/Application\ Support/.WebIde80
# system: caches, local history, etc (idea.system.path)
# system\log: logs and thread dumps (idea.log.path)
cat >>"$PATH_APP_PROPERTIES" <<EOF
# BEGIN PHPSTORM CUSTOM CONFIG LOCATION
# Added by script ($0)
idea.config.path=$PATH_TARGET_CONFIG_DIR
idea.plugins.path=$PATH_TARGET_PLUGINS_DIR
# END PHPSTORM CUSTOM CONFIG LOCATION
EOF
echo "Wrote to '$PATH_APP_PROPERTIES'"
cat "$PATH_APP_PROPERTIES"
echo
echo "Complete."
echo
}
move_phpstorm_config_to_single_folder "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment