from Save Entire Command History by Jonathan Snell
Maintains a complete record of the command history (Matlab only maintains the last 20k worth ...

finish.m
setpref('StartupDirectory','LastWorkingDirectory',pwd)
preserve_history;

Contact us at files@mathworks.com