「Windowsでエクスプローラーからフォルダを各種ターミナルで開く」の版間の差分

Notion-MW
Notion-MW
302行目: 302行目:
たとえば以下のようなvbsを用意する。
たとえば以下のようなvbsを用意する。


<syntaxhighlight style="margin-bottom:0.2em;" lang="python">vb.net
m_with_cap_m
Dim objShell
 
Set objShell = CreateObject("WScript.Shell")
<pre class="visual">Dim objShell
Set objShell = CreateObject(&quot;WScript.Shell&quot;)
objShell.CurrentDirectory = WScript.Arguments(1)
objShell.CurrentDirectory = WScript.Arguments(1)
objShell.Run(WScript.Arguments(0)),,False</syntaxhighlight>
objShell.Run(WScript.Arguments(0)),,False</pre>
<div style='text-align: center;'>startatdir.vbs</div>
<div style='text-align: center;'>startatdir.vbs</div>


489行目: 490行目:
<li><p>vbsの例</p>
<li><p>vbsの例</p>
<p>次の節で解説する「(自分が起動された)カレントディレクトリでの起動」にも対応している(引数がない場合)。</p>
<p>次の節で解説する「(自分が起動された)カレントディレクトリでの起動」にも対応している(引数がない場合)。</p>
<syntaxhighlight lang="</syntaxhighlight></li></ul>"></li></ul>
<pre class="visual">Dim objShell
Dim curDir


vb.net Dim objShell Dim curDir
Set ws = CreateObject(&quot;Wscript.Shell&quot;)
Dim dir
If WScript.Arguments.Count = 0 Then
  dir = ws.CurrentDirectory
Else
  dir = Wscript.Arguments(0)
