ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Anonymous​File

by nchauhan890 ST3

Sublime Text 3 plugin to quickly create already-saved files to test code snippets.

Details

Installs

  • Total 153
  • Win 116
  • OS X 23
  • Linux 14
Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5 Sep 4 Sep 3 Sep 2 Sep 1 Aug 31 Aug 30 Aug 29 Aug 28 Aug 27 Aug 26 Aug 25 Aug 24 Aug 23 Aug 22 Aug 21 Aug 20 Aug 19 Aug 18 Aug 17 Aug 16 Aug 15 Aug 14 Aug 13 Aug 12 Aug 11 Aug 10 Aug 9 Aug 8 Aug 7 Aug 6 Aug 5 Aug 4 Aug 3 Aug 2
Windows 0 0 0 1 0 2 0 1 2 1 0 0 0 3 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 2 1 1 1 0
OS X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

Anonymous File

Sublime Text 3 plugin to quickly create already-saved files to test code snippets.

Intro

Have you ever thought of a brilliant idea and wanted to test out your code as fast as possible? You'd go through making a new file, writing the code out, saving the file somewhere, running it and then deleting it if the code failed. Now, with Anonymous File, you can quicken this workflow by creating pre-saved files which delete themselves upon closure.

Configuration

Edit the AnonymousFile.sublime-settings files to configure this plugin. Open through Preferences --> Package Settings --> AnonymousFile --> Settings - User or the command palette.

Setting Description
dir Directory to save new files
recently_closed Directory to move recently closed files to
keep Number of recently closed files to keep - must be between 0 and 100
file_extension Extension to create new files with - must contain the dot “.” (e.g. “.py”)

If the plugin detects any errors in the settings, such as numbers out of boundaries or file system locations which aren't directories or do not exist, a message will be shown in the status bar and in the console.

Commands

Anonymous File has 2 commands and 1 to edit settings available through the command palette. The table below shows the internal command names.

Command Command name
Create Anonymous File anonymous_file
Save Anonymous File save_anonymous_file

Context Menu

Anonymous File provides access to the Create Anonymous File and Save Anonymous File commands by default with their respective names unchanged.

Usage and internals

To create a new Anonymous File, right-click the current view to open the Context Menu and click Create Anonymous File, or alternatively click the same command through the Command Palette. This file is saved in the directory set as dir in the AnonymousFile.sublime-settings file and has the extension designated by the file_extension setting also in the settings file mentioned. It will have a base name of the form af_xyz where xyz are randomly assigned letters or digits. The file can be used as normal and any code written can be run without having to save the file beforehand.

Upon closure, the file is automatically deleted and moved to the directory set as recently_closed in the settings file. The keep setting specifies how many files will be kept in this directory; if the number is 0, the directory will remain empty. However, due to the nature of the code, the file is moved to the directory before being deleted so the recently_closed directory must be given regardless.

When an Anonymous File is closed, it's file name is written to recent_files.txt which is located in the directory specified as dir in settings. The order of the file names are oldest to newest. The plugin writes this data to a file so that when the whole Sublime Text application is closed, the file names are kept in order to ensure the oldest file(s) is/are removed from the recently closed folder even when Sublime Text is re-opened. However, if the file is deleted before Sublime Text opens, any file names that were recorded are lost which will mean that they are not removed from the recently_closed directory, causing there to be more files than is specified by the keep setting.

Alternatively, the Save Anonymous File command can be invoked through the Context Menu or Command Palette which opens a Save As prompt to save the file. After saving, the file is removed from the plugin's list of currently open Anonymous Files so when closed, the file isn't deleted. Even if you save the file with the same af_xyz name in the same directory, it still counts as saving the file and thus will not be deleted upon closure.