diff options
author | 2022-05-09 16:47:48 +0100 | |
---|---|---|
committer | 2022-05-09 21:07:35 +0100 | |
commit | 7dd27c9ee5f2dcece8fe93c43fe8d0459d2af6e1 (patch) | |
tree | a4752e358c2ec6fae4bc3727e475d7d80432a94a | |
parent | 4100857bc39c8c5c353c4dd0c51355ccfd0ee281 (diff) | |
download | notes_cli-master.tar.gz notes_cli-master.tar.bz2 notes_cli-master.zip |
-rwxr-xr-x | notes_cli | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -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()) |