Announcement

Collapse
No announcement yet.

Is saving backups in Kate with time-stamp possible?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Is saving backups in Kate with time-stamp possible?

    Kate Version 18.12.1 in KDE Neon 5.14.5

    For example, if I have /home/chimak/Desktop/text.txt and I edit and save it, I would like to have the backup file stored in ~/Public/Backups with a suffix like -20180122190631 (year, month, date, hour in 24h format, minutes, and seconds).

    In Settings > Configure Kate > Open/Save>Advanced,

    I have /home/chimak/Public/Backups/ in the Prefix box

    But if I put -$(date +%Y%m%d%H%M%S) or even "-$(date +%Y%m%d%H%M%S)" in the Suffix box, both appear literally and are not converted to a time-stamp.

    So after editing /home/chimak/Desktop/text.txt, ~/Public/Backups/ has test.txt-$(date +%Y%m%d%H%M%S) or test.txt-"$(date +%Y%m%d%H%M%S)" whereas what I want is test.txt-20180122190631.

    The idea is to have time-stamped backups of files I edit with Kate in case I mess up and need to go back.

    ##############
    If I use the default ~ as suffix, the incoming test.txt~ replaces the previous test.txt~.

    ##############
    Also asked here: https://www.reddit.com/r/kde/comment..._backups_with/
    Last edited by chimak111; Jan 23, 2019, 05:47 AM.
    Kubuntu 20.04

    #2
    Geany has a "Save As" plugin, which if active, allows the user a choice of suffixes via the Plugin Preferences GUI:
    Attached Files
    Kubuntu 20.04

    Comment


      #3
      I do this with vim, it's a very good idea.

      But googling kate scripting and plugins has found no hint of an events framework, or triggers, or the like. Of course, maybe I just don't know the right search term...

      However, there's other approaches. A background script using inotifywait could do the job (minimally tested):
      Code:
      #!/bin/bash
      dir_to_watch=whatever
      
      inotifywait -r -m --exclude '[^~]$' -e create,close --format '%w%f'  $dir_to_watch |
       while read line
       do
           newname=${line%\~}$(printf "%(%F-%T)T.bk")
           mv $line $newname
       done
      Another good idea is to check the file in to a private branch of your VCS of choice on every save; I keep meaning to set that up...
      Regards, John Little

      Comment


        #4
        @jlittle, Thanks for looking into this!

        The inotify route would be, I'm guessing, an always-on feature whereas with Geany (or Kate, if there's a solution) would be as and when needed. Further, I would need to specify a whole lot of directories to watch because of dir_to_watch=whatever.

        I've not ever wrapped my head around VCS

        As for my other needs, like LibreOffice documents and spreadsheets, they're in my Dropbox folder and so I can get at older versions that way.

        For now, it seems that Geany has what I need but let's hope that someone comes up with something for Kate.
        Kubuntu 20.04

        Comment


          #5
          Well, it isn't available at this time: https://www.reddit.com/r/kde/comment...s_with/eerg3m5
          Kubuntu 20.04

          Comment

          Working...
          X