Сервер X имеет несколько буферов обмена. Один с Ctrl + C называется буфер обмена, тот, где вы выделяете что-то, называется первичным. xclip позволяет вставлять вывод. Например, я скопировал часть вашего вопроса, но выделил другой текст в терминале:
Вы можете использовать эту идею в сценарии, который связан с быстрым сочетанием клавиш. Фактически, я написал сценарий, который размещен как
. Основная идея - связать его с ярлыком клавиатуры. Выделите то, что вы хотите добавить, затем нажмите ярлык. Например, я привязал мой к Ctrl + Alt + C . Exact command python /path/to/file.py
import gi
gi.require_version('Notify', '0.7')
from gi.repository import Notify
import subprocess
import os
import sys
# This script is meant to be bound to keyboard shortcut
def send_notification(title, text):
Notify.init(sys.argv[0])
n = Notify.Notification.new(title, text)
n.show()
def run_cmd(cmdlist):
# function for running
try:
stdout = subprocess.check_output(cmdlist)
except subprocess.CalledProcessError:
send_notification(sys.argv[0],"Clipboard error")
sys.exit(1)
else:
if stdout:
return stdout
# get contents of both clipboards
clip = run_cmd("xclip -o -sel clip".split())
primary = run_cmd("xclip -o -sel primary".split())
# write to temp file contents
# of both clipboards appended
temp_file = "/tmp/append.clip"
f = open(temp_file, "w")
f.write( clip + primary )
f.close()
# Read the new contents into clipboard
run_cmd(("xclip -sel clip " + temp_file).split())
# clean up
os.remove(temp_file)