End If
dir = Replace(dir,&quot;%&quot;,&quot;==%&quot;)
ws.run &quot;powershell -Command &quot;&quot;&amp; {Start-Process -Verb Runas -Filepath wt -Argumentlist powershell, -noexit, -command, Set-Location, -LiteralPath, ('\&quot;&quot;'''+($args[1].Trim('\&quot;&quot;') -replace '''', '''''' -replace ';', '\;' )+'''.Replace(''==%'',''%'')\&quot;&quot;')}&quot;&quot; --% &quot;&quot;\&quot;&quot;&quot;&amp;dir&amp;&quot;\&quot;&quot;&quot;&quot;&quot;, vbHide


<pre>    Set ws = CreateObject(&quot;Wscript.Shell&quot;)
Set objShell = Nothing</pre></li></ul>
    Dim dir
</li>
    If WScript.Arguments.Count = 0 Then
      dir = ws.CurrentDirectory
    Else
      dir = Wscript.Arguments(0)
    End If
    dir = Replace(dir,&quot;%&quot;,&quot;==%&quot;)
    ws.run &quot;powershell -Command &quot;&quot;&amp; {Start-Process -Verb Runas -Filepath wt -Argumentlist powershell, -noexit, -command, Set-Location, -LiteralPath, ('\&quot;&quot;'''+($args[1].Trim('\&quot;&quot;') -replace '''', '''''' -replace ';', '\;' )+'''.Replace(''==%'',''%'')\&quot;&quot;')}&quot;&quot; --% &quot;&quot;\&quot;&quot;&quot;&amp;dir&amp;&quot;\&quot;&quot;&quot;&quot;&quot;, vbHide
   
    Set objShell = Nothing
    ```</pre>
<ul>
<li><p>cmd</p>
<li><p>cmd</p>
<p><code>powershell &#45;Command &quot;&amp; &#123;$bak&#61;$env&#58;MY_PERCENT&#59;$mypath&#61;$args&#91;1&#93;.Trim(&#39;\&quot;&#39;)&#59; $env&#58;MY_PERCENT &#61; &#39;%%&#39;&#59;if ($mypath.Length &#45;gt 258) &#123; $mypath &#61; cmd /c \&quot;for %%A in (`\&quot;$($mypath.Replace(&#39;%%&#39;, &#39;%%MY_PERCENT%%&#39;))`\&quot;) do @echo %%&#126;sA\&quot; &#125;&#59;$env&#58;MY_PERCENT &#61; $bak&#59;Start&#45;Process &#45;Verb Runas &#45;Filepath wt &#45;Argumentlist &#39;&#45;d&#39;, (&#39;\&quot;&#39;+($mypath &#45;replace &#39;\\$&#39;,&#39;\\\\&#39; &#45;replace &#39;&#59;&#39;, &#39;\&#59;&#39;)+&#39;\&quot;&#39;), cmd&#125;&quot; &#45;&#45;%% &quot;\&quot;%V\&quot;&quot;</code></p>
<p><code>powershell &#45;Command &quot;&amp; &#123;$bak&#61;$env&#58;MY_PERCENT&#59;$mypath&#61;$args&#91;1&#93;.Trim(&#39;\&quot;&#39;)&#59; $env&#58;MY_PERCENT &#61; &#39;%%&#39;&#59;if ($mypath.Length &#45;gt 258) &#123; $mypath &#61; cmd /c \&quot;for %%A in (`\&quot;$($mypath.Replace(&#39;%%&#39;, &#39;%%MY_PERCENT%%&#39;))`\&quot;) do @echo %%&#126;sA\&quot; &#125;&#59;$env&#58;MY_PERCENT &#61; $bak&#59;Start&#45;Process &#45;Verb Runas &#45;Filepath wt &#45;Argumentlist &#39;&#45;d&#39;, (&#39;\&quot;&#39;+($mypath &#45;replace &#39;\\$&#39;,&#39;\\\\&#39; &#45;replace &#39;&#59;&#39;, &#39;\&#59;&#39;)+&#39;\&quot;&#39;), cmd&#125;&quot; &#45;&#45;%% &quot;\&quot;%V\&quot;&quot;</code></p>
514行目: 513行目:
<p><code>&quot;C&#58;\Program Files\Git\usr\bin\sh.exe&quot; &quot;C&#58;\path\to\gb&#45;wt&#45;admin.sh&quot; &quot;%V&quot;</code></p>
<p><code>&quot;C&#58;\Program Files\Git\usr\bin\sh.exe&quot; &quot;C&#58;\path\to\gb&#45;wt&#45;admin.sh&quot; &quot;%V&quot;</code></p>
<p>で、<code>gb&#45;wt&#45;admin.sh</code>の中身は以下。</p>
<p>で、<code>gb&#45;wt&#45;admin.sh</code>の中身は以下。</p>
<syntaxhighlight lang="</syntaxhighlight></li></ul>">
<syntaxhighlight lang="c#">#!/bin/sh
c# #!/bin/sh IFS= LANG=en_US.UTF-8 echo $*|/bin/sed 's/\/\\/'|/bin/cygpath -f -|printf %q $(/bin/cat) |/bin/sed &quot;s/'/''/g;s/%/==%/g;s/;/\\;/g&quot;|/bin/xargs -d '\n' -I {} powershell -Command Start-Process -Filepath wt -ArgumentList &quot;'&quot;'&quot;C:\Program Files\Git\usr\bin\env.exe&quot;'&quot;'&quot; , '&quot;MSYSTEM=MINGW64&quot;' , &quot;'&quot;'&quot;C:\Program Files\Git\usr\bin\sh.exe&quot;'&quot;'&quot; , &quot;'--login'&quot;, &quot;'-c'&quot;, &quot;'&quot;'&quot;IFS=;cd $(echo {}| /bin/sed s/==%/%/g) ; exec bash&quot;'&quot;'&quot; ```
IFS=
LANG=en_US.UTF-8
echo $*|/bin/sed 's/\\/\\\\/'|/bin/cygpath -f -|printf %q $(/bin/cat) |/bin/sed "s/'/''/g;s/%/==%/g;s/;/\\\\;/g"|/bin/xargs -d '\n' -I {} powershell -Command Start-Process -Filepath wt -ArgumentList "'"'"C:\Program Files\Git\usr\bin\env.exe"'"'" , '"MSYSTEM=MINGW64"' , "'"'"C:\Program Files\Git\usr\bin\sh.exe"'"'" , "'--login'", "'-c'", "'"'"IFS=\;cd $(echo {}| /bin/sed s/==%/%/g) \; exec bash"'"'"</syntaxhighlight>
<p>Cygwinも同様である。</p></li></ul>


<pre>Cygwinも同様である。</pre>
<span id="vs-codeのメニューおまけ"></span>
<span id="vs-codeのメニューおまけ"></span>
==== VS Codeのメニュー(おまけ) ====
==== VS Codeのメニュー(おまけ) ====