better docs, configure editor by an env var

This commit is contained in:
Kacper Marzecki 2025-03-20 21:31:08 +01:00
parent f48445f3b6
commit 234e3d6efc
3 changed files with 53 additions and 24 deletions

View File

@ -1,38 +1,61 @@
# td # td
> This readme is automatically generated by [create-ink-app](https://github.com/vadimdemedes/create-ink-app) ## Install (this was generated by Ink starter, dunno if that works)
## Install
```bash ```bash
$ npm install --global td $ 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 # Manual
P.S. A more complete summary of keybinds can be displayed on `?` keybind
1. **Task Management**: 1. **Task Management**:
- Create, edit, delete tasks. - Create, edit, delete tasks.
- View lists in a ranger-like UI https://github.com/ranger/ranger - View lists in a ranger-like UI https://github.com/ranger/ranger
- Tasks can have subtasks. - Tasks can have subtasks.
2. **Navigation**: 2. **Navigation**:
- Vim-like keybindings for navigation: - Vim-like keybindings for navigation:
- `hjkl` to navigate in and between subtask lists. - `hjkl` to navigate in and between subtask lists.
- `HJKL` to move a task 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 top of the list.
- `G` to go to the bottom of the list. - `G` to go to the bottom of the list.
- `d` to go down 5 tasks - `d` to go down 5 tasks
- `u` to go up 5 tasks - `u` to go up 5 tasks
- `D` to delete a task (with a confirmation dialog) - `D` to delete a task (with a confirmation dialog)
- `x` to cut a task - `x` to cut a task
- `p` to paste a cut task - `p` to paste a cut task
3. **Task Operations**: 3. **Task Operations**:
- `a` to add a new task. - `a` to add a new task.
- `A` to add a new subtask. - `A` to add a new subtask.
- `a` to add a new task. - `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) - `d` to delete the selected task. (with confirmation using fzf)
- `space` to toggle the completion status of a task. - `space` to toggle the completion status of a task.
@ -40,9 +63,7 @@ $ npm install --global td
- Uses neovim for text editing. - Uses neovim for text editing.
5. **Persistence**: 5. **Persistence**:
- Save and load tasks from a file ($HOME/.config/td/tasks.json) - Save and load tasks from a file
- TODO: configurable location
6. **Search**: 6. **Search**:
- `/` to search for tasks (fzf). - `/` to search for tasks (fzf).

View File

@ -7,6 +7,8 @@ import { loadTasks, saveTasks, commitAndPushTasks, pullTasks, addLog, readLog, s
import { Tabs, Tab } from 'ink-tab'; import { Tabs, Tab } from 'ink-tab';
import Scrollbar from "./scrollbar.js"; import Scrollbar from "./scrollbar.js";
// got it set to `n` - my alias for neovim
const EDITOR = process.env.TD_EDITOR || "n"
const countIncompleteSubtasks = (task) => { const countIncompleteSubtasks = (task) => {
if (!task.subtasks || task.subtasks.length === 0) return 0; if (!task.subtasks || task.subtasks.length === 0) return 0;
@ -111,11 +113,11 @@ export default function TaskApp() {
const tempFile = "/tmp/task_edit.txt"; const tempFile = "/tmp/task_edit.txt";
fs.writeFileSync(tempFile, task.content || task.name); fs.writeFileSync(tempFile, task.content || task.name);
try { try {
// Run Neovim in a tmux split and use "wait-for" to track when it closes // Run editor 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'`); 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) // Wait for editor to exit (blocks execution until the user quits the editor)
execSync("tmux wait-for nvim_done"); execSync("tmux wait-for editing_done");
} catch (error) { } catch (error) {
// If tmux is not available, open Neovim normally // If tmux is not available, open Neovim normally
spawn("n", [tempFile], { stdio: "inherit" }); spawn("n", [tempFile], { stdio: "inherit" });
@ -292,7 +294,12 @@ export default function TaskApp() {
if (input === "\\") { if (input === "\\") {
execSync("tmux-td") try {
execSync("command -v tmux-td");
execSync("tmux-td");
} catch (error) {
log("tmux-td is not available");
}
} }

View File

@ -7,6 +7,7 @@ if (!process.env.TD_TASK_DIR) {
const TASK_FILE = path.join(process.env.TD_TASK_DIR, "tasks.json"); const TASK_FILE = path.join(process.env.TD_TASK_DIR, "tasks.json");
const QUERY_FILE = path.join(process.env.TD_TASK_DIR, "query"); const QUERY_FILE = path.join(process.env.TD_TASK_DIR, "query");
const LOG_FILE = path.join(process.env.TD_TASK_DIR, "log"); const LOG_FILE = path.join(process.env.TD_TASK_DIR, "log");
if (fs.existsSync(LOG_FILE)) { if (fs.existsSync(LOG_FILE)) {
fs.rmSync(LOG_FILE) fs.rmSync(LOG_FILE)
} }