#TIL #bash 커맨드 라인에 입력할 긴 명령어를 에디터로 편집하기

$ docker run \
--name gerrit-mysql \
--volumes-from=gerrit-data \
-e MYSQL_ROOT_PASSWORD=123456 \
-e MYSQL_DATABASE=reviewdb \
-e MYSQL_USER=gerrit2 \
-e MYSQL_PASSWORD=gerrit \
-d \
mysql:5.6.30

이렇게 긴 명령어를 바로 처넣는다. “거, 실수하기 딱 좋을 위치네”

edit-and-execute-command (C-x C-e)

Invoke an editor on the current command line, and execute the result as shell commands. Bash attempts to invoke $VISUAL, $EDITOR, and emacs as the editor, in that order.

- 8.4.8 Some Miscellaneous Commands

이럴 때, C-x C-e 키를 누르면 된다. 임시파일을 에디터로 연다. 에디터로 편집하고 저장한 내용을 커맨드 라인에 입력한다. 아무것도 설정 안 하면 emacs로 연다. 선인들의 지혜에 감탄을 안 할 수가 없다.

$ export VISUAL=ec-wait
$ export EDITOR=ec-wait
$ cat ec-wait
#!/bin/sh

if [ "OS" = "Windows_NT" ]
then
emacsclientw --alternate-editor=runemacs "$@"
else
emacsclient --alternate-editor=/Applications/Emacs.app/Contents/MacOS/Emacs "$@"
fi

실행 중인 emacs에서 열려고 VISUAL, EDITOR 환경 변수를 설정했다.

참고

Feedback plz <3 @ohyecloudy, ohyecloudy@gmail.com

A Random Post