Skip to content

Instantly share code, notes, and snippets.

@steinbring
Last active March 13, 2024 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steinbring/1f24e13917d541aebbbad92795a73a78 to your computer and use it in GitHub Desktop.
Save steinbring/1f24e13917d541aebbbad92795a73a78 to your computer and use it in GitHub Desktop.
A command-line task tracking app for grim
// 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