diff --git a/docs/customize/prompt-override.md b/docs/customize/prompt-override.md index a76a85eb60..cc6723cb50 100644 --- a/docs/customize/prompt-override.md +++ b/docs/customize/prompt-override.md @@ -40,4 +40,4 @@ For example, create a file named `prompts/genius/sql/sql-gen-clarify.vm`, will o │ └── sql-gen-design.vm └── sre └── generate-dockerfile.vm -``` \ No newline at end of file +``` diff --git a/docs/features/shell-suggest.md b/docs/features/shell-suggest.md new file mode 100644 index 0000000000..6af88c78c3 --- /dev/null +++ b/docs/features/shell-suggest.md @@ -0,0 +1,22 @@ +--- +layout: default +title: Shell Suggest +parent: Basic Features +nav_order: 12 +permalink: /features/refactoring +--- + +## Default context + +```kotlin +data class ShellSuggestContext( + val question: String, + val shellPath: String, + val cwd: String, + // today's date like 20240322 + val date: String = SimpleDateFormat("yyyyMMdd").format(Date()), + // operating system name + val os: String = System.getProperty("os.name") +) +``` + diff --git a/exts/ext-terminal/src/main/kotlin/cc/unitmesh/terminal/ShellCommandSuggestAction.kt b/exts/ext-terminal/src/main/kotlin/cc/unitmesh/terminal/ShellCommandSuggestAction.kt index 1541a4eb21..4f9a3ac882 100644 --- a/exts/ext-terminal/src/main/kotlin/cc/unitmesh/terminal/ShellCommandSuggestAction.kt +++ b/exts/ext-terminal/src/main/kotlin/cc/unitmesh/terminal/ShellCommandSuggestAction.kt @@ -59,7 +59,8 @@ class ShellCommandSuggestAction : AnAction() { val options = TerminalProjectOptionsProvider.getInstance(project) templateRender.context = ShellSuggestContext( - data, options.shellPath, options.startingDirectory + data, options.shellPath, + options.startingDirectory ?: project.guessProjectDir()?.path ?: System.getProperty("user.home") ) val promptText = templateRender.renderTemplate(template) @@ -159,4 +160,3 @@ class ShellCommandSuggestAction : AnAction() { } } -data class ShellSuggestContext(val question: String, val shellPath: String, val cwd: String) diff --git a/exts/ext-terminal/src/main/kotlin/cc/unitmesh/terminal/ShellSuggestContext.kt b/exts/ext-terminal/src/main/kotlin/cc/unitmesh/terminal/ShellSuggestContext.kt new file mode 100644 index 0000000000..e00ad0bb43 --- /dev/null +++ b/exts/ext-terminal/src/main/kotlin/cc/unitmesh/terminal/ShellSuggestContext.kt @@ -0,0 +1,14 @@ +package cc.unitmesh.terminal + +import java.text.SimpleDateFormat +import java.util.* + +data class ShellSuggestContext( + val question: String, + val shellPath: String, + val cwd: String, + // today's date like 20240322 + val date: String = SimpleDateFormat("yyyyMMdd").format(Date()), + // operating system name + val os: String = System.getProperty("os.name") +) \ No newline at end of file