diff --git a/metainfo.xml b/metainfo.xml
index fd63e74476..d71a699f10 100644
--- a/metainfo.xml
+++ b/metainfo.xml
@@ -127,6 +127,7 @@
Add support for highlighting matches of the currently selected text area (beyond double click)
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)
Add case-insensitive smart search (#1410)
Add OpenBSD support
Update of contour.desktop file (#1423)
diff --git a/src/contour/Actions.h b/src/contour/Actions.h
index 4ba5739b67..19171daa5b 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 0d30a015cc..5c7e4e8e9a 100644
--- a/src/contour/TerminalSession.cpp
+++ b/src/contour/TerminalSession.cpp
@@ -1129,12 +1129,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;