5

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.

1
  • I think it is not possible without patching the source code. But you can get this stamp in terminal by date +%H:%M\ %d.%m.%Y.. You can set an alias for this command to enter it fast.
    – Pilot6
    Aug 15, 2015 at 14:31

2 Answers 2

2
  1. Install the package xdotool via, we need the command xdotool

    sudo apt-get install xdotool
    
  2. 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

  3. Make it executable

    chmod +x your_script
    
  4. Assign a keyboard shortcut for the script, eg Super+F5 or some other shortcut that is not used.

    enter image description here

10
  • Did you test it in nano? It has another binding for F5. But it can be undone in .nanorc
    – Pilot6
    Aug 15, 2015 at 14:48
  • @Pilot6 No :) only in gedit and in a terminal … But Super+F5 should work.
    – A.B.
    Aug 15, 2015 at 14:58
  • Super+F5 will open an app from launcher. F5 works but shows 18^01 15.08.2015.
    – Pilot6
    Aug 15, 2015 at 15:00
  • @Pilot6 18^01? why the ^? o_O
    – A.B.
    Aug 15, 2015 at 15:05
  • @Pilot6 Can you test it with xdotool type $(date +"%H")':'$(date +"%M")' '$(date +"%d")'.'$(date +"%m")'.'$(date +"%Y.") please?
    – A.B.
    Aug 15, 2015 at 15:30
0

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:

  1. You can execute external programs, and print the output into Nano.
  2. You can make custom keyboard shortcuts, including ones that can execute external commands, using macro-like actions along with it. You do not actually need to use Nano's standard macro feature, however.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .