-
-
Save verticonaut/1200469 to your computer and use it in GitHub Desktop.
RubyMine CommandLine Launcher updated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import socket | |
import struct | |
import sys | |
import os | |
import os.path | |
import time | |
# see com.intelij.idea.SocketLock for the server side of this interface | |
RUN_PATH = '/Applications/RubyMine 3.2.4.app' | |
CONFIG_PATH = '/Users/martin_schweizer/Library/Preferences/RubyMine32' | |
args = [] | |
skip_next = False | |
for arg in sys.argv[1:]: | |
if arg == '-l' or arg == '--line': | |
args.append(arg) | |
skip_next = True | |
elif skip_next: | |
args.append(arg) | |
skip_next = False | |
else: | |
line_nr_index = arg.rfind(':') | |
if line_nr_index == -1: | |
args.append(os.path.abspath(arg)) | |
else: | |
file_name = arg[0:line_nr_index] | |
line_nr = arg[line_nr_index+1:] | |
args.append('-l') | |
args.append(line_nr) | |
args.append(os.path.abspath(file_name)) | |
def launch_with_port(port): | |
found = False | |
s = socket.socket() | |
s.settimeout(0.3) | |
try: | |
s.connect(('127.0.0.1', port)) | |
except: | |
return False | |
while True: | |
try: | |
path_len = struct.unpack(">h", s.recv(2))[0] | |
path = s.recv(path_len) | |
path = os.path.abspath(path) | |
if os.path.abspath(path) == os.path.abspath(CONFIG_PATH): | |
found = True | |
break | |
except: | |
break | |
if found: | |
if args: | |
cmd = "activate " + "\0".join(args) | |
encoded = struct.pack(">h", len(cmd)) + cmd | |
s.send(encoded) | |
time.sleep(0.5) # don't close socket immediately | |
return True | |
return False | |
port = -1 | |
try: | |
f = open(os.path.join(CONFIG_PATH, 'port')) | |
port = int(f.read()) | |
except Exception: | |
type, value, traceback = sys.exc_info() | |
print(value) | |
port = -1 | |
if port == -1: | |
# SocketLock actually allows up to 50 ports, but the checking takes too long | |
for port in range(6942, 6942+10): | |
if launch_with_port(port): exit() | |
else: | |
if launch_with_port(port): exit() | |
if sys.platform == "darwin": | |
# Mac OS: RUN_PATH is *.app path | |
if len(args): | |
args.insert(0, "--args") | |
os.execvp("open", ["-a", RUN_PATH] + args) | |
else: | |
# unix common | |
bin_dir, bin_file = os.path.split(RUN_PATH) | |
os.chdir(bin_dir) | |
os.execv(bin_file, [bin_file] + args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
* RubyMine command line lauchcher change so it opens files on line ....*
_Usage_
mine this/isYourFile:123
Opens file isYourFile on line 123.