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.
2 Answers
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

- 42,548
- 23
- 127
- 221
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!
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