Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

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.
share|improve this answer
1  
Thanks, appreciated. Kudos. –  pajju Jun 15 '13 at 17:41
    
@pajju, I edited the answer with a little more stuff. –  user25656 Jul 18 '13 at 10:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.