Last active
October 11, 2019 22:54
-
-
Save dhilst/22eaf6089cc35fb8d43b4a49b680a5a4 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import sys | |
import re | |
def jobs_line(string): | |
return re.match( | |
r"^\[(?P<id>\d+)\]\s+(?P<default>\+|-)?\s+(?P<state>.*?)\s+(?P<rest>.*)", string | |
).groupdict() | |
# I may need something more sophisticated in future | |
def is_vim(rest): | |
return "vim" in rest | |
if __name__ == "__main__": | |
if sys.stdin.isatty(): | |
sys.stderr.write("Usage: jobs | {}".format(sys.argv[0])) | |
sys.exit(-1) | |
data = sys.stdin.read().strip().split("\n") | |
data = map(jobs_line, data) | |
for d in data: | |
if is_vim(d["rest"]): | |
print("fg %{id}".format_map(d)) | |
sys.exit(0) | |
else: | |
print("/usr/bin/env vim") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment