Skip to content

Instantly share code, notes, and snippets.

@mathieutu
Created February 6, 2018 09:12
Show Gist options
  • Save mathieutu/5951cf965521f98c701d7cb98cf161b8 to your computer and use it in GitHub Desktop.
Save mathieutu/5951cf965521f98c701d7cb98cf161b8 to your computer and use it in GitHub Desktop.
Iterm workflow form phpstorm one.
import sys
import glob
import json
from workflow import Workflow, ICON_WEB, web
def getProjectDirectories():
with open('config.json') as data_file:
data = json.load(data_file)
projects = {}
for dir in data['ProjectDirectories']:
for project in glob.iglob(dir + '/*/*/.idea/'):
project = project[:-7]
folderList = project.split('/')
projectName = folderList[-2] + '/' + folderList[-1]
projects[projectName] = project
for project in glob.iglob(dir + '/*/'):
project = project[:-1]
folderList = project.split('/')
projectName = folderList[-1]
projects[projectName] = project
return projects
def urlSearch(project):
return project
def main(wf):
allProjects = wf.cached_data('allProjects', getProjectDirectories, max_age= -1)
""" Filter the projects """
if len(wf.args):
projects = wf.filter(wf.args[0], allProjects, key=urlSearch)
else:
projects = allProjects
for project in projects:
wf.add_item(title=project,
subtitle=allProjects[project],
icon="icon.png",
arg=allProjects[project],
valid=True)
wf.send_feedback()
if __name__ == u"__main__":
wf = Workflow()
sys.exit(wf.run(main))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment