aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xnotes_cli17
1 files changed, 9 insertions, 8 deletions
diff --git a/notes_cli b/notes_cli
index 5db00cb..280122a 100755
--- a/notes_cli
+++ b/notes_cli
@@ -4,11 +4,12 @@ const { homedir } = require('os')
const https = require('https')
const readline = require("readline")
+const DATA_DIR = `${homedir}/.local/share/notes_cli`
+
let conf, notesList = [], active = 0; scroll = 0;
let draw = { t: 'p', v: () => ['Loading NOTES CLI...'] }; menu = 'Press [h] for help'; sort = 3
const cl = (m, c) => console.log(c ? `\x1b[${c}m${m}\x1b[0m` : m)
const cls = () => console.clear()
-const filesPath = `${homedir}/.local/share/notes_cli`
const fixedStr = (s, l) => s.length < l ? s.padEnd(l) : s.substring(0, l)
const formatDate = d => d.replace('T',' ').replace(/\..*Z/, '')
@@ -98,7 +99,7 @@ const getNewNoteTitle = (existing = false) => {
}
const saveTmpFile = (note, { content }) => {
- const file = `${filesPath}/${note._id}.tmp`
+ const file = `${DATA_DIR}/${note._id}.tmp`
fs.writeFile(file, content, function(err) {
if(err) { exitWithError(['Error creating tmp file']) }
return editTmpFile(note)
@@ -106,7 +107,7 @@ const saveTmpFile = (note, { content }) => {
}
const readTmpFile = (note, title) => {
- const file = `${filesPath}/${title ? 'new' : note._id}.tmp`
+ const file = `${DATA_DIR}/${title ? 'new' : note._id}.tmp`
fs.readFile(file, function(err, f){
if (err) { return getEmail() }
try {
@@ -131,7 +132,7 @@ const noteRemoved = (list) => {
}
const createTmpFile = (title) => {
- const file = `${filesPath}/new.tmp`
+ const file = `${DATA_DIR}/new.tmp`
const child_process = require('child_process')
const editor = process.env.EDITOR || 'vi';
cursor.show()
@@ -149,7 +150,7 @@ const createTmpFile = (title) => {
}
const editTmpFile = (note) => {
- const file = `${filesPath}/${note._id}.tmp`
+ const file = `${DATA_DIR}/${note._id}.tmp`
const child_process = require('child_process')
const editor = process.env.EDITOR || 'vi';
cursor.show()
@@ -258,15 +259,15 @@ const getKey = () => {
}
const setSession = (session) => {
- if (!fs.existsSync(filesPath)) fs.mkdirSync(filesPath, { recursive: true });
- fs.writeFile(`${filesPath}/session`, JSON.stringify(session), function(err) {
+ if (!fs.existsSync(DATA_DIR)) fs.mkdirSync(DATA_DIR, { recursive: true });
+ fs.writeFile(`${DATA_DIR}/session`, JSON.stringify(session), function(err) {
if (err) { exitWithError(['Error writting session file']) }
getSession()
})
}
const getSession = () => {
- fs.readFile(`${filesPath}/session`, function(err, f){
+ fs.readFile(`${DATA_DIR}/session`, function(err, f){
if (err) return getEmail()
try {
conf = JSON.parse(f.toString())