Last active
June 20, 2026 17:47
-
-
Save masato3/478222b916a8273df6e602dcbd5c7443 to your computer and use it in GitHub Desktop.
パイプが存在していないならWezTerm経由でパイプ付与したNeovim起動。パイプが存在していたらNeovimに投げる。そのあとにWezTermの指定したタブへ切り替え
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経由でパイプ付与したNeovim起動。パイプが存在していたらNeovimに投げる。そのあとにWezTermの指定したタブへ切り替え | |
| ' WezTerm経由のYaziから、WezTerm経由のNeovim開く用 | |
| ' Gemini | |
| Option Explicit | |
| Dim shell, fso, args, filepath | |
| Set shell = CreateObject("WScript.Shell") | |
| Set fso = CreateObject("Scripting.FileSystemObject") | |
| Set args = WScript.Arguments | |
| ' --- 環境設定 --- | |
| Dim pipe, wezterm, nvim, wezterm_exe, target_tab_index | |
| pipe = "\\.\pipe\nvim-remote" | |
| wezterm = "C:\tools\WezTerm\wezterm-gui.exe" | |
| 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 -- """ & nvim & """ --listen """ & pipe & """ """ & filepath & """" | |
| Else | |
| startCmd = """" & wezterm & """ start -- """ & 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