터미널에서 키에 명령을 어떻게 할당합니까?


10

터미널에서 사용하는 단어에 특수 키 조합을 할당하는 솔루션이 있습니까? 예를 들어 less 명령은 매우 유용하며 ia lot을 사용하여 다른 프로세스의 출력을 파이프로 전달합니다.

아이디어는 다른 명령을 작성하기 위해 할당 된 터미널 사용에서만 활성화되는 특수 키 조합을 설정하는 것입니까? 따라서 터미널 창에서 Ctrl+ L를 누르면 쓸 수 있습니다.

| less

또는 Ctrl+ G는

| grep

참고 : 명령 줄에 문자를 추가하면 마지막으로 실행되지 않습니다. 비슷한 방법으로 탭 완성이지만 더 구체적입니다.

답변:


10

예, 바인드 명령을 사용할 수 있습니다

bind '"\ey"':"\"less \C-m\""

Alt-e를 less 명령에 매핑하고 실행합니다 (\ Cm aka Ctrl-m 사용)

아마 | 당신은 그것을 탈출해야합니다.

bind '"\ey"':"\"\|less \C-m\""

명령 행에 추가하려면 * \ Cm \ ""을 제거하십시오.

바인딩이 이미 정의되어 있으므로주의하십시오.

Ctrl + A    Go to the beginning of the line you are currently typing on
Ctrl + E    Go to the end of the line you are currently typing on
Ctrl + L                Clears the Screen, similar to the clear command
Ctrl + U    Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H    Same as backspace
Ctrl + R    Let’s you search through previously used commands
Ctrl + C    Kill whatever you are running
Ctrl + D    Exit the current shell
Ctrl + Z    Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W    Delete the word before the cursor
Ctrl + K    Clear the line after the cursor
Ctrl + T    Swap the last two characters before the cursor
Esc + T     Swap the last two words before the cursor
Alt + F     Move cursor forward one word on the current line
Alt + B     Move cursor backward one word on the current line
Tab     Auto-complete files and folder names

위에서 볼 수 있듯이 Control 키는 Cm으로 만들어 졌으므로 다음과 같이 Ctrl-g를 사용하여 less 명령을 시작할 수 있습니다.

' "\ Cg"'바인딩 : "\"\ | less * \ Cm \ ""

Alt (ALT 만 해당)의 키 코드를 얻으려면 쉘에서 read 명령을 사용할 수 있습니다.

@~$ read
^[y

^ [y는 \ ey와 같습니다

자세한 내용은이 질문에 대한 답변도 있습니다.

/programming/4119991/bash-call-script-with-customized-keyboard-shortcuts


고맙습니다. 바인딩을 삭제하거나 모든 바인딩을 표시하려면 어떻게해야합니까?
— NES

처음 두 가지 예가 잘못되었습니다. 바인딩 구문으로 할당 한 후 적은 시간이 지나면 항상 와일드 카드도 인쇄합니다.
— NES

bind -p 및 bind -P는 모든 바인딩을 보여줍니다. 나는 스타와 실수했다 ... 나는 대답을 업데이트 해요
— tmow

고마워 어류에서 같은 목표를 달성하는 방법에 대한 아이디어가 있습니까? 나는 지금까지 작동하지만 문제는 기본적으로 문자열을 명령 줄에 추가하는 대신 물고기가 자동으로 명령을 실행하는 것 같습니다. 여기에 linux.die.net/man/1/bind 맨 페이지가 있습니다. 불행히도 예제는 제 경우에별로 도움이되지 않습니다.
— NES

이것은 이미 내장 기능 내가 생각 fishshell.com/user_doc/index.html#editor가 에서 Alt-P 바로 가기 고소
— tmow
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.