How to enable Gedit autosave files with name of current system Date and Time

I want Gedit to autosave files, by the default name with the current system Date and time. Is this possible?

If not, is any hack to achieve the same?

The use of this feature is, the file names are unique by default and easy to find them for later.

Thanks


Solution 1:

There is a plugin available that will do the job.

  • Download "doublesave.zip" from here.
  • Extract the contents and copy doublesave.plugin and doublesave.py to ~/.local/share/gedit/plugins. If the folder does not exist, you will need to create it.
  • Also create ~/gedit-backups because the backup files will be stored here.
    Open gedit and enable the Doublesave plugin: select Edit ▸ Preferences ▸ Plugins ▸ [Name of Plugin] to enable the plugin.

From now on, each time you save a file in gedit while working, a timestamped backup is created in ~/gedit-backups.


It is also possible to tweak some things. For example, I've recently installed Dropbox and wanted to have gedit-backups in my Dropbox folder rather than in ~/home/user. And I preferred my timestamp to be %Y%m%d%H%M%S rather than %Y_%m_%d-%H_%M_%S.

To make both those changes, edit ~/.local/share/gedit/plugins/doublesave.py.

  • create a folder called gedit-backups in the desired location
  • open gedit, and untick the Doublesave plugin
  • exit gedit
  • delete ~/.local/share/gedit/plugins/doublesave.pyc
  • edit ~/.local/share/gedit/plugins/doublesave.py

    • look for

      homedir = os.path.expanduser("~")+"/gedit-backups/"
      commands.getoutput("mkdir "+homedir)
      
      name = doc.get_short_name_for_display()
      
      timestamp = datetime.now().strftime("%Y_%m_%d-%H_%M_%S")
      
      ext = ".bak"
      newFileName =  name+"-" + timestamp + ext
      newpath = "\""+homedir + newFileName+"\""
      command = "cp \""+source+"\" "+ newpath
      print command
      commands.getoutput(command)
      commands.getoutput("chmod -w "+newpath)
      
  • change homedir = os.path.expanduser("~")+"/gedit-backups/" to what is required. I use homedir = os.path.expanduser("~")+"/Dropbox/gedit-backups/"
  • change the timestamp as needed. I changed "%Y_%m_%d-%H_%M_%S" to "%Y%m%d%H%M%S"
  • save the file
  • reopen gedit and reinstall the Doublesave plugin.