Skip to content

Instantly share code, notes, and snippets.

@jGleitz
Last active February 7, 2016 13:02
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 jGleitz/cfe503728b3a0bc1f00c to your computer and use it in GitHub Desktop.
Save jGleitz/cfe503728b3a0bc1f00c to your computer and use it in GitHub Desktop.
[Shell script] URL Handler for opening Eclipse
#!/bin/bash
###################################################################
# CONFIGURATION #
# #
# Please adapt the lines below to match your Eclipse installation #
###################################################################
# Path to the eclipse executable to launch
ECLIPSE="/opt/eclipse/eclipse"
# A String in Eclipse’s window title that will identify it
ECLIPSE_WINDOW_NAME='Eclipse'
# The title of Eclipse’s 'Go To Line' window
GO_TO_LINE_TITLE='Go To Line'
##########
# SCRIPT #
##########
URL_PATTERN="^openineclipse://open\\?url=file://([^&]+)&line=([0-9]+)$"
url="$1"
if ! [[ "$url" =~ $URL_PATTERN ]]; then
echo 'not recognised'
exit 1
fi
echo "recoginsed"
filepath="${BASH_REMATCH[1]}"
filename=$(basename "$filepath")
linenumber=${BASH_REMATCH[2]}
# Launch Eclipse and open the file
eval "\"$ECLIPSE\" --launcher.openFile \"$filepath\" &>/dev/null & "
# Find the Eclipse window (while waiting for it to appear)
xdotool search --sync --onlyvisible --name ".*$filename.*$ECLIPSE_WINDOW_NAME.*" windowfocus --sync
sleep 0.5s
# Press ctrl+l and enter the line number
xdotool key --clearmodifiers ctrl+l type --clearmodifiers $linenumber
# Find the 'Go To Line' window, ativate it, type the line and hit enter
xdotool search --sync --onlyvisible --name "$GO_TO_LINE_TITLE" windowfocus --sync key --clearmodifiers Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment