Skip to content

Instantly share code, notes, and snippets.

@muhqu
Last active August 29, 2015 14:08
Show Gist options
  • Save muhqu/57e0c0682918c23530a1 to your computer and use it in GitHub Desktop.
Save muhqu/57e0c0682918c23530a1 to your computer and use it in GitHub Desktop.
#!/bin/sh
main() {
TITLE="$(eclipseWindowTitle)"
if [[ -z "$TITLE" ]]; then
error "no title"
exit 1; # no title
fi
WORKSPACE="$(echo "$TITLE" | awk -F ' - ' '{print $(NF)}')"
if [[ -z "$WORKSPACE" || ! -d "$WORKSPACE" ]]; then
error "workspace not found"
exit 1;
fi
FILEPATH_WITH_PACKAGE="$(echo "$TITLE" | awk -F ' - ' '{print $(NF-2)}')"
FILEPATH_WITHIN_PACKAGE="${FILEPATH_WITH_PACKAGE#*/}"
PACKAGE_NAME="${FILEPATH_WITH_PACKAGE%%/*}"
if [[ -z "$PACKAGE_NAME" || -z "$FILEPATH_WITHIN_PACKAGE" ]]; then
error "unknown package-name or filepath within package"
exit 1;
fi
PACKAGE_PATH="$(find "$WORKSPACE" -type f -name .project \! -path '*/target/*' | xargs -n10 grep "<name>${PACKAGE_NAME}</name>" | awk 'BEGIN{FS="/.project:"}{print $1}' | head -1)"
if [[ -z "$PACKAGE_PATH" || ! -d "$PACKAGE_PATH" ]]; then
error "package-path not found"
exit 1;
fi
ABS_FILEPATH="$(find "$PACKAGE_PATH" -type f -path "*$FILEPATH_WITHIN_PACKAGE" \! -path '*/target/*' | head -1)"
if [[ -z "$ABS_FILEPATH" || ! -f "$ABS_FILEPATH" ]]; then
error "absolut file path not found"
exit 1; #
fi
echo "$ABS_FILEPATH"
echo "$PACKAGE_PATH"
echo "$FILEPATH_WITHIN_PACKAGE"
}
eclipseWindowTitle() {
osascript -s ho - <<-APPLESCRIPT
global windowTitle
set windowTitle to ""
tell application "System Events"
tell process "Eclipse"
tell (1st window whose value of attribute "AXMain" is true)
set windowTitle to value of attribute "AXTitle"
end tell
end tell
end tell
return {windowTitle}
APPLESCRIPT
}
error() {
echo >&2 "Error: " "$@"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment