Last active
March 9, 2018 16:19
-
-
Save akatrevorjay/3fb5bc753edd42b2abd0accb4dde4cdc to your computer and use it in GitHub Desktop.
Revisions
-
akatrevorjay revised this gist
Mar 9, 2018 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,9 @@ #!/usr/bin/env python3 """ _____________ tabs-to-repos -- Quickly gnt all of the github repos that you have open in firefox tabs. Pipe the output to your shell to actually clone them, otherwise it just prints the commands and some comments ;) @trevorj 12/2017 https://gist.github.com/akatrevorjay/3fb5bc753edd42b2abd0accb4dde4cdc @@ -88,7 +90,6 @@ def main(re_url=RE_GITHUB_REPO): md = AttrDict(m.groupdict()) print('# %s' % tab.url) print('git clone https://github.com/%s/%s.git' % (md.user, md.repo)) -
akatrevorjay revised this gist
Mar 9, 2018 . No changes.There are no files selected for viewing
-
akatrevorjay revised this gist
Mar 9, 2018 . 1 changed file with 17 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """ _____________ tabs-to-repos -- Download all github repos that you have open in firefox tabs (quick hack) @trevorj 12/2017 https://gist.github.com/akatrevorjay/3fb5bc753edd42b2abd0accb4dde4cdc @@ -13,13 +13,13 @@ import re import sys import lz4.block # noqa: bug in firefox_tabs requires this, it only imports bare `lz4` import firefox_tabs log = logging.getLogger(__name__) # noqa FF_PROF_GLOB = '~/.mozilla/firefox*/*.*/' FF_PROF_SESS_REC_GLOB = '%s/sessionstore-backups/recovery.jsonlz4' % FF_PROF_GLOB RE_GITHUB_REPO = re.compile( r'(?P<scheme>https?)://(www\.|)github.com/(?P<user>[-_0-9a-zA-Z]+)/(?P<repo>[-_0-9a-zA-Z]+)/?$', @@ -37,13 +37,17 @@ def __init__(self, *args, **kwargs): self.__dict__ = self def _glob_me_prof(pat=FF_PROF_GLOB, sort_by=lambda x: -os.stat(x).st_mtime): pat = os.path.expanduser(pat) paths = glob.glob(pat) sorted_paths = sorted(paths, key=sort_by) if not sorted_paths: log.warn('Could not glob %r. What OS are you on?', glob) for p in sorted_paths: yield p def _load_firefox_data(path): @@ -67,7 +71,7 @@ def _iter_firefox_tabs(session_data, container_factory=AttrDict): def main(re_url=RE_GITHUB_REPO): path = next(_glob_me_prof(FF_PROF_SESS_REC_GLOB)) log.info('Loading from firefox session store backup: %r', path) session_data = _load_firefox_data(path) @@ -101,4 +105,4 @@ def main(re_url=RE_GITHUB_REPO): datefmt='%Y/%m/%d %H:%M:%S' ) main() -
akatrevorjay revised this gist
Dec 31, 2017 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,11 @@ #!/usr/bin/env python3 """ _____________ tabs-to-repos -- Download all github repos that you have open in firefox tabs (quick hack; verify and pipe to sh) @trevorj 12/2017 https://gist.github.com/akatrevorjay/3fb5bc753edd42b2abd0accb4dde4cdc """ import glob import logging -
akatrevorjay revised this gist
Dec 31, 2017 . 1 changed file with 27 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,23 @@ #!/usr/bin/env python3 import glob import logging import os import re import sys import lz4.block # bug in firefox_tabs requires this, it only imports bare `lz4` import firefox_tabs log = logging.getLogger(__name__) FF_SS_REC_GLOB = os.path.expanduser('~/.mozilla/firefox/*/sessionstore-backups/recovery.jsonlz4') RE_GITHUB_REPO = re.compile( r'(?P<scheme>https?)://(www\.|)github.com/(?P<user>[-_0-9a-zA-Z]+)/(?P<repo>[-_0-9a-zA-Z]+)/?$', re.IGNORECASE, ) class AttrDict(dict): @@ -53,10 +61,16 @@ def _iter_firefox_tabs(session_data, container_factory=AttrDict): def main(re_url=RE_GITHUB_REPO): path = _latest_file_in_glob(FF_SS_REC_GLOB) log.info('Loading from firefox session store backup: %r', path) session_data = _load_firefox_data(path) tabs = list(_iter_firefox_tabs(session_data)) log.info('Loaded session data: num_tabs=%d', len(tabs)) for tab in tabs: log.debug('Checking tab: url=%s', tab.url) m = re_url.match(tab.url) if not m: continue @@ -67,6 +81,17 @@ def main(re_url=RE_GITHUB_REPO): print('# %s' % tab.url) print('git clone https://github.com/%s/%s.git' % (md.user, md.repo)) # avoids gc overhead at exit. sys.exit(0) if __name__ == '__main__': logging.basicConfig( level=logging.DEBUG, # Match squid log output format='%(asctime)s| %(name)s/%(process)d: %(message)s ' '@%(funcName)s:%(lineno)d #%(levelname)s', datefmt='%Y/%m/%d %H:%M:%S' ) main() -
akatrevorjay revised this gist
Dec 31, 2017 . 1 changed file with 18 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,13 @@ #!/usr/bin/env python3 import glob import os import re import firefox_tabs import lz4.block # bug in firefox_tabs requires this, it only imports bare `lz4` FF_SS_REC_GLOB = os.path.expanduser('~/.mozilla/firefox/*/sessionstore-backups/recovery.jsonlz4') RE_GITHUB_REPO = re.compile(r'(?P<scheme>https?)://(www\.|)github.com/(?P<user>\w+)/(?P<repo>\w+)/?$', re.IGNORECASE) @@ -21,16 +22,22 @@ def __init__(self, *args, **kwargs): self.__dict__ = self def _latest_file_in_glob(glob_match): mtime = lambda p: os.stat(p).st_mtime paths = glob.glob(glob_match) sorted_paths = sorted(paths, key=mtime) if not sorted_paths: raise ValueError('Could not find Firefox session store backup. What OS are you on? Check the glob.') return sorted_paths[0] def _load_firefox_data(path): path = os.path.expanduser(path) session_data = firefox_tabs.load_data(path) return session_data def _iter_firefox_tabs(session_data, container_factory=AttrDict): for window_idx, window in enumerate(session_data['windows']): for tab in window['tabs']: current_tab = tab['entries'][-1] @@ -44,11 +51,13 @@ def _iter_firefox_tabs(session_data=_load_firefox_data, container_factory=AttrDi yield tab def main(re_url=RE_GITHUB_REPO): path = _latest_file_in_glob(FF_SS_REC_GLOB) session_data = _load_firefox_data(path) tabs = list(_iter_firefox_tabs(session_data)) for tab in tabs: m = re_url.match(tab.url) if not m: continue -
akatrevorjay created this gist
Dec 31, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ #!/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()