Code Snippet download code as file / Code Management in Anytype

Is your feature request related to a problem? Please describe.
I would like to use anytype to manage my personal library of code scripts in lieu of an IDE/Text editor. To this end, I would like to have the source of the script inside of anytype, along side meta-data and other notes already in anytype before exporting it for external purposes.

However, with the way code-blocks and files work, you cannot manage the internals of a file within anytype. And you cannot export code blocks as files within anytype.

Describe the solution you’d like
[Solution One] Give “Code Snippet” blocks the ability to download the contained code as the file type.

Example:

  • I have a “Code Snippet” block filled with a Powershell Script written inside.
  • I access the “Block-Menu” by clicking the grab-handle menu on the left of the block.
  • In the menu there is an option, “download”
  • Clicking “download” opens the OS-managed “save file…” explorer, where it defaults to trying to save the file as a “page name-script.ps1”

Notice: The downloaded file type defaults to the code block’s current file type. Powershell script outputs a .ps1 file, C# code outputs a .cs file, not specifying outputs a .txt, ect.

[Solution Two] Give “Object View” the ability to display the internals of files that match the extensions of file-types, used for languages in “Code Snippets”.

Example:

  • I have a stored python script in anytype, stored as “script.py”.
  • I access the “Block-Menu” by clicking the grab-handle menu on the left of the block.
  • In the menu, I click “Open as Object”
  • The resulting Object Screen has a “Code Snippet” block, populated with the file contents on the left side. (Instead of pdf-viewer, or generic file icon block).
  • I can edit the contents of the file, and have anytype synchronize my changes into the stored file.

Notice: This solution is asking a bit much, hence why it’s the second solution, however, it would make anytype a degree more powerful (could be used for bare minimum IDE).

From a developer’s point of view: This might be accomplished by “reading” files fed into anytype, storing them as a regular text with the extension meta-information, then “Object View” under the hood is just modifying a text and displaying in a code-snippet. With a download, outputting the text content with the expected file extension. This could even be extended to a “run” (instead of open or download) which attempts to use the OS default program against the file.

This could be dangerous because when anytype starts “touching” the insides of the files you are closer to the risk of “running” unchecked code. You might come across malicious items which then need to be sanitized, or are not from this machine / user. (Sharing doesn’t exist yet, but when it does, I’m imagining someone shares you something malicious, intentionally or not.)

Describe alternatives you’ve considered
Currently if I want the source of truth to exist in anytype, there are two strategies I used.

  • Keep my script as a file. Store the file in anytype. If I need to make modifications: download the file, modify, save to drive, save into anytype, delete from drive, remove old object from anytype.
    This isn’t ergonomic because I have to manually replace the file with the previously existing one.

  • Keep my script as code-snippet. Use Anytype as Text IDE, modifications is easy, just change the text. To get a “file” from my script so I can use it, I have to open a text editor, copy & paste from anytype to my text editor, “save as…” my personally known filetype.
    This isn’t ergonomic because I have to open an additional program literally just to turn it into a file.

Other methods to get to this end were,

  • Trying to print a saved File Object in anytype doesn’t attempt to print the contents, it just creates a nice looking display of the name of the File. So I can’t just “print out” my saved scripts to accomplish this.

Additional context
Example of [Solution Two], where the Object View for a file matching a code-style from code-snippet displays as a Code Snippet so it can be edited. Notice the “Last Modified” field, which would be required for this feature, so users understand if things were changed.

3 Likes