Skip to content

Commit

Permalink
Save note file in home directory instead of workspace folder
Browse files Browse the repository at this point in the history
  • Loading branch information
inaki-ibarra committed Sep 13, 2019
1 parent 4089ce4 commit 1b56f32
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## [Unreleased]

## [1.0.3] - 2019-09-12
## [1.0.4] - 2019-09-13
### Changed
- Save in home directory instead of workspace folder when filepath is not defined

## [1.0.3] - 2019-09-13
### Added
- Error when there's no folder in workspace and missing filepath

Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ If the Daily Notes file is already open:
* Press ```Ctrl+W``` to close the file
* Press ```Ctrl+S``` to save the file

If you don't want to save Daily Notes file in current workspace:
You may save your note file anywhere:

* Create a new file ```daily-notes.md```, copy the path and set the ```dailyNotes.filePath``` in config
* Create a new file ```daily-notes.md```, copy the path and set the ```dailyNotes.filePath``` in config.

## Extension Settings

Expand All @@ -37,7 +37,6 @@ This extension contributes the following settings:

## Known Issues

* You may get an error 'extension.open failed' when there's no open folder in your workspace. You can fix this by setting ```dailyNotes.filePath``` in config or opening a folder first, then ```Alt+N```.
* If you are using remote Windows Subsystem for Linux a.k.a WSL for VSCode, the file path format from Windows may not work.
This can be solved easily by using the file path from WSL e.g. ```/mnt/c/projects```.

Expand Down
12 changes: 3 additions & 9 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const vscode = require('vscode');
const fs = require('fs');
const firstline = require('firstline');
const homedir = require('os').homedir();

/**
* @param {vscode.ExtensionContext} context
Expand All @@ -10,31 +11,24 @@ function activate(context) {
let disposable = vscode.commands.registerCommand('extension.open', function () {
const filePath = getFilePath();

if (!filePath) {
return vscode.window.showErrorMessage("Open a folder in your workspace first or set DailyNotes.FilePath in Config");
}

if (fs.existsSync(filePath)) {
prependDateHeader(filePath);
} else {
createNewNote(filePath);
}

vscode.workspace.openTextDocument(filePath).then(doc => {
vscode.window.showTextDocument(doc, { preview: true });
vscode.window.showTextDocument(doc);
});
});

function getFilePath() {
const configFilePath = vscode.workspace.getConfiguration().get('dailyNotes.filePath');
const workspaceFolders = vscode.workspace.workspaceFolders;

if (configFilePath) {
return configFilePath;
} else if (workspaceFolders && workspaceFolders.length > 0) {
return workspaceFolders[0].uri.fsPath + "/daily-notes.md";
} else {
return null;
return homedir + "/daily-notes.md";
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-daily-notes",
"displayName": "VSCode Daily Notes",
"description": "A simple text-based journal extension for Visual Studio Code",
"version": "1.0.3",
"version": "1.0.4",
"icon": "images/icon.png",
"engines": {
"vscode": "^1.38.0"
Expand Down

0 comments on commit 1b56f32

Please sign in to comment.