Skip to content

Instantly share code, notes, and snippets.

@GongT
Last active February 23, 2018 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GongT/60248ec8395200dddeeebf8ec6d41b03 to your computer and use it in GitHub Desktop.
Save GongT/60248ec8395200dddeeebf8ec6d41b03 to your computer and use it in GitHub Desktop.
Idea IDE commandline shortcut
#!/usr/bin/env bash
#################################
IDEA_PATH="/opt/PhpStorm/bin/phpstorm.sh"
#################################
set -e
BASENAME="$(basename "${IDEA_PATH}")"
ID=$(echo -n ${BASENAME} | md5sum | awk '{print $1}')
if screen -list | grep "${ID}" | grep -q '(Dead' &>/dev/null ; then
echo "shortcut: screen process died, wiping"
screen -wipe >/dev/null || true
fi
ARGV=()
push_arg() {
ARGV+=("$1")
}
for ARG in "$@" ; do
if [ "$ARG" = "." ] ; then
push_arg "$(pwd)"
elif [ "${ARG:0:1}" = "." ] && echo "$ARG" | grep -qE '^\.\.?/' ; then
push_arg "$(realpath -m "$ARG")"
else
push_arg "$ARG"
fi
done
echo "shortcut: cmdline: pstorm ${ARGV[@]}" >&2
if screen -list | grep "${ID}" &>/dev/null ; then
echo "shortcut: reuse exists instance in screen $ID." >&2
"${IDEA_PATH}" "${ARGV[@]}"
else
echo "shortcut: starting new instance in screen $ID." >&2
screen -dmS "$ID" "${IDEA_PATH}" "${ARGV[@]}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment