I need a time-stamp that is inserted with a hot key, like F5 in old notepad. Format should be:
hh:mm dd.mm.yyyy.
p.s. Dot in the end of the year is grammatically correct in Serbian language, so it is not a mistake.
Install the package xdotool
via, we need the command xdotool
sudo apt-get install xdotool
Create a small script
#!/bin/bash
sleep 0.1
xdotool type $(date +"%H:%M")' '$(date +"%d.%m.%Y.")
If the output does not looks something like
17:31 15.08.2015.
use
#!/bin/bash
sleep 0.1
xdotool type $(date +"%H")':'$(date +"%M")' '$(date +"%d")'.'$(date +"%m")'.'$(date +"%Y")'.'
If the time is not fully inserted after pressing the shortcut, increment the parameter for sleep
, eg 0.5
, in the script
Make it executable
chmod +x your_script
Assign a keyboard shortcut for the script, eg Super+F5 or some other shortcut that is not used.
.nanorc
18^01 15.08.2015.
xdotool type $(date +"%H")':'$(date +"%M")' '$(date +"%d")'.'$(date +"%m")'.'$(date +"%Y.")
please?
This answer was tested with Nano 6.4.
As far as I can tell, Nano doesn't ship with a keyboard shortcut that inserts a timestamp of the current time and date. However, Nano does offer features that allow you to configure some stuff so you can do this:
So, you can use a third-party command-line timestamp program, and make a keyboard shortcut that uses it.
Here is how to do this:
Open your Nanorc file with Nano (not another text editor, because you'll need to make use of Nano's verbatim input feature); you can do nano ~/.nanorc
to open the Nanorc file.
Type the following on its own line (which makes use of the idea that Pilot06 mentioned in the comments):
bind F5 "date +%I:%M\ %d.%m.%Y." main
Or if you want 24-hour time do this instead:
bind F5 "date +%H:%M\ %d.%m.%Y." main
Now, go between the "d
and press Alt+v; then press Ctrl+t.
Now, go between the ."
and press Alt+v and then press enter.
Then press Alt+v and press backspace, once.
Your line should look something like this (but it might look a little different, and don't copy/paste this, because it probably won't count the special characters as verbatim input):
bind F5 "^Tdate +%I:%M\ %d.%m.%Y.^M^?" main
Save and close Nano. You're done. It won't work in instances of Nano that are already open (you'll have to close those and restart them).
Now, whenever you press F5, it'll insert a timestamp according as you wanted.
To see directives for the command-line program called date
, type man date
, date --help
, or info date
(press q to get out of the manpage or the info page). Directives are the things like %H.
Here's an example of a fancy timestamp:
date +%-d\ %B\ %-Y\ \(%A\)—%-I:%M:%S\ %p
date +%H:%M\ %d.%m.%Y.
. You can set an alias for this command to enter it fast.