Created
October 7, 2016 14:20
-
-
Save kunev/5de0e64bddabad20258924926078cd83 to your computer and use it in GitHub Desktop.
a script to handle editor://$FILE_NAME:$LINE_NUMBER URIs
This file contains hidden or 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
#!/bin/env python | |
import os | |
import subprocess | |
import sys | |
import re | |
uri = sys.argv[1] | |
print(uri) | |
file_path_with_position = re.sub(r'editor://|vim://', '', uri) | |
line_number = None | |
if ':' in file_path_with_position: | |
file_path, line_number = file_path_with_position.split(':') | |
else: | |
file_path = file_path_with_position | |
print(file_path) | |
editor_command = 'vim {}'.format(file_path) | |
if line_number: | |
editor_command = editor_command + ' +{}'.format(line_number) | |
arguments = ['/usr/bin/termite', '-e', editor_command] | |
print(arguments) | |
subprocess.run(arguments) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment