LoginSignup
7
6

More than 5 years have passed since last update.

Windows エクスプローラからBashのコマンドウインドウを開く

Last updated at Posted at 2016-05-14

fish.png

はじめに

ターミナル使っているときに
CDコマンドでカレントディレクトリを移動するのが地味に面倒ですね。
本記事では、Windowsのエクスプローラで表示しているディレクトリで
bashを開くことでこの問題を解決します。

前提

[TIPS] Windowsエクスプローラからコマンドプロンプトを開く

アドレスバーに「cmd」と入力して [Enter]

cmd.gif

現在開いているフォルダのパスから使えるのが便利。
⇒ Windowsエクスプローラから Git-bash , Bash on Ubuntu on Windowsを開けると更に捗る。

0. 2016/05/14(初稿)時点の方法(Git-bash)

0-1. 以下のバッチファイルを作り、パスを通したディレクトリに配置

bash.bat
@echo off
if "%CD%" == "C:\WINDOWS\system32" (
cd %HOMEDRIVE%%HOMEPATH%
)
start "" "C:\Program Files\Git\git-bash.exe"

0-2. アドレスバーに「bash」と入力して [Enter]

2017/10/13追記

windows10では、アドレスバーに 「bash」 と入力すると
Bash on Ubuntu on Windows が起動する。
というか、BoW あれば特に Git-bash 要らない気も。。。

というわけで、

ConEmu使用のfish shellを開く

1. Windows10で快適なfishシェル環境構築

以下に従い、ConEmuでfishシェルを使用できるようにする。

Windows10で快適なfishシェル環境構築

2. ConEmuのtasks設定を編集

1.の記事
6.ConEmuの設定 のtasksの設定で HOMEDIRに移動させている ~ を削除する

ConEmuのtasks設定
-%windir%¥system32¥bash.exe ~ -new_console:t:"Fish" -cur_console:p -c fish
+%windir%¥system32¥bash.exe -new_console:t:"Fish" -cur_console:p -c fish

3. バッチファイルを作り、パスを通したディレクトリに配置

*1 を参考に作成。
本記事では、task名は Fish::Bash on Ubuntu on Windows としています。

fish.bat
@echo off

rem
rem fish shellをエクスプローラから開くためのバッチ
rem

setlocal

rem CONEMU_PATHは自身の環境に合わせて変更してください。
set CONEMU_PATH=C:\Program Files\ConEmu\
set CONEMU_EXE=ConEmu.exe

if "%PROCESSOR_ARCHITECTURE%" NEQ "x86" (
  set CONEMU_EXE=ConEmu64.exe
)

set CONEMU=%CONEMU_PATH%%CONEMU_EXE%

rem /cmd { } は ConEmuに設定した task名 を入力してください。
start "" "%CONEMU%" /dir "%CD%" /cmd "{Fish::Bash on Ubuntu on Windows}" -new_console

endlocal

3. アドレスバーに「fish」と入力して [Enter]

fish.gif

参考

*1) エクスプローラで開いているフォルダをConEmu上のnyagosで開く
https://qiita.com/bamchoh/items/431b9c7a8d8e9143016b

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6