Closed4

WezTerm + Nushell + StarShip環境セットアップメモ

ねおさんねおさん

やること

WindowsとMacそれぞれでターミナル環境構築

  • WezTerm
  • Nushell
  • Starship

ついでにVSCodeでNushellを使えるようにする

ねおさんねおさん

Windows

gsudo nushell starship関連

nu -version
0.96.1
starship --version
starship 1.20.1
branch:master
commit_hash:f505324
build_time:2024-07-27 09:12:42 +00:00
build_env:rustc 1.80.0 (051478957 2024-07-21),stable-x86_64-pc-windows-msvc

StartShip設定

mkdir ~/.cache/starship/
starship init nu | save ~/.cache/starship/init.nu
echo "\nsource ~/.cache/starship/init.nu\n"| save --append ($nu.config-path)

WezTerm

winget install wezterm

weztermの設定を編集

nushellからnvimを開く場合

nvim ($env.HOMEPATH + "/.wezterm.lua")

powershellからnvimを開く場合

nvim $HOME/.wezterm.lua
$HOME/.wezterm.lua
local wezterm = require 'wezterm'

return {
  scrollback_lines = 3500, -- 保持する行数
  enable_scroll_bar = true, -- スクロール有効化
  default_prog = { 'nu' }, -- 起動するシェル
}

nushell設定

weztermでnushellを使うと、なにかしら操作するたび改行されてしまう。
shell_integrationをfalseにする

$nu.config-path
    shell_integration: {
        # osc2 abbreviates the path if in the home_dir, sets the tab/window title, shows the running command in the tab/window title
-        osc2: true
+        osc2: false
        # osc7 is a way to communicate the path to the terminal, this is helpful for spawning new tabs in the same directory
-        osc7: true
+        osc7: false
        # osc8 is also implemented as the deprecated setting ls.show_clickable_links, it shows clickable links in ls output if your terminal supports it. show_clickable_links is deprecated in favor of osc8
-        osc8: true
+        osc8: false
        # osc9_9 is from ConEmu and is starting to get wider support. It's similar to osc7 in that it communicates the path to the terminal
-        osc9_9: tru
+        osc9_9: false
        # osc133 is several escapes invented by Final Term which include the supported ones below.
        # 133;A - Mark prompt start
        # 133;B - Mark prompt end
        # 133;C - Mark pre-execution
        # 133;D;exit - Mark execution finished with exit code
        # This is used to enable terminals to know where the prompt is, the command is, where the command finishes, and where the output of the command is
-        osc133: true
+        osc133: false
        # osc633 is closely related to osc133 but only exists in visual studio code (vscode) and supports their shell integration features
        # 633;A - Mark prompt start
        # 633;B - Mark prompt end
        # 633;C - Mark pre-execution
        # 633;D;exit - Mark execution finished with exit code
        # 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce
        # 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal
        # and also helps with the run recent menu in vscode
-        osc633: true
+        osc633: false
        # reset_application_mode is escape \x1b[?1l and was added to help ssh work better
-        reset_application_mode: true
+        reset_application_mode: false
    }

VSCode設定

settings.jsonを編集

settings.json
  "terminal.integrated.profiles.windows": {
+    "Nushell": {
+      "path": "C:\\Program Files\\nu\\bin\\nu.exe",
+      "icon": "terminal-nushell"
+    },
    "PowerShell": {
      "source": "PowerShell",
      "icon": "terminal-powershell"
    },
    "Command Prompt": {
      "path": [
        "${env:windir}\\Sysnative\\cmd.exe",
        "${env:windir}\\System32\\cmd.exe"
      ],
      "args": [],
      "icon": "terminal-cmd"
    },
    "Git Bash": {
      "source": "Git Bash"
    },
    "Ubuntu (WSL)": {
      "path": "C:\\WINDOWS\\System32\\wsl.exe",
      "args": ["-d", "Ubuntu"]
    }
  },
-  "terminal.integrated.defaultProfile.windows": "PowerShell",
+  "terminal.integrated.defaultProfile.windows": "Nushell",

ついでにnushell拡張機能をinstall
https://marketplace.visualstudio.com/items?itemName=TheNuProjectContributors.vscode-nushell-lang

ねおさんねおさん

Mac

nushell

brew install nushell
nu --version
0.96.1

starship

brew install starship
starshio --version
starship 1.20.1
branch:
commit_hash:
build_time:2024-07-27 09:07:23 +00:00
build_env:rustc 1.79.0 (129f3b996 2024-06-10) (Homebrew),

starship設定

windowsと同じ

デフォルトシェル変更

二通りある

ターミナルアプリでデフォルトを設定

WezTermの設定変更

~/.config/wezterm/wezterm.lua
return {
  default_prog = { '/opt/homebrew/bin/nu' },
}

ログインシェルを変更してしまう

下記のように記載があるので注意が必要

WARNING

Nu is still in development and is not intended to be POSIX compliant. Be aware that some programs on your system might assume that your login shell is POSIX compatible. Breaking that assumption can lead to unexpected issues.

https://www.nushell.sh/book/default_shell.html#setting-nu-as-default-shell-on-your-terminal

/etc/shellsに追加

# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
/opt/homebrew/bin/fish
+/opt/homebrew/bin/nu
chsh -s /opt/homebrew/bin/nu

PATHを引き継ぐ

cat $PATH
vi $nu.config-path
+$env.PATH = ($env.PATH + "{zshでcatされた内容}:/opt/homebrew/bin/")

Wezterm

brew install wezterm

wezterm設定

普通にスクロールできる&デフォルトシェルを変更できたので別に何もしなくていいかも

VSCode設定

settings.json
  "terminal.integrated.profiles.osx": {
+    "nushell": {
+      "path": "nu",
+      "icon": "terminal-nushell"
+    },
    "bash": {
      "path": "bash",
      "args": ["-l"],
      "icon": "terminal-bash"
    },
    "zsh": {
      "path": "zsh",
      "args": ["-l"]
    },
    "fish": {
      "path": "fish",
      "args": ["-l"]
    },
    "tmux": {
      "path": "tmux",
      "icon": "terminal-tmux"
    },
    "pwsh": {
      "path": "pwsh",
      "icon": "terminal-powershell"
    }
  },
+  "terminal.integrated.defaultProfile.osx": "nushell"
このスクラップは2024/08/20にクローズされました