Skip to content

Instantly share code, notes, and snippets.

@kunev
Created October 7, 2016 14:20
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 kunev/5de0e64bddabad20258924926078cd83 to your computer and use it in GitHub Desktop.
Save kunev/5de0e64bddabad20258924926078cd83 to your computer and use it in GitHub Desktop.
a script to handle editor://$FILE_NAME:$LINE_NUMBER URIs
#!/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