aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Fabian Homborg <FHomborg@gmail.com>2016-05-13 15:02:28 +0200
committerGravatar Fabian Homborg <FHomborg@gmail.com>2016-05-25 16:10:16 +0200
commit2f51088bfb950ab0edcc53668c74e7fb6c58613f (patch)
tree4c91f9e34d4850caebfe9c7adfc7127681ba5924 /src
parent0a40dcdb44050ff06a89fb2a837db1b01c4dba8c (diff)
kill: Remove xsel integration
Overwriting the user's clipboard by default is annoying and contributors don't use it. This is better served via an explicit binding that calls e.g. `xsel`.
Diffstat (limited to 'src')
-rw-r--r--src/kill.cpp86
1 files changed, 2 insertions, 84 deletions
diff --git a/src/kill.cpp b/src/kill.cpp
index 17a10d85..706b1815 100644
--- a/src/kill.cpp
+++ b/src/kill.cpp
@@ -1,7 +1,7 @@
// The killring.
//
// Works like the killring in emacs and readline. The killring is cut and paste with a memory of
-// previous cuts. It supports integration with the X clipboard.
+// previous cuts.
#include "config.h" // IWYU pragma: keep
#include <stdbool.h>
@@ -12,8 +12,6 @@
#include <string>
#include "common.h"
-#include "env.h"
-#include "exec.h"
#include "fallback.h" // IWYU pragma: keep
#include "kill.h"
#include "path.h"
@@ -22,59 +20,10 @@
typedef std::list<wcstring> kill_list_t;
static kill_list_t kill_list;
-/// Contents of the X clipboard, at last time we checked it.
-static wcstring cut_buffer;
-
-/// Test if the xsel command is installed. Since this is called often, cache the result.
-static int has_xsel() {
- static signed char res = -1;
- if (res < 0) {
- res = !!path_get_path(L"xsel", NULL);
- }
-
- return res;
-}
-
void kill_add(const wcstring &str) {
ASSERT_IS_MAIN_THREAD();
if (str.empty()) return;
-
- wcstring cmd;
- wcstring escaped_str;
kill_list.push_front(str);
-
- // Check to see if user has set the FISH_CLIPBOARD_CMD variable, and, if so, use it instead of
- // checking the display, etc.
- //
- // I couldn't think of a safe way to allow overide of the echo command too, so, the command used
- // must accept the input via stdin.
- const env_var_t clipboard_wstr = env_get_string(L"FISH_CLIPBOARD_CMD");
- if (!clipboard_wstr.missing()) {
- escaped_str = escape(str.c_str(), ESCAPE_ALL);
- cmd.assign(L"echo -n ");
- cmd.append(escaped_str);
- cmd.append(clipboard_wstr);
- } else {
- // This is for sending the kill to the X copy-and-paste buffer.
- if (!has_xsel()) {
- return;
- }
-
- const env_var_t disp_wstr = env_get_string(L"DISPLAY");
- if (!disp_wstr.missing()) {
- escaped_str = escape(str.c_str(), ESCAPE_ALL);
- cmd.assign(L"echo -n ");
- cmd.append(escaped_str);
- cmd.append(L" | xsel -i -b");
- }
- }
-
- if (!cmd.empty()) {
- if (exec_subshell(cmd, false /* do not apply exit status */) == -1) {
- // Do nothing on failure.
- }
- cut_buffer = escaped_str;
- }
}
/// Remove first match for specified string from circular list.
@@ -99,38 +48,7 @@ const wchar_t *kill_yank_rotate() {
return kill_list.front().c_str();
}
-/// Check the X clipboard. If it has been changed, add the new clipboard contents to the fish
-/// killring.
-static void kill_check_x_buffer() {
- if (!has_xsel()) return;
-
- const env_var_t disp = env_get_string(L"DISPLAY");
- if (!disp.missing()) {
- size_t i;
- wcstring cmd = L"xsel -t 500 -b";
- wcstring new_cut_buffer = L"";
- wcstring_list_t list;
- if (exec_subshell(cmd, list, false /* do not apply exit status */) != -1) {
- for (i = 0; i < list.size(); i++) {
- wcstring next_line = escape_string(list.at(i), 0);
- if (i > 0) new_cut_buffer += L"\\n";
- new_cut_buffer += next_line;
- }
-
- if (new_cut_buffer.size() > 0) {
- // The buffer is inserted with backslash escapes, since we don't really like tabs,
- // newlines, etc. anyway.
- if (cut_buffer != new_cut_buffer) {
- cut_buffer = new_cut_buffer;
- kill_list.push_front(new_cut_buffer);
- }
- }
- }
- }
-}
-
const wchar_t *kill_yank() {
- kill_check_x_buffer();
if (kill_list.empty()) {
return L"";
}
@@ -141,4 +59,4 @@ void kill_sanity_check() {}
void kill_init() {}
-void kill_destroy() { cut_buffer.clear(); }
+void kill_destroy() {}