windows에서 bash를 emacs shell로 사용

1 minute read

(setq windows? (eq system-type 'windows-nt))
(when windows?
  (let ((bash-dir "C:/Program Files (x86)/Git/bin"))
    (setq explicit-shell-file-name
          (concat bash-dir "/bash.exe"))
    (setq shell-file-name
          explicit-shell-file-name)
    (add-to-list 'exec-path bash-dir)
    (setq explicit-bash.exe-args
          '("--noediting" "--login" "-i"))
    (setenv "SHELL" explicit-shell-file-name)
    (setenv "PATH" (concat bash-dir
                           path-separator
                           (getenv "PATH")))))

windows는 cmd가 디폴트. 이번에 bash로 갈아탔다. 이제 모든 운영체제에서 emacs shell로 bash를 사용한다. 운영체제가 바뀌어도 기댈 수 있는 도구가 하나 더 생겼다.

bash

별로 안 친해. windows에서만 개발해 친할 일이 없었다. 대학교 때 뭔지도 모르고 조금 써본 정도가 전부다.

요즘 windows에서 bash를 많이 쓴다. git 때문에. 이거 아니면 쓸 일이 있었을까? Git for Windows가 설치하는 bash를 많이 쓴다. 손에 익으니 bash에서 쓰는 git이 가장 편하다. 주로 bash에서 사용하고 보조도구로는 sourcetree, emacs magit-mode를 사용한다.

shell은 배울 가치가 있다. 시간대비 효과가 좋기 때문이다. 처음엔 powershell을 점찍어 뒀는데, 매력을 못 느끼고 있다. 차라리 windows에서도 쓸 수 있으니 bash를 익히는 게 낫겠다. os x에서도 쓸 수 있으니깐.

emacs shell

emacs 안에서 shell을 쓸 수 있다. buffer로 shell과 상호작용을 한다. 거지 같지만 않다면 지원하는 걸 쓰는 게 좋다. 키바인딩을 비롯한 환경이 그대로여서 컨텍스트 스위칭이 없기 때문이다. 써보니 거지가 아니라 왕자네. 정말 편하다.

emacs 쓴다면 이거 놓치면 안 된다.

SHELL global variable

emacs에서 프로그램을 실행할 때 사용하는 shell을 정의한다.

M-x grep

대표적인 게 grep. 외부 프로그램을 실행해 결과를 받아온다. 이렇게 외부 프로그램 실행에 쓰는 shell을 정의한다.

explicit-shell-file-name

M-x shell

interactive subshell 실행에 사용

shell-file-name

M-x shell-command
M-x async-shell-command
M-x shell-command-on-region

single shell commands에 사용.

PATH, exec-path

executable-find에서 exec-path 를 사용한다.

PATH와 exec-path는 어디에서 참조하는가가 다르다. 구분해 사용할 필요가 있을까? 똑같이 맞춰서 가는 게 속 편해.

override keybindings

;;; shell mode
(add-hook 'shell-mode-hook
          (lambda ()
            ;; evil-scroll-up과 충돌
            (define-key shell-mode-map "\C-d" nil)))

키바인딩을 제거하려면 nil을 할당하면 된다.

reference

PS: 탐색기는 shell에서 start . 로 열 수 있다.

Update <2017-04-08 Sat> gcc 때문에 Git for Windows SDK를 사용 중.

C-x C-s C-x C-c