From c28ebf3710dddc8cf652b74165e12da7b4dc1338 Mon Sep 17 00:00:00 2001 From: Yaraslau Tamashevich Date: Tue, 2 Jul 2024 16:05:52 +0300 Subject: [PATCH] Add paste selection option to evaluate selection via shell --- metainfo.xml | 1 + src/contour/Actions.h | 7 +++++-- src/contour/Config.cpp | 8 ++++++++ src/contour/TerminalSession.cpp | 7 +++++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/metainfo.xml b/metainfo.xml index 5b06fd3985..9e84914846 100644 --- a/metainfo.xml +++ b/metainfo.xml @@ -126,6 +126,7 @@
  • Add key bindings disabled indicator for status line (#783)
  • When switching to normal mode screen will stay in same position (#808)
  • Add customizable per-input-mode default text/background coloring for indicator statusline (#1528)
  • +
  • Add option PasteSelection to paste text as a shell input (#1549)
  • Update of contour.desktop file (#1423)
  • Changed configuration entry values for `font_locator` down to `native` and `mock` only (#1538).
  • Do not export the `TERM` environment variable on Windows OS (when using ConPTY).
  • 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;