Closed pykong closed 6 years ago
@pykong That is a great point and a snippets:import
feature is slated for the next release.
In the meantime, you can do the following:
cacher snippets:add [path_to_file] -t=[title] -d=[description] -q
@jookyboi Thanks for your suggestion. I will try that out. Keep on the good work with cacher! IMHO by far the best snippet manager I have found.
Here is such quick and dirty script written in python, in case anyone in use comes across it.
How to use:
1.) Install and Setup Cacher-Cli as explained.
2.) Save below snippet to gist_imp.py
3.) Run like: python3 gist_imp.py path/to/my/gist_box_export_file.json
4.) Enjoy, see the magic happen...
Limitations:
import json
import os
import subprocess
import sys
from tempfile import TemporaryDirectory
with open(sys.argv[1], "r") as f:
js = json.load(f)
groups = js["groups"]
with TemporaryDirectory() as dirpath:
for group in groups:
gists = group["gists"]
for g in gists:
description = g["description"]
files = g["files"]
for f in files:
content = f["content"]
filename = f["filename"]
title = description[:20]
with open(filename, "w") as target:
target.write(content)
cmd = (f"cacher snippets:add {filename}"
f" -d '{description}' -t '{title}'")
print(cmd)
subprocess.run(cmd, shell=True, cwd=dirpath)
I would really like to import the batch of snippets from the
json
file I have exported from GistBox. If there were any API documentation I could do it myself via a self-written script probably. Yet, as there is now this CLI tool forcacher.io
in the making, maybe it could implement such import feature.