自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Windows下Emacs中的zsh Shell

系統(tǒng) Windows Linux
運(yùn)行跨平臺(tái) shell(例如 Bash 或 zsh)的最大優(yōu)勢在于你能在多平臺(tái)上使用同樣的語法和腳本。在 Windows 上設(shè)置(替換)shell 挺麻煩的,但所獲得的回報(bào)遠(yuǎn)遠(yuǎn)超出這小小的付出。

[[259323]]

運(yùn)行跨平臺(tái) shell(例如 Bash 或 zsh)的***優(yōu)勢在于你能在多平臺(tái)上使用同樣的語法和腳本。在 Windows 上設(shè)置(替換)shell 挺麻煩的,但所獲得的回報(bào)遠(yuǎn)遠(yuǎn)超出這小小的付出。

zsh shell inside Emacs on Windows

zsh shell inside Emacs on Windows

MSYS2 子系統(tǒng)允許你在 Windows 上運(yùn)行 Bash 或 zsh 之類的 shell。使用 MSYS2 很重要的一點(diǎn)在于確保搜索路徑都指向 MSYS2 子系統(tǒng)本身:存在太多依賴關(guān)系了。

MSYS2 安裝后默認(rèn)的 shell 就是 Bash;zsh 則可以通過包管理器進(jìn)行安裝:

  1. pacman -Sy zsh

通過修改 etc/passwd 文件可以設(shè)置 zsh 作為默認(rèn) shell,例如:

  1. mkpasswd -c | sed -e 's/bash/zsh/' | tee -a /etc/passwd

這會(huì)將默認(rèn) shell 從 bash 改成 zsh。

要在 Windows 上的 Emacs 中運(yùn)行 zsh ,需要修改 shell-file-name 變量,將它指向 MSYS2 子系統(tǒng)中的 zsh 二進(jìn)制文件。該二進(jìn)制 shell 文件在 Emacs exec-path 變量中的某個(gè)地方。

  1. (setq shell-file-name (executable-find "zsh.exe"))

不要忘了修改 Emacs 的 PATH 環(huán)境變量,因?yàn)?MSYS2 路徑應(yīng)該先于 Windows 路徑。接上一個(gè)例子,假設(shè) MSYS2 安裝在 c:\programs\msys2 中,那么執(zhí)行:

  1. (setenv "PATH" "C:\\programs\\msys2\\mingw64\\bin;C:\\programs\\msys2\\usr\\local\\bin;C:\\programs\\msys2\\usr\\bin;C:\\Windows\\System32;C:\\Windows")

在 Emacs 配置文件中設(shè)置好這兩個(gè)變量后,在 Emacs 中運(yùn)行:

  1. M-x shell

應(yīng)該就能看到熟悉的 zsh 提示符了。

Emacs 的終端設(shè)置(eterm)與 MSYS2 的標(biāo)準(zhǔn)終端設(shè)置(xterm-256color)不一樣。這意味著某些插件和主題(提示符)可能不能正常工作 - 尤其在使用 oh-my-zsh 時(shí)。

檢測 zsh 否則在 Emacs 中運(yùn)行很簡單,使用變量 $INSIDE_EMACS。

下面這段代碼片段取自 .zshrc(當(dāng)以交互式 shell 模式啟動(dòng)時(shí)會(huì)被加載),它會(huì)在 zsh 在 Emacs 中運(yùn)行時(shí)啟動(dòng) git 插件并更改主題:

  1. # Disable some plugins while running in Emacs
  2. if [[ -n "$INSIDE_EMACS" ]]; then
  3. plugins=(git)
  4. ZSH_THEME="simple"
  5. else
  6. ZSH_THEME="compact-grey"
  7. fi

通過在本地 ~/.ssh/config 文件中將 INSIDE_EMACS 變量設(shè)置為 SendEnv 變量……

  1. Host myhost
  2. SendEnv INSIDE_EMACS

……同時(shí)在 ssh 服務(wù)器的 /etc/ssh/sshd_config 中設(shè)置為 AcceptEnv 變量……

  1. AcceptEnv LANG LC_* INSIDE_EMACS

……這使得在 Emacs shell 會(huì)話中通過 ssh 登錄另一個(gè)運(yùn)行著 zsh 的 ssh 服務(wù)器也能工作的很好。當(dāng)在 Windows 下的 Emacs 中的 zsh 上通過 ssh 遠(yuǎn)程登錄時(shí),記得使用參數(shù) -t,-t 參數(shù)會(huì)強(qiáng)制分配偽終端(之所以需要這樣,時(shí)因?yàn)?Windows 下的 Emacs 并沒有真正的 tty)。

跨平臺(tái),開源真是個(gè)好東西…… 

責(zé)任編輯:龐桂玉 來源: Linux中國
相關(guān)推薦

2011-07-20 10:18:41

EmacsShell

2010-01-16 20:22:47

Windows 7shell

2023-07-27 17:41:02

BashZshFish

2019-06-17 08:50:49

Emacs shell命令Windows

2011-07-19 10:16:55

2020-03-09 12:31:08

WindowsWindows 10GNU Emacs

2024-04-08 09:23:43

MacShell操作系統(tǒng)

2019-06-13 10:24:34

工具性能數(shù)據(jù)

2021-03-09 08:58:51

windowsemacswsl2

2020-04-26 20:00:14

EmacsLinux

2009-03-04 12:03:30

LinuxZsh技巧

2014-07-31 11:24:21

Linuxshell命令

2019-02-27 12:00:09

開源Org模式Emacs

2020-12-15 09:08:40

LinuxShell

2012-01-18 10:46:33

ibmdw

2010-04-08 15:37:33

2009-07-20 17:17:54

Shell函數(shù)ASP.NET環(huán)境

2010-11-02 21:17:17

2021-01-19 13:10:29

ZshLinuxUbuntu

2023-06-03 20:36:35

ShellLinuxBash
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)