Skip to content

Instantly share code, notes, and snippets.

@masato3
Created July 10, 2026 10:55
Show Gist options
  • Select an option

  • Save masato3/46418bc8dce64eacf5fb641c6b18abb9 to your computer and use it in GitHub Desktop.

Select an option

Save masato3/46418bc8dce64eacf5fb641c6b18abb9 to your computer and use it in GitHub Desktop.
パイプが存在していないなら、WezTerm経由でfnm初期化してパイプ付与したNeovim起動。パイプが存在していたらNeovimに投げる。そのあとにWezTermの指定したタブへ切り替え
' パイプが存在していないなら、WezTerm経由でfnm初期化してパイプ付与したNeovim起動。パイプが存在していたらNeovimに投げる。そのあとにWezTermの指定したタブへ切り替え
' WezTerm経由のYaziから、WezTerm経由のNeovim開く用
Option Explicit
Dim shell, fso, args, filepath
Set shell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set args = WScript.Arguments
' --- 環境設定 ---
Dim pipe, wezterm, fnmInit, nvim, wezterm_exe, target_tab_index
pipe = "\\.\pipe\nvim-remote"
wezterm = "C:\tools\WezTerm\wezterm-gui.exe"
fnmInit = "C:\tools\cmder_mini\bin\fnm-init_command-prompt.cmd"
nvim = shell.ExpandEnvironmentStrings("%userprofile%\scoop\apps\neovim\current\bin\nvim.exe")
wezterm_exe = "C:\tools\WezTerm\wezterm.exe"
target_tab_index = "0"
' ----------------
' 引数(ファイルパス)の取得
If args.Count > 0 Then
filepath = args(0)
Else
filepath = ""
End If
' パイプが存在するかどうかで分岐
If fso.FileExists(pipe) Then
' ---------------------------------------------------------
' 2回目以降の起動: 既存のNeovimにリモートでファイルを送る
' ---------------------------------------------------------
If filepath <> "" Then
Dim remoteCmd
remoteCmd = """" & nvim & """ --server " & pipe & " --remote """ & filepath & """"
' ここは裏で処理するため 0 (非表示) で実行
shell.Run remoteCmd, 0, True
End If
' フォーカス対策(WezTermを前面へ)
WScript.Sleep 50
ActivateWezTerm
Else
' ---------------------------------------------------------
' 1回目: WezTermごと新規起動
' ---------------------------------------------------------
Dim startCmd
If filepath <> "" Then
startCmd = """" & wezterm & """ start -- cmd.exe /c """"" & fnmInit & """ && """ & nvim & """ --listen """ & pipe & """ """ & filepath & """"
Else
startCmd = """" & wezterm & """ start -- cmd.exe /c """"" & fnmInit & """ && """ & nvim & """ --listen """ & pipe & """"
End If
shell.Run startCmd, 1, False
End If
' メモリ解放
Set shell = Nothing
Set fso = Nothing
Set args = Nothing
' --- WezTermを確実にアクティブにするサブプロシージャ ---
Sub ActivateWezTerm()
Dim wmi, processes, process, activated
Set wmi = GetObject("winmgmts:\\.\root\cimv2")
Set processes = wmi.ExecQuery("Select * from Win32_Process Where Name = 'wezterm-gui.exe'")
activated = False
For Each process In processes
If shell.AppActivate(process.ProcessId) Then
activated = True
Exit For
End If
Next
If Not activated Then
shell.AppActivate "wezterm"
End If
Set wmi = Nothing
Set processes = Nothing
End Sub
' ==============================================================================
' WezTermの指定したタブへ切り替え
' ==============================================================================
Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run """" & wezterm_exe & """ cli activate-tab --tab-index " & target_tab_index, 0, False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment