diff --git a/src/contour/Actions.h b/src/contour/Actions.h index a5556040c7..48663f7435 100644 --- a/src/contour/Actions.h +++ b/src/contour/Actions.h @@ -49,7 +49,7 @@ struct OpenConfiguration{}; struct OpenFileManager{}; struct OpenSelection{}; struct PasteClipboard{ bool strip = false; }; -struct PasteSelection{}; +struct PasteSelection{ bool evaluateInShell = false;}; struct Quit{}; struct ReloadConfig{ std::optional profileName; }; struct ResetConfig{}; @@ -182,7 +182,10 @@ namespace documentation "Pastes clipboard to standard input. Pass boolean parameter 'strip' to indicate whether or not to " "strip repetitive whitespaces down to one and newlines to whitespaces." }; - constexpr inline std::string_view PasteSelection { "Pastes current selection to standard input." }; + constexpr inline std::string_view PasteSelection { "Pastes current selection to standard input." + "Option `evaluate_in_shell` specify if pasted text " + "must be appended with linefeed and used as an input " + "for the running shell" }; constexpr inline std::string_view Quit { "Quits the application." }; constexpr inline std::string_view ReloadConfig { "Forces a configuration reload." }; constexpr inline std::string_view ResetConfig { diff --git a/src/contour/Config.cpp b/src/contour/Config.cpp index 303d95d880..273291d5bc 100644 --- a/src/contour/Config.cpp +++ b/src/contour/Config.cpp @@ -1713,6 +1713,14 @@ std::optional YAMLConfigReader::parseAction(YAML::Node const& n } } + if (holds_alternative(action)) + { + if (auto eval = node["evaluate_in_shell"]; eval && eval.IsScalar()) + { + return actions::PasteSelection { eval.as() }; + } + } + if (holds_alternative(action)) { if (auto chars = node["chars"]; chars.IsScalar()) diff --git a/src/contour/TerminalSession.cpp b/src/contour/TerminalSession.cpp index cb3a918d9e..d4183e34dc 100644 --- a/src/contour/TerminalSession.cpp +++ b/src/contour/TerminalSession.cpp @@ -1126,12 +1126,15 @@ bool TerminalSession::operator()(actions::PasteClipboard paste) return true; } -bool TerminalSession::operator()(actions::PasteSelection) +bool TerminalSession::operator()(actions::PasteSelection paste) { if (QClipboard* clipboard = QGuiApplication::clipboard(); clipboard != nullptr) { string const text = normalize_crlf(clipboard->text(QClipboard::Selection)); - terminal().sendPaste(string_view { text }); + if (paste.evaluateInShell) + terminal().sendRawInput(string_view { text + "\n" }); + else + terminal().sendPaste(string_view { text }); } return true;