diff options
Diffstat (limited to 'packages/cli/src/ui/hooks/useShellHistory.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/useShellHistory.ts | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/packages/cli/src/ui/hooks/useShellHistory.ts b/packages/cli/src/ui/hooks/useShellHistory.ts index 2e18dfbd..a0812f5b 100644 --- a/packages/cli/src/ui/hooks/useShellHistory.ts +++ b/packages/cli/src/ui/hooks/useShellHistory.ts @@ -7,9 +7,8 @@ import { useState, useEffect, useCallback } from 'react'; import * as fs from 'fs/promises'; import * as path from 'path'; -import { isNodeError, getProjectTempDir } from '@google/gemini-cli-core'; +import { isNodeError, Storage } from '@google/gemini-cli-core'; -const HISTORY_FILE = 'shell_history'; const MAX_HISTORY_LENGTH = 100; export interface UseShellHistoryReturn { @@ -20,9 +19,12 @@ export interface UseShellHistoryReturn { resetHistoryPosition: () => void; } -async function getHistoryFilePath(projectRoot: string): Promise<string> { - const historyDir = getProjectTempDir(projectRoot); - return path.join(historyDir, HISTORY_FILE); +async function getHistoryFilePath( + projectRoot: string, + configStorage?: Storage, +): Promise<string> { + const storage = configStorage ?? new Storage(projectRoot); + return storage.getHistoryFilePath(); } // Handle multiline commands @@ -67,20 +69,23 @@ async function writeHistoryFile( } } -export function useShellHistory(projectRoot: string): UseShellHistoryReturn { +export function useShellHistory( + projectRoot: string, + storage?: Storage, +): UseShellHistoryReturn { const [history, setHistory] = useState<string[]>([]); const [historyIndex, setHistoryIndex] = useState(-1); const [historyFilePath, setHistoryFilePath] = useState<string | null>(null); useEffect(() => { async function loadHistory() { - const filePath = await getHistoryFilePath(projectRoot); + const filePath = await getHistoryFilePath(projectRoot, storage); setHistoryFilePath(filePath); const loadedHistory = await readHistoryFile(filePath); setHistory(loadedHistory.reverse()); // Newest first } loadHistory(); - }, [projectRoot]); + }, [projectRoot, storage]); const addCommandToHistory = useCallback( (command: string) => { |
