Skip to content

Instantly share code, notes, and snippets.

@akatrevorjay
Last active March 9, 2018 16:19
Show Gist options
  • Select an option

  • Save akatrevorjay/3fb5bc753edd42b2abd0accb4dde4cdc to your computer and use it in GitHub Desktop.

Select an option

Save akatrevorjay/3fb5bc753edd42b2abd0accb4dde4cdc to your computer and use it in GitHub Desktop.
Download all github repos that you have open in firefox tabs
#!/usr/bin/env python3
import os
import re
import firefox_tabs
import lz4.block # bug in firefox_tabs requires this, it only imports bare `lz4`
FF_SS_REC_PATH = os.path.expanduser('~/.mozilla/firefox/qfs7tr6x.def/sessionstore-backups/recovery.jsonlz4')
RE_GITHUB_REPO = re.compile(r'(?P<scheme>https?)://(www\.|)github.com/(?P<user>\w+)/(?P<repo>\w+)/?$', re.IGNORECASE)
class AttrDict(dict):
"""
>>> m = AttrDict(omg=True, whoa='yes')
"""
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self
def _load_firefox_data(path=FF_SS_REC_PATH):
path = os.path.expanduser(path)
session_data = firefox_tabs.load_data(path)
return session_data
def _iter_firefox_tabs(session_data=_load_firefox_data, container_factory=AttrDict):
if callable(session_data):
session_data = session_data()
for window_idx, window in enumerate(session_data['windows']):
for tab in window['tabs']:
current_tab = tab['entries'][-1]
tab = container_factory(
url=current_tab['url'],
title=current_tab['title'],
window=window_idx,
)
yield tab
def main():
tabs = list(_iter_firefox_tabs())
for tab in tabs:
m = RE_GITHUB_REPO.match(tab.url)
if not m:
continue
md = AttrDict(m.groupdict())
# so hacky
print('# %s' % tab.url)
print('git clone https://github.com/%s/%s.git' % (md.user, md.repo))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment