Nushell

WezTerm и nushell

# macOS:
brew install --cask wezterm
brew install nushell
brew install fzf fd

Создать файл config:

# Go to any Terminal emulator
cd ~/.config/
mkdir wezterm
cd wezterm
which nu # check nushell location for config
vim wezterm.lua

Вставить конфиг (путь до nushell проверить и заменить):

-- Load the wezterm module
local wezterm = require 'wezterm'

-- Initialize configuration object
local config = wezterm.config_builder and wezterm.config_builder() or {}

-- Use WebGPU for better performance
config.front_end = "WebGpu"
config.webgpu_power_preference = "HighPerformance"

-- Set Nushell as the default shell
-- This path is standard for Mac with Apple Silicon
-- To find the path on your system, run `which nu` in Terminal.app
config.default_prog = {'/usr/local/bin/nu'}

-- Get the home directory (works on both macOS and Windows)
local home = os.getenv("HOME") or os.getenv("USERPROFILE") or ""

-- Set XDG_CONFIG_HOME environment variable for Nushell
config.set_environment_variables = {
    XDG_CONFIG_HOME = home .. "/.config",
}

local quick_select_patterns = {
  -- Nushell error paths (like ╭─[/path/to/file.nu:1946:63])
  "─\\[(.*\\:\\d+\\:\\d+)\\]",

  -- Table patterns
  -- $env.config.table.mode = "default"
  -- $env.config.table.header_on_separator = true
  -- $env.config.footer_mode = "always"
  "(?<=─|╭|┬)([a-zA-Z0-9 _%.-]+?)(?=─|╮|┬)", -- Headers
  "(?<=│ )([a-zA-Z0-9 _.-]+?)(?= │)", -- Column values

  -- File paths (stops at ~, allows dots in path but stops before dot+space)
  "/[^/\\s│~]+(?:/[^/\\s│~]+)*(?:\\.(?!\\s)[a-zA-Z0-9]+)?",
}

config.quick_select_patterns = quick_select_patterns

return config

Переменные среды

Настроим переменную среды для VSCode - (для macOS):

# Для ZSH:
cat << EOF >> ~/.zprofile
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF
# Для Bash:
cat << EOF >> ~/.bash_profile
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF

Переменные для nushell - запустить config nu команду и добавить кониг с путями. Как вариант, запустив nu, можно узнать локацию файла с помощью команды $nu.config-path.

$env.PATH = (
    $env.PATH
    | split row (char esep)
    | append [
        "/opt/homebrew/bin"
        "/usr/local/bin"
        "/usr/bin"
        "/bin"
        "/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
        # ... последняя ссылка на VSCode, + можно добавить ещё разные пути
    ]
    | str trim
    | where {|i| $i | path exists }
    | uniq
)

$env.config.history.file_format = "Sqlite"
$env.config.history.max_size = 5_000_000
$env.config.show_banner = false

# ALT+SHIFT+R to see all history commands
$env.config.menus ++= [
    {
        # List all unique successful commands
        name: working_dirs_cd_menu
        only_buffer_difference: true
        marker: "? "
        type: {
            layout: list
            page_size: 23
        }
        style: {
            text: green
            selected_text: green_reverse
        }
        source: {|buffer, position|
            open $nu.history-path
            | query db "SELECT DISTINCT(cwd) FROM history ORDER BY id DESC"
            | get CWD
            | into string
            | where $it =~ $buffer
            | compact --empty
            | each {
                if ($in has ' ') { $'"($in)"' } else {}
                | {value: $in}
            }
        }
    }
]
$env.config.keybindings ++= [
    {
        name: "working_dirs_cd_menu"
        modifier: alt_shift
        keycode: char_r
        mode: emacs
        event: { send: menu name: working_dirs_cd_menu}
    }
]

# переключение между папками по частям их названий в стиле zsh
$env.config.completions.algorithm = "Fuzzy" 

# FZF дополнение по CTRL+T
$env.config.keybindings ++= [
    {
        name: fzf_files
        modifier: control
        keycode: char_t
        mode: [emacs, vi_normal, vi_insert]
        event: [
          {
            send: executehostcommand
            cmd: "
              let fzf_ctrl_t_command = \"fd --type=file | fzf --preview 'bat --color=always --style=full --line-range=:500 {}'\";
              let result = nu -c $fzf_ctrl_t_command;
              commandline edit --append $result;
              commandline set-cursor --end
            "
          }
        ]
    }
]

# для Quick Selection с CTRL+SHIFT+SPACE:
$env.config.table.header_on_separator = true
$env.config.footer_mode = "always"

Проба Quick Selection

  • Вывести список файлов в терминале nu с ls
  • Видим табличный вывод
  • Нажимаем Ctrl+Shift+Space для активации quick select mode. WezTerm подсветит:
    • Column headers (name, size, modified)
    • Individual cell values in each column
    • Any file paths У каждого поля будет буква или две с цифрой, нажание соответствующих букв скопирует поле в буфер обмена.

Настроить среду