Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Save eXide editor tabs to disk
xquery version "3.1";
(:
# Save eXide editor tabs to disk
1. Install "LocalStorage Manager" Chrome extension
https://chrome.google.com/webstore/detail/localstorage-manager/fkhoimdhngkiicbjobkinobjkoefhkap
2. Open eXide. Reload to force eXide to write all editor tabs to local storage.
3. Click on "LocalStorage Manager" extension icon in Chrome toolbar
4. Select "Download". This saves a file like localhost_8080-2019-12-31_15-55-06.txt to your Downloads folder.
5. Paste the file's full path into the $local:eXide-storage-file variable (preserving the "file:/" protocol)
6. Update the $local:destination-directory variable with your desired destination
7. Run the query in eXide. All tabs will be stored to the destination directory, stripping off the "/db" prefix. New files will be stored in the "new" directory with a basename "untitled-", followed by a number taken from the tab name, followed by an extension based on the mimetype.
:)
declare variable $local:eXide-storage-file {
"file:/Users/joe/Downloads/localhost_8080-2019-12-31_15-55-06.txt"
};
declare variable $local:destination-directory {
"/Users/joe/Downloads"
};
declare variable $local:eXide-storage {
json-doc($local:eXide-storage-file)
};
let $tabs :=
for $key-g in map:keys($local:eXide-storage)
group by $tab-key := $key-g => replace("^(eXide\.\d+).+$", "$1")
where matches($tab-key, "^eXide\.\d+$")
order by substring-after($tab-key, ".") => xs:integer()
(: name, data, mime, last-line, writable, path :)
return
map:merge((
map:entry("tab", $tab-key),
for $key in $key-g
let $label := substring-after($key, $tab-key || ".")
return
map:entry($label, $local:eXide-storage($key))
))
let $destination :=
$local:destination-directory
|| "/eXide-export-"
|| $local:eXide-storage-file
=> substring-after("localhost_8080-")
=> substring-before(".txt")
for $tab in $tabs
let $extension :=
switch ($tab?mime)
case "application/xquery" return ".xq"
case "application/xml" return ".xml"
default return ".txt"
let $is-new := starts-with($tab?path, "__new__")
let $path :=
if ($is-new) then
"new/"
else
$tab?path => replace("^/db/", "") => substring-before($tab?name)
let $filename :=
if ($is-new) then
replace($tab?path, "__new__", "untitled-") || $extension
else
$tab?name
where $tab?data ne ""
return
(
file:mkdirs($destination || "/" || $path),
file:serialize-binary($tab?data => util:string-to-binary(), $destination || "/" || $path || "/" || $filename)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.