extension: only insert date on current week

This commit is contained in:
Vincent Batts 2017-02-20 14:08:12 -05:00
parent 1a7945b5fe
commit 8c51dfaca1
2 changed files with 11 additions and 6 deletions

View File

@ -42,7 +42,7 @@ function activate(context) {
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
return;
}
openNote(basedir +"/"+ formatWeekFilename(currentWeek()));
openNote(basedir +"/"+ formatWeekFilename(currentWeek()), true);
}));
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenNextWeek', function () {
@ -68,13 +68,18 @@ exports.deactivate = deactivate;
* opens filepath in the current window, creating the file if needed
*
* @param {String} filepath is the path of the new note file
* @param {Boolean} insertDate whether to insert the date stamp on creation
* @return {undefined}
*/
function openNote(filepath) {
function openNote(filepath, insertDate) {
fs.access(filepath, fs.constants.R_OK | fs.constants.W_OK, (err) => {
if (err) {
try {
fs.writeFileSync(filepath, dateLine());
if (insertDate) {
fs.writeFileSync(filepath, dateLine());
} else {
fs.writeFileSync(filepath, "");
}
} catch (e) {
vscode.window.showErrorMessage("next-note: failed to create "+ filepath);
console.error(e);
@ -94,7 +99,7 @@ function openNote(filepath) {
* @returns {String}
*/
function getBasedir() {
var basedir = process.env["NOTEDIR"];
var basedir = process.env["NOTEDR"];
if (!basedir) {
basedir = process.env["HOME"]+"/Notes";

View File

@ -25,7 +25,7 @@
"commands": [
{
"command": "extension.nextNoteOpenPreviousWeek",
"title": "NextNote: Open Current Week"
"title": "NextNote: Open Previous Week"
},
{
"command": "extension.nextNoteOpenCurrentWeek",
@ -33,7 +33,7 @@
},
{
"command": "extension.nextNoteOpenNextWeek",
"title": "NextNote: Open Current Week"
"title": "NextNote: Open Next Week"
},
{
"command": "extension.nextNoteInsertDate",