
독일어에서는 "Sehr geehrter Herr ...."로 메일과 편지를 시작합니다.
나는 이것을 계속해서 입력하는 것에 지쳤습니다. 그리고 이와 같은 텍스트 블록을 삽입할 수 있는 바로가기를 제공하도록 애플리케이션을 구성하는 데 지쳤습니다.
데스크탑 환경에서 댓글 텍스트 블록을 삽입하는 방법이 있나요?
이렇게 하면 vi, Thunderbird, Firefox, libreoffice에 텍스트 블록을 삽입할 수 있습니다.
또 다른 예: ssh-pub-key를 어딘가에 삽입해야 하는 경우가 종종 있습니다. 저는 ssh-copy-id를 사용하는 방법을 알고 있지만 구성 가능한 텍스트 블록 목록에 액세스할 수 있는 데스크톱 솔루션도 있으면 좋을 것 같습니다.
답변1
나는 사용한다자동키Ubuntu 소프트웨어 센터에서 설치됩니다.
정말 사용하기 쉬운
[email protected]
입력 gm
하고 탭을 눌러 내 이메일 주소와 같은 "문구"를 추가했습니다.<tab>
답변2
아래 스크립트는 작업을 수행합니다사용하는 응용 프로그램 Ctrl+V 텍스트를 붙여넣으려면. 예를 들어 * 에서는 작동하지 않는다는 것을 아는 것이 중요합니다 gnome-terminal
.
Firefox, Thunderbird, Libreoffice, Sublime Text 및 Gedit에서 아무 문제 없이 테스트했습니다.
작동 원리
스크립트가 호출되면 정의한 조각을 나열하는 창이 나타납니다. 항목을 선택하거나 해당 번호를 입력하면 텍스트 조각이 Ctrl+ V"호환" 되는 모든 응용 프로그램의 맨 앞 창에 붙여넣어집니다 .
스니펫 추가/편집
을 선택하면 manage snippets
의 스크립트 폴더가 ~/.config/snippet_paste
노틸러스에서 열립니다. 새 스니펫을 만들려면 스니펫의 텍스트가 포함된 텍스트 파일을 만드세요. 파일 이름을 지정하는 데 신경 쓰지 마십시오. 일반 텍스트라면 괜찮습니다. 스크립트는 파일의 콘텐츠만 사용하고 찾은 모든 파일('콘텐츠)의 번호가 매겨진 목록을 만듭니다.
코드 조각 디렉터리( ~/.config/snippet_paste
)가 존재하지 않으면 스크립트가 해당 디렉터리를 생성합니다.
사용하는 방법
먼저 설치
xdotool
하고xclip
, 시스템에 설치되어 있지 않은 경우:sudo apt-get install xdotool
그리고
sudo apt-get install xclip
아래 스크립트를 복사하여 다른 이름으로 저장하고
paste_snippets.py
다음 명령으로 실행하세요.python3 /path/to/paste_snippets.py
스크립트
#!/usr/bin/env python3
import os
import subprocess
home = os.environ["HOME"]
directory = home+"/.config/snippet_paste"
if not os.path.exists(directory):
os.mkdir(directory)
# create file list with snippets
files = [
directory+"/"+item for item in os.listdir(directory) \
if not item.endswith("~") and not item.startswith(".")
]
# create string list
strings = []
for file in files:
with open(file) as src:
strings.append(src.read())
# create list to display in option menu
list_items = ["manage snippets"]+[
(str(i+1)+". "+strings[i].replace("\n", " ").replace\
('"', "'")[:20]+"..") for i in range(len(strings))
]
# define (zenity) option menu
test= 'zenity --list '+'"'+('" "')\
.join(list_items)+'"'\
+' --column="text fragments" --title="Paste snippets"'
# process user input
try:
choice = subprocess.check_output(["/bin/bash", "-c", test]).decode("utf-8")
if "manage snippets" in choice:
subprocess.call(["nautilus", directory])
else:
i = int(choice[:choice.find(".")])
# copy the content of corresponding snippet
copy = "xclip -in -selection c "+"'"+files[i-1]+"'"
subprocess.call(["/bin/bash", "-c", copy])
# paste into open frontmost file
paste = "xdotool key Control_L+v"
subprocess.Popen(["/bin/bash", "-c", paste])
except Exception:
pass
노틸러스를 사용하지 않는 경우
다른 파일 브라우저를 사용하는 경우 라인 (29)를 바꾸십시오.
subprocess.Popen(["nautilus", directory])
에 의해:
subprocess.Popen(["<your_filebrowser>", directory])
단축키 조합에 스크립트 넣기
보다 편리하게 사용하려면 스크립트를 호출하는 바로가기를 만들 수 있습니다.
시스템 설정 →건반→단축키→맞춤 단축키
+명령을 추가하려면 클릭하세요 .
python3 /path/to/paste_snippets.py
스크립트는 다음 사이트에도 게시되어 있습니다.gist.gisthub.
*편집하다
아래 버전은 ( gnome-
) 터미널이 맨 앞의 애플리케이션인지 자동으로 확인하여 붙여넣기 명령을 자동으로 + 가 아닌 Ctrl+ Shift+ 로 변경하는 버전입니다.VCtrlV
사용법과 설정은 거의 동일합니다.
스크립트
#!/usr/bin/env python3
import os
import subprocess
home = os.environ["HOME"]
directory = home+"/.config/snippet_paste"
if not os.path.exists(directory):
os.mkdir(directory)
# create file list with snippets
files = [
directory+"/"+item for item in os.listdir(directory) \
if not item.endswith("~") and not item.startswith(".")
]
# create string list
strings = []
for file in files:
with open(file) as src:
strings.append(src.read())
# create list to display in option menu
list_items = ["manage snippets"]+[
(str(i+1)+". "+strings[i].replace("\n", " ").replace\
('"', "'")[:20]+"..") for i in range(len(strings))
]
# define (zenity) option menu
test= 'zenity --list '+'"'+('" "')\
.join(list_items)+'"'\
+' --column="text fragments" --title="Paste snippets" --height 450 --width 150'
def check_terminal():
# function to check if terminal is frontmost
try:
get = lambda cmd: subprocess.check_output(cmd).decode("utf-8").strip()
get_terms = get(["xdotool", "search", "--class", "gnome-terminal"])
term = [p for p in get(["xdotool", "search", "--class", "terminal"]).splitlines()]
front = get(["xdotool", "getwindowfocus"])
return True if front in term else False
except:
return False
# process user input
try:
choice = subprocess.check_output(["/bin/bash", "-c", test]).decode("utf-8")
if "manage snippets" in choice:
subprocess.call(["nautilus", directory])
else:
i = int(choice[:choice.find(".")])
# copy the content of corresponding snippet
copy = "xclip -in -selection c "+"'"+files[i-1]+"'"
subprocess.call(["/bin/bash", "-c", copy])
# paste into open frontmost file
paste = "xdotool key Control_L+v" if check_terminal() == False else "xdotool key Control_L+Shift_L+v"
subprocess.Popen(["/bin/bash", "-c", paste])
except Exception:
pass