Skip to content

Instantly share code, notes, and snippets.

@dobe
Last active December 11, 2018 21:39
Show Gist options
  • Save dobe/12c6a989f481d9e9769cefb0fea8271c to your computer and use it in GitHub Desktop.
Save dobe/12c6a989f481d9e9769cefb0fea8271c to your computer and use it in GitHub Desktop.
intellij wrapper around the idea cli script which searches for the project in parent dirs
#!/usr/bin/env bash
set -e
target=${1:-"$PWD"}
target=$(realpath "$target")
if [ -d "$target" ]
then
cd "$target"
else
if [ -f "$target" ]
then
cd $(dirname "$target")
target_file=$target
else
echo "$target" is not a file or a directory && exit 1
fi
fi
while [ ! -d .idea ]
do
cd ..
if [ $(pwd) = "/" ]
then
if [ -n "$target_file" ]
then
# start idea with file argument only and let if find the open project if one exists
idea "$target_file"
exit 0
else
echo "no project found" && exit 1
fi
fi
done
idea "$PWD" "$target_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment