confirmCMD
macro which has been really useful for me. Now I had an idea: it's a bit tedious when working a file where I modify the command if I have to repeat those changes over and over again. Wouldn't it be nice if the last command that was confirmed would be saved and presented as a default next time I call confirmCMD?This version does that (well, almost):
Code: Select all
function confirmCMD($ctxt,$cmd) {
$configfile = resolvepath("%tmp%\" . $ctxt . "\" . gpc(,"base") . ".xy_cmd");
if (exists($configfile)) {
$content = readfile($configfile);
// put last item into $c, the others info $items
$c = gettoken($content,-1,<CRLF>);
msg "c=" . $c;
$items = formatlist($content . <CRLF> . $cmd,"d",<CRLF>);
} else {
$c = $cmd;
$items = "";
$content = "";
}
$c = input("Edit command","",$c,"s","cancel",,,$items);
end $c == "cancel";
$content = formatlist($content . $c . <CRLF>,"d",<CRLF>);
writefile($configfile,$content,,"utf8bom");
return $c;
}
$ctxt
defines a context, it's just a string variable describing what the command does. $cmd
is the command. (To save the last command executed, we create file in %tmp% (in a subdir named $ctxt
) which has the same base name as the current file.When I look at that file after
writefile
(at the end of the macro) was executed, it contains the literal text "<CRLF>" instead of carriage return & linefeed. Why is that happening???