search by file & cat not echo | search by 's'
This commit is contained in:
parent
e3d48a09b6
commit
96ba769603
@ -3,7 +3,7 @@ import React, { useState, useEffect } from "react";
|
||||
import { render, Box, Text, useApp, useInput } from "ink";
|
||||
import fs from "fs";
|
||||
import { execSync, spawn } from "child_process";
|
||||
import { loadTasks, saveTasks, commitAndPushTasks, pullTasks, addLog, readLog } from "./tasks.js";
|
||||
import { loadTasks, saveTasks, commitAndPushTasks, pullTasks, addLog, readLog, saveQueryFile } from "./tasks.js";
|
||||
import { Tabs, Tab } from 'ink-tab';
|
||||
import Scrollbar from "./scrollbar.js";
|
||||
|
||||
@ -224,10 +224,11 @@ export default function TaskApp() {
|
||||
}
|
||||
}
|
||||
|
||||
if (input === "/") {
|
||||
if (input === "s") {
|
||||
try {
|
||||
const taskNames = tasks.map(taskContents).flat().map(fzfLine).join("\n");
|
||||
const query = execSync(`echo "${taskNames}" | fzf --prompt 'Search: '`, { stdio: "pipe" }).toString().trim();
|
||||
const queryFile = saveQueryFile(taskNames)
|
||||
const query = execSync(`cat ${queryFile} | fzf --prompt 'Search: ' --preview "echo {} | sed 's/|/\\n/g'"`, { stdio: "pipe" }).toString().trim();
|
||||
const res = findTaskPathWithContent(tasks, query)
|
||||
log("Path:", res)
|
||||
if (res) {
|
||||
@ -311,11 +312,11 @@ export default function TaskApp() {
|
||||
g/G - Go to top/bottom
|
||||
h/l - Navigate parent/subtasks
|
||||
a - Add task
|
||||
s - Add subtask
|
||||
A - Add subtask
|
||||
e - Edit task in Neovim
|
||||
s - Search
|
||||
S - Sync (Push/Pull)
|
||||
space - Toggle completion
|
||||
/ - Search
|
||||
? - Show help
|
||||
==========================
|
||||
` })
|
||||
|
||||
@ -5,11 +5,11 @@ if (!process.env.TD_TASK_DIR) {
|
||||
throw new Error("Environment variable TD_TASK_DIR is not defined");
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
const ensureIds = (tasks) => {
|
||||
return tasks.map(task => {
|
||||
if (!task.id) {
|
||||
@ -30,6 +30,10 @@ export function loadTasks() {
|
||||
}
|
||||
};
|
||||
|
||||
export function saveQueryFile(content) {
|
||||
fs.writeFileSync(QUERY_FILE, content);
|
||||
return QUERY_FILE;
|
||||
};
|
||||
export function saveTasks(tasks) {
|
||||
const updatedTasks = ensureIds(tasks);
|
||||
fs.writeFileSync(TASK_FILE, JSON.stringify(updatedTasks, null, 2));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user