Last active
July 10, 2026 10:59
-
-
Save masato3/d3d72ffef5eb8f7341f50dc7d830271c to your computer and use it in GitHub Desktop.
パイプが存在していないなら、WezTerm経由でfnm初期化してパイプ付与したNeovim起動。パイプが存在していたらNeovimに投げる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' パイプが存在していないなら、WezTerm経由でfnm初期化してパイプ付与したNeovim起動。パイプが存在していたら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 | |
| 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") | |
| ' ---------------- | |
| ' 引数(ファイルパス)の取得 | |
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment