Sunday, December 16, 2018

An NEdit Shortcut for Inserting the Date

You need to execute a unix command (depending of course on the format you want. This applies to 12/16/18 style date ) like

$ date +%m/%d/%y

das große problem : NEdit interprets the "%" :(

So you have to tell it to send unix something that date can then use. That is, the 

"%m/%d/%y" needs to magically appear before the date command is executed.

Enter command substitution and the answer :

$ date +`perl -e 'print "\045m/\045d/\045y";'`

You see how it arbeitet? First, the perl command is executed and the result is placed in the date command. The perl command uses octal codes to put the % in the print statement - so NEdit is clueless. 

So, what do YOU do? Do ALT-x, and enter this, and see that it works. Then, go into record macro mode and record this, and then do the Preferences > Default Settings > Customize Menus .. thing :)

Enjoy!

Now, what if you want something like "Dec 16 2018" :

date "+%b %d %Y"

Phew - how little I know :) If you use backticks for command substitution, this new one will give you grief. Turns out, the professional way to do command substitution is $( )

So, start with (in NEdit ALT-x execute command dialog ) :

date "+$(perl -e 'print "\045b \045d \045Y";')"

And all is well :) Thanks to the maestros :)

No comments: