2

Does the gedit editor have a code to automatically embed the current date when I save a file? I don't always remember to edit my "last updated" comment in the file.

  • I am aware of https://help.gnome.org/users/gedit/stable/gedit-plugins-insert-date-time.html.en edit/insert date and time, but that inserts a text string. I need a "code" to be inserted which will be interpreted at the time the file is saved. –  Aug 23 '19 at 23:29
  • Please edit your question with the new information / explanations. gedi is a text editor, what kind of "code" are you trying to edit? The inserted "code" would depend on the language the "code" is written in. Gedit cannot edit binary code. – user68186 Aug 24 '19 at 00:07
  • I was looking for something like WordPerfect had which would enter today's date and time at the point in the document where you indicated it should appear. Each time you save the file, it updates the date/time in the document itself. –  Apr 27 '20 at 22:07

2 Answers2

2

Does the gedit editor have a code to automatically embed the current date when I save a file?

I have gedit 3.28.1 and am not aware of such a code.

The following script inserts a timestamp into your file as the last line at the time you save the file with plain text editors such as gedit or geany and for LibreOffice Writer on x11. I don't use Wayland.

You'll need to install xdotool and xsel.

#!/bin/bash

sleep 0.1 && xdotool key ctrl+End Return;

sleep 0.1 && date '+%Y-%m-%d %H:%M:%S' | tr -d "\n" | xsel -i -b;

sleep 0.1 && xdotool key "ctrl+v";

sleep 0.1 && xdotool key "Alt+F4";

exit

I saved the script as add-timestamp.sh in ~/bin, made it executable, and assigned Shift+Super+S as its keyboard shortcut.

My laptop is a bit aged; maybe the various sleep entries aren't needed on a faster machine.

Credit to http://www.arcadien.net/node/48

animation to illustrate adding timestamp

DK Bose
  • 42,548
  • 23
  • 127
  • 221
0

I didn't find a way to do it in gedit, but I found a way to do it with PHP. Since I wanted the functionality for my web page files anyway, the PHP option works for me. To make my individual pages display the date/time that they were last edited, I add this line of code to the page's source:

Last modified: " . date ("F d Y H:i:s.", getlastmod()) . ""; ?>

Works for me. Also, CK Bose' answer looks like a good solution. Thanks, DK Bose!