Download packages/cli/src/ui/commands/copyCommand.ts from SaylorTwift/gemini-cli: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/SaylorTwift/gemini-cli/resolve/main/packages/cli/src/ui/commands/copyCommand.ts
- Command line
-
hf download hf://SaylorTwift/gemini-cli/packages/cli/src/ui/commands/copyCommand.ts
-
curl -L -o copyCommand.ts https://huggingface.co/SaylorTwift/gemini-cli/resolve/main/packages/cli/src/ui/commands/copyCommand.ts
1.93 kB
| /** | |
| * @license | |
| * Copyright 2025 Google LLC | |
| * SPDX-License-Identifier: Apache-2.0 | |
| */ | |
| import { debugLogger } from '@google/gemini-cli-core'; | |
| import { copyToClipboard } from '../utils/commandUtils.js'; | |
| import { | |
| CommandKind, | |
| type SlashCommand, | |
| type SlashCommandActionReturn, | |
| } from './types.js'; | |
| export const copyCommand: SlashCommand = { | |
| name: 'copy', | |
| description: 'Copy the last result or code snippet to clipboard', | |
| kind: CommandKind.BUILT_IN, | |
| autoExecute: true, | |
| action: async (context, _args): Promise<SlashCommandActionReturn | void> => { | |
| const chat = context.services.agentContext?.geminiClient?.getChat(); | |
| const history = chat?.getHistory(); | |
| // Get the last message from the AI (model role) | |
| const lastAiMessage = history | |
| ? history.filter((item) => item.role === 'model').pop() | |
| : undefined; | |
| if (!lastAiMessage) { | |
| return { | |
| type: 'message', | |
| messageType: 'info', | |
| content: 'No output in history', | |
| }; | |
| } | |
| // Extract text from the parts | |
| const lastAiOutput = lastAiMessage.parts | |
| ?.filter((part) => part.text) | |
| .map((part) => part.text) | |
| .join(''); | |
| if (lastAiOutput) { | |
| try { | |
| const settings = context.services.settings.merged; | |
| await copyToClipboard(lastAiOutput, settings); | |
| return { | |
| type: 'message', | |
| messageType: 'info', | |
| content: 'Last output copied to the clipboard', | |
| }; | |
| } catch (error) { | |
| const message = error instanceof Error ? error.message : String(error); | |
| debugLogger.debug(message); | |
| return { | |
| type: 'message', | |
| messageType: 'error', | |
| content: `Failed to copy to the clipboard. ${message}`, | |
| }; | |
| } | |
| } else { | |
| return { | |
| type: 'message', | |
| messageType: 'info', | |
| content: 'Last AI output contains no text to copy.', | |
| }; | |
| } | |
| }, | |
| }; | |