From 234e3d6efc78ff7e83a80345ef23090c6a16adfd Mon Sep 17 00:00:00 2001 From: Kacper Marzecki Date: Thu, 20 Mar 2025 21:31:08 +0100 Subject: [PATCH] better docs, configure editor by an env var --- readme.md | 59 +++++++++++++++++++++++++++++++++---------------- source/app.js | 17 +++++++++----- source/tasks.js | 1 + 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/readme.md b/readme.md index 8d1b576..05879aa 100644 --- a/readme.md +++ b/readme.md @@ -1,38 +1,61 @@ # td -> This readme is automatically generated by [create-ink-app](https://github.com/vadimdemedes/create-ink-app) - -## Install - +## Install (this was generated by Ink starter, dunno if that works) ```bash $ npm install --global td ``` + +# Dependencies +fzf https://github.com/junegunn/fzf + for searching & selectors +tmux + for displaying an editor in a side pane + IMPORTANT: this must be run inside tmux + Ive got a comfy tmux config I can share later if U'd want it :) + +# ENV vars +TD_EDITOR + Editor for ask editing, CLI only (recommend neovim (again Ive got a comfy config I can share later if U'd want it :))) +TD_TASK_DIR + Directory for storing tasks.json and logs. Assumed to be a git repo + +set them before running `td` + +```bash +$ tmux +$ export TD_EDITOR=nvim +$ export TD_TASK_DIR=/home/omnissiah/git/tasks/ +$ npm run buid +$ node dist/cli.js +``` +or in Your .bashrc + # Manual +P.S. A more complete summary of keybinds can be displayed on `?` keybind 1. **Task Management**: - Create, edit, delete tasks. - View lists in a ranger-like UI https://github.com/ranger/ranger - Tasks can have subtasks. - 2. **Navigation**: - - Vim-like keybindings for navigation: - - `hjkl` to navigate in and between subtask lists. - - `HJKL` to move a task in and between subtask lists. - - `g` to go to the top of the list. - - `G` to go to the bottom of the list. - - `d` to go down 5 tasks - - `u` to go up 5 tasks - - `D` to delete a task (with a confirmation dialog) - - `x` to cut a task - - `p` to paste a cut task + - Vim-like keybindings for navigation: + - `hjkl` to navigate in and between subtask lists. + - `HJKL` to move a task in and between subtask lists. + - `g` to go to the top of the list. + - `G` to go to the bottom of the list. + - `d` to go down 5 tasks + - `u` to go up 5 tasks + - `D` to delete a task (with a confirmation dialog) + - `x` to cut a task + - `p` to paste a cut task 3. **Task Operations**: - `a` to add a new task. - `A` to add a new subtask. - `a` to add a new task. - - `e` to edit the selected task using neovim. + - `e` to edit the selected task using external editor. - `d` to delete the selected task. (with confirmation using fzf) - `space` to toggle the completion status of a task. @@ -40,9 +63,7 @@ $ npm install --global td - Uses neovim for text editing. 5. **Persistence**: - - Save and load tasks from a file ($HOME/.config/td/tasks.json) - - TODO: configurable location - + - Save and load tasks from a file 6. **Search**: - `/` to search for tasks (fzf). diff --git a/source/app.js b/source/app.js index aee87ec..1f5bb64 100644 --- a/source/app.js +++ b/source/app.js @@ -7,6 +7,8 @@ import { loadTasks, saveTasks, commitAndPushTasks, pullTasks, addLog, readLog, s import { Tabs, Tab } from 'ink-tab'; import Scrollbar from "./scrollbar.js"; +// got it set to `n` - my alias for neovim +const EDITOR = process.env.TD_EDITOR || "n" const countIncompleteSubtasks = (task) => { if (!task.subtasks || task.subtasks.length === 0) return 0; @@ -111,11 +113,11 @@ export default function TaskApp() { const tempFile = "/tmp/task_edit.txt"; fs.writeFileSync(tempFile, task.content || task.name); try { - // Run Neovim in a tmux split and use "wait-for" to track when it closes - execSync(`tmux split-window -h 'n ${tempFile}; tmux wait-for -S nvim_done'`); + // Run editor in a tmux split and use "wait-for" to track when it closes + execSync(`tmux split-window -h '${EDITOR} ${tempFile}; tmux wait-for -S editing_done'`); - // Wait for Neovim to exit (blocks execution until the user quits Neovim) - execSync("tmux wait-for nvim_done"); + // Wait for editor to exit (blocks execution until the user quits the editor) + execSync("tmux wait-for editing_done"); } catch (error) { // If tmux is not available, open Neovim normally spawn("n", [tempFile], { stdio: "inherit" }); @@ -292,7 +294,12 @@ export default function TaskApp() { if (input === "\\") { - execSync("tmux-td") + try { + execSync("command -v tmux-td"); + execSync("tmux-td"); + } catch (error) { + log("tmux-td is not available"); + } } diff --git a/source/tasks.js b/source/tasks.js index 6b1acf2..c5ead36 100644 --- a/source/tasks.js +++ b/source/tasks.js @@ -7,6 +7,7 @@ if (!process.env.TD_TASK_DIR) { const TASK_FILE = path.join(process.env.TD_TASK_DIR, "tasks.json"); const QUERY_FILE = path.join(process.env.TD_TASK_DIR, "query"); const LOG_FILE = path.join(process.env.TD_TASK_DIR, "log"); + if (fs.existsSync(LOG_FILE)) { fs.rmSync(LOG_FILE) }