Last active
March 13, 2024 18:26
-
-
Save steinbring/1f24e13917d541aebbbad92795a73a78 to your computer and use it in GitHub Desktop.
A command-line task tracking app for grim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make sure to run "chmod +x taskling.js" before doing anything | |
// To add a task, use node taskling.js -add 'Your task here'. | |
// To remove a task, use node taskling.js -rm 'Task to remove'. | |
// To display all tasks, simply run node taskling.js. | |
const fs = require('fs'); | |
const path = require('path'); | |
const filePath = path.join(__dirname, 'taskling.txt'); | |
// Function to add a task | |
function addTask(task) { | |
fs.appendFileSync(filePath, `${task}\n`, 'utf8'); | |
console.log('Task added:', task); | |
} | |
// Function to remove a task | |
function removeTask(taskToRemove) { | |
const tasks = fs.readFileSync(filePath, 'utf8').split('\n'); | |
const filteredTasks = tasks.filter(task => !task.includes(taskToRemove)); | |
fs.writeFileSync(filePath, filteredTasks.join('\n'), 'utf8'); | |
console.log('Task removed:', taskToRemove); | |
} | |
// Function to display all tasks | |
function displayTasks() { | |
const tasks = fs.readFileSync(filePath, 'utf8'); | |
console.log('Tasks:\n', tasks); | |
} | |
const args = process.argv.slice(2); | |
switch (args[0]) { | |
case '-add': | |
if (args[1]) { | |
addTask(args[1]); | |
} else { | |
console.log('Please specify a task to add.'); | |
} | |
break; | |
case '-rm': | |
if (args[1]) { | |
removeTask(args[1]); | |
} else { | |
console.log('Please specify a task to remove.'); | |
} | |
break; | |
default: | |
displayTasks(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment