How to set bash interpreter path in IntelliJ - bash

I am wondering which path should be set in "Interpreter path" area in Run/Debug Configurations in IntelliJ, to complie and run bash script.
Using IntelliJ 15.0.3 on Windows 7

You must have a shell installed.
I have Git installed, so I use the path to the git shell.
Something like C:\Program Files\Git\bin\sh.exe.
I use also the --login -i flags for the "Interpreter options" field.

If you want to use the Windows CMD.exe you have to set:
Interpreter path: C:\WINDOWS\system32\CMD.exe (or wherever your cmd.exe is located)
Interpreter options: /C
Working directory: path/to/your/project
in the IntelliJ run config.
(Tested with IntelliJ 2017.3)

In Ubuntu,
Interrupter path can be set to: /bin/bash

On Windows 10 you can also use PowerShell.
Interpreter path: c:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
Interpreter options: -Command
Working directory: path/to/your/project

For gitbash as your interpreter i found 2 ways
1.- For "BashSupport" plugin in intellij
Type Ctrl + Alt + S to go to settings
Search for Bash Support or go to "Languages & Frameworks->BashSupport"
In "Default Interpreter" put the path for gitbash
C:\Program Files\Git\bin\bash.exe
Then right click on the script to run and click on Edit script
Then click in "Use project interpreter"
Then in "Interpreter options" put
--login -i --
2.- For "Shell Script" plugin in Intellij
First set gitbash as your terminal
Ctrl + Alt + S to go to settings
Search for Terminal or go to "Tools->Terminal"
In "Shell path" put
C:\Program Files\Git\bin\bash.exe
Then Right click on the script to run and click on Edit script
Then in "Interpreter path" put
C:\Program Files\Git\bin\bash.exe
Then in "Interpreter options" put
-login -i --

Related

WSL Bash with ZSH integrated in ConEmu - Open Here Issue

I am using Ubuntu Bash with ZSH installed on WSL, Windows 10.
Command in (ConEmu Task settings):
"%WINDIR%\System32\wsl.exe ~" -cur_console:p
Command in (ConEmu Integration settings):
-Single -run {Bash::ubuntu} -cur_console:n
All other terminals integrated in ConEmu I can open with right click in the current project folder, but Ubuntu Bash opens always in default folder (~).
I tried the settings described here:
ConEmu + WSL: Open new console in current tab directory
So, with the command:
set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -C~ -cur_console:pm:/mnt
It works the same as in my case.
With the correct one:
set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -cur_console:pm:/mnt
The terminal opens in current folder and it works, but opens in Bash, no more ZSH.
I would appreciate your help.
Finally it works with ZSH! My settings:
Tasks
Bash::ubuntu
-icon "%USERPROFILE%\ubuntu\ubuntu.ico"
"%WINDIR%\System32\wsl.exe" -cur_console:pm:/mnt
Integrations
Bash Here
-Single -run {Bash::ubuntu} -cur_console:n
%USERPROFILE%\ubuntu\ubuntu.ico

How to open webstorm from terminal

To edit files from terminal I use subl (for sublime text) in order to edit the file;
example: If i need to edit app.js file I use subl app.js
Is there any way I can set up webstorm to open from the terminal ?
Try in terminal 'wstorm' and 'webstorm'
If the commands don't work you can run in WebStorm: "Tools" -> "Create Command Line Launcher..."
Note: The solution works only for Linux / MacOS
Update January 2016 using Webstorm 11.0.3 on mac os x
There was no option as described in the accepted answer.
Instead, just use the already installed command line binary wstorm designed for this purpose. Location shown below:
If you actually wish to open webstorm and have it load the contents of the current working directory for example, then place a . after the command:
wstorm .
Noted, others had made similar comments in this answers section, and wished to clarify the situation.
In Webstorm 2020.1.2 you need to do it via JetBrains ToolBox Settings. To do that go to JetBrain Toolbox, click on the settings cog, open Shell Scripts and type the path: /usr/local/bin click apply. Go to your terminal, from your project folder type webstorm . Hope this helps.
As suggested by Ali Faris(comment below), if you have an error like this Shell Scripts failed: /usr/local/bin/webstorm (Permission denied): inside of the logs
Jetbrains Toobox -> settings -> show log files -> toolbox.log (for me in: ~/Library/Logs/JetBrains/Toolbox).
Change /usr/local/bin to another folder name of your choice with the correct access rights, e.g - I chose this name: ~/.jetbrains-launchers.
You can check if script is created by Jetbrains: ls ~/.jetbrains-launchers (you should see a script for each of the jetbrains applications you use).
Add this to your path if needed for example if you use zsh add this at the bottom of your .zshrc export PATH="$HOME/.jetbrains-launchers:$PATH"
Open a new terminal window and this should work.
Basically jetbrains will create script like this (in this case for webstorm cat ~/.jetbrains-launchers/webstorm):
#!/bin/bash
#Generated by JetBrains Toolbox 1.22.10970 at 2022-01-08T12:57:24.803251
declare -a ideargs=()
declare -- wait=""
for o in "$#"; do
if [[ "$o" = "--wait" || "$o" = "-w" ]]; then
wait="-W"
o="--wait"
fi
if [[ "$o" =~ " " ]]; then
ideargs+=("\"$o\"")
else
ideargs+=("$o")
fi
done
open -na "/Users/[YOUR-USER]/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-0/213.6461.79/WebStorm.app/Contents/MacOS/webstorm" $wait --args "${ideargs[#]}"
I also downloaded WebStorm and wanted to use a similar shortcut to open files directly from the terminal.
I was surprised to find I already had a shortcut in my command line tools for webstorm:
subl is to Sublime as wstorm is to Webstorm.
Otherwise, as anstarovoyt has kindly pointed out, you can simply create your own shortcut via "Tools" > "Create Command Line Launcher"
Another way to do that:
open -a /Applications/WebStorm.app #Open last project
open -a /Applications/WebStorm.app Desktop #Open particular folder
open -a /Applications/WebStorm.app Desktop myscript.js #Open particular file
You can add alias to your config file:
#Edit your config:
vim ~/.bashrc
#add line:
alias ws='open -a /Applications/WebStorm.app'
#Read your config file:
source ~/.bashrc
Now you can use it:
ws . myscript.js
I know this is an older thread, but trying to achieve this using Windows was kind of a pain and I wasn't able to find anything specifically designed for my purposes. I created a Bash function that you can add as an alias (for Git Bash on Windows) that works similar to the command line functions in Visual Studio Code.
Here's the link to the Gist.
If you change the integrated terminal in WebStorm to Git Bash (instructions included in the Gist), you can perform the following actions:
Create a new file in the current working directory and open it in the editor:
wstorm foo.js
Create a new file in an existing relative path and open it in the editor:
wstorm foo/bar.js
This also works with subdirectories that don't exist:
wstorm this/path/doesnt/exist/file.js
If you're working in a Git Bash terminal (not in WebStorm) and want to open WebStorm up in the current directory, you can open it similar to Visual Studio Code:
wstorm .
Note: This needs to be done in a directory with a .idea folder.
As of 2019-03-09, WebStorm 2018.3.4 on Mac does not have Tools > "Create Command Line Launcher...". However, this works:
WebStorm Preferences > Keymap > Main Menu > Tools > Create Command-line Launcher...
Right-click "Create Command-line Launcher..." > Add Keyboard Shortcut
Assign a keyboard shortcut
Close Preferences
Type the keyboard shortcut to open "Create Launcher Script"
Click Ok to run the script
You can now launch WebStorm from the terminal with webstorm and can choose a directory to open
After setting up WebStorm to create the cli launcher you actually want to run
wstorm . &
to run the IntelliJ on the background otherwise IntelliJ closes if you happen to close the terminal you have launched the app from.
In WebStorm IDE, click DOUBLE CLICK ON SHIFT and type Create Command Line Launcher then click OK from luncher script promote .
cd project_folder_path using terminal and type webstorm ./ .
that is not for Windows OS
In Ubuntu terminal type:
/var/opt/webstorm6/WebStorm-129.664/bin/webstorm.sh
Note: please see your WebStorm build version, code mine is 129.664
In the terminal, while being in the given project folder:
webstorm .
I know that this is a pretty old thread, but I recently came across this problem on Windows (I'm using the JetBrains Toolbox).
With the following steps all new and existing applications that have been installed with the Toolbox will be added to your path!
Follow these steps to achieve this:
Because of permissions, we need to create a new directory in your user. I named it .path, so that I can also store any other application there in the future. So this will be C:\Users\<PC_USER>\.path\.
The the Toolbox click on the gear icon in the top right corner.
Then click on Enable Shell Scripts and/or Generate Shell Scripts.
In the input field that is located under the switch paste your path folder. (C:\Users\<PC_USER>\.path\)
Open your Edit the system environment variables program that can be found in Windows search or the control panel.
Click on the Environment Variables... button that is located in the right corner, a new window should pop up.
In the new window select the variable that says Path in the Variable column from the top list and then click on the edit button that is situated under the top list. Another new window should pop-up.
Click on new and paste your path there. (C:\Users\<PC_USER>\.path\)
Click on Ok in Edit environment variable > Environment Variables > System Properties.
Go to C:\Users\<PC_USER>\.path\ and all your toolbox installed applications should be there.
Restart your CLI and it should work.
The wstorm command didn't work in my Git bash, so I added the following function to my .bash_profile instead:
wstorm() {
/c/Program\ Files\ \(x86\)/JetBrains/WebStorm\ 2016.2.2/bin/WebStorm.exe $PWD/$1
}
A short solution relevant to the year 2021 for Linux users.
Just execute the comand:
sudo ln -s /<your path to Webstorm directory>/bin/webstorm.sh /usr/local/bin/webstorm
Since /usr/local/bin should be in the PATH environment variable by default, you should be able to run the webstorm command from anywhere in the shell.
More details Webstorm docs
I am running Windows 10 and whipped up a batch file (ws.bat) that implements this with optional command line argument for path to load).
:: place this batch file in your path and set to your WS EXE
:: ref: https://www.robvanderwoude.com/battech_defined.php
:: author: bob#bobchesley.net
#echo off
set target=%1
if defined target (goto passedarg) else (goto noarg)
:passedarg
echo Starting WebStorm with '%target%'
"C:\Program Files\JetBrains\WebStorm 2018.3.2\bin\webstorm.exe" %target%
goto:EOF
:noarg
echo Starting WebStorm with 'Current Dir'
"C:\Program Files\JetBrains\WebStorm 2018.3.2\bin\webstorm.exe" .
Pretty simple but it works.
webstorm . doesn't work on Windows. Try this for the current folder:
webstorm $pwd
$pwd is the current folder's path

(ConEmu + Cygwin) How to change tab name of ConEmu from within a cygwin bash script

i've configuring my ConEmu + Cygwin enviroment. I've created a task, when i start it in a tab, the task will run a batch file, which in turn will change dir into cygwin and run
bash --login -i my_ssh_entry_script.sh
Inside my_ssh_entry_script.sh, it will read a config file in my home directory then print a menu for me to select which host to connect. And finally
...
exec ssh -p$port $userhost
Now i can work on the selected machine in the same conemu tab. This works fine. And the script also works on linux machine too.
But there is a little flaw. I can't change the tab's title. I've tried to change it to:
....
exec $(cygpath ${ConEmuDir})/ConEmu.exe /cmd ssh -p$port $userhost -cur_console:t:$title
But this will always create a new tab. Any suggestion to slove it? Thanks~
1) You need GuiMacro, thoroughly described in the project wiki:
http://conemu.github.io/en/GuiMacro.html
ConEmuC -GuiMacro Rename 0 "Title"
2) You do not need to run batch. It causes extra and useless cmd.exe in yours process tree. You can do all required "CD" and "SET" from the task content directly.
At least for cmd shell:
"-new_console:d:C:\Users\dir_name" cmd /V /K -new_console:t:Tab_renamed

Setup git in Intellij terminal

I want to use git in Intellij Terminal but it does not recognize the command. In Command Prompt and Windows power shell the command in recognized (I added the git path in System Environment Variables). I am also aware that Intellij has an GUI integration with Git.
So, can anyone tell me how can I use the git command in the Intellij terminal.
Setup JetBrains(InteliJ, WebStorm, PHPStorm) IDE terminal to use GIT bash
File
Settings
(Enter 'Terminal' in search)
Change Shell path to:
"C:\Program Files\Git\bin\sh.exe" --login -i
or
"C:\Program Files\Git\bin\bash.exe"
If you have another directory for installed git change it respectively.
In the IDEA settings make sure that your terminal path leads to "usr/bin" instead of "/bin".
As a result you will see pretty rich console output:
For me, it works also but only the path of Git Bash has changed in Windows :
"C:\Users\REPLACE_THIS_BY_YOUR_USER\AppData\Local\Programs\Git\bin\sh.exe" --login -i
The full path is not needed anymore (windows), I just replaced cmd.exe to sh.exe and bingo was his name O
Settings > Tools > Terminal > Shell path > sh.exe
In my case, the Git Bash through IntelliJ had TERM=xterm-256color.
Regular Git Bash had TERM=xterm
To fix the garbled characters issue in IntelliJ Idea,
Go to "File | Settings | Tools | Terminal"
Environment Variables: TERM=cygwin
In IntelliJ Terminal, Shell Path I was using was already:
C:\Users\<userId>\programs\Git\bin\bash.exe --login -i
You don't need to reinstall anything. Go to:
File
Settings
Search for terminal
in shell path type: "C:\Program Files\Git\bin\sh.exe" --login -i (or another directory where you installed Git)
This worked for me:
IntelliJ:
File->Settings->Version Control->Git:
On the right side, Path to Git executable:
"C:\Program Files\Git\bin\git.exe"

Open Cygwin at a specific folder

How can I create a Cygwin shortcut that will open Cygwin at a specific folder? This would obviate having to type
cd /cygdrive/c/Users/Tom/Desktop/
each time I launch Cygwin.
When you install Cygwin (or if you’ve already installed it, download it again and start setup again to run an update), make sure that you select the chere package under the "Shells" category.
After Cygwin is launched, open up a Cygwin terminal (as an administrator) and type the command: chere -i -t mintty -s bash.
Now you should have "Bash Prompt Here" in the Windows right-click context menu.
(mintty is Cygwin's default terminal. If you don't choose it with the -t option, your "Bash Prompt Here" will use the same terminal as the Windows Command Prompt, which prevents horizontal resizing.)
Here's what I use. It doesn't require chere package or registry tinkering. Works on Windows 7.
Go to your "Send To" folder:
C:\Users\<your_user_name>\AppData\Roaming\Microsoft\Windows\SendTo
Create a shortcut named Bash Here having this in the Target field:
C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico C:\cygwin\bin\bash.exe -l -c "cd \"$0\" ; exec bash"
In the Windows Explorer, you right-click on a folder & select Send To > Bash Here.
And here's the opposite trick, opening a Windows Explorer in your current bash dir. Create this alias:
alias winx='/cygdrive/c/Windows/explorer.exe /e,\`cygpath -w .\`'
Note: the cygpath -w . part above is enclosed in back-ticks.
Now just type winx at the bash prompt, and a Win Explorer pops up there.
Note: If winx directs you to your documents folder, try
alias winx='/cygdrive/c/Windows/explorer.exe /e,`cygpath -w $PWD`'
From the cygwin terminal, run this command:
echo "cd your_path" >> ~/.bashrc
The .bashrc script is run when you open a new bash session. The code above with change to the your_path directory when you open a new cygwin session.
I made a .reg file that puts an "Open Cygwin Here" option in the right-click context menu.
It depends on the Cygwin "chere" package, which you can install using apt-cyg if you didn't install it in the initial setup.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash]
#="Open Cygwin Here"
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash\command]
#="C:\\cygwin\\bin\\mintty.exe -e /bin/xhere /bin/bash.exe"
For cygwin64 or installations without chere you can use the following command in a registry entry (assuming windows due to your path, also assuming cygwin installation directory is c:\cygwin64)
C:\cygwin64\bin\mintty.exe /bin/sh -lc 'cd "`cygpath "%V"`"; bash'
Works on Windows 7 and 8
Registry file available for download here: http://tomkay.me/blog/Cygwin64---Open-Here-18
Windows Registry Editor Version 5.00
; Open cygwin to folder
; http://tomkay.me - Tom Kay
[HKEY_CLASSES_ROOT\Folder\shell\open_cygwin]
#="Open Cygwin Here"
[HKEY_CLASSES_ROOT\Folder\shell\open_cygwin\command]
#="C:\\cygwin64\\bin\\mintty.exe /bin/sh -lc 'cd \"`cygpath \"%V\"`\"; bash'"
[HKEY_CLASSES_ROOT\Directory\Background\shell\open_cygwin]
#="Open Cygwin Here"
[HKEY_CLASSES_ROOT\Directory\Background\shell\open_cygwin\command]
#="C:\\cygwin64\\bin\\mintty.exe /bin/sh -lc 'cd \"`cygpath \"%V\"`\"; bash'"
If you want to have that directory as your default, simply add a cd statement to your ~/.profile file.
What I tend to do is use that method to set my usual directory, plus define aliases for my common cases as well:
alias tom="cd /users/tom"
or your equivalent. This lets me change directories very fast.
As two7s_clash said you first need to install chere package and setup mintty:
Open Cygwin terminal as administrator
apt-cyg install chere
chere -i -t mintty
You are now able to open cygwin in specific directory with a Right mouse click in Windows Explorer (Context Menu) and select "Bash Prompt Here".
You can also open cygwin from a specific directory using windows command prompt:
Open windows command prompt
Navigate (cd) to custom directory
Execute C:\cygwin64\bin\mintty.exe C:\cygwin64\bin\env.exe CHERE_INVOKING=1 C:\cygwin64\bin\bash.exe -l
This command will open cygwin with current directory taken from command prompt.
FreeCommander
This command can also be used to open cygwin from custom file manager, like FreeCommander.
To open cygwin with current directory taken from FreeCommander, do the following:
Tools -> Favorite Tools -> Favorite tools edit... (Ctrl + Shift + Y)
Add a new toolbar (+ Icon), Shortcut: Insert
Name: cygwin
Program or folder: C:\cygwin64\bin\mintty.exe
Start folder: %ActivDir%
Parameter: C:\cygwin64\bin\env.exe CHERE_INVOKING=1 C:\cygwin64\bin\bash.exe -l
You can add custom shortcut to open cygwin from FreeCommander:
Tools -> Define keyboard shortcuts
Scroll down to "Favorite tool 01" (or "Favorite tool N")
Assign new shortcut key: I use Ctrl + Shift + T
Great reference: MinTTY Wiki, article Tips: Starting in a particular directory
I use and Icon to launch my cygwin without the chere package.
Create a shortcut on my desktop for the cygwin terminal.
R-click the icon and select properties.
On the shortcut tab, use this for the TARGET:
C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -c 'cd'
For START IN, Put the path of the dir/folder where you want to
launch cygwin. i.e. C:\some\dir\name\here
To create a Windows shortcut that launches a Cygwin terminal in a directory of your own choosing, try the following:
Right-click on the Windows desktop, select 'New', and then select 'Shortcut'.
For location of the item, enter the following text, changing the mintty path as needed and substituting the name of the desired directory where indicated.
C:\cygwin64\bin\mintty.exe /bin/sh -lc 'cd DESIRED-DIRECTORY; exec bash'
For example, the OP would use the following text:
C:\cygwin64\bin\mintty.exe /bin/sh -lc 'cd /cygdrive/c/Users/Tom/Desktop/; exec bash'
Click 'Next'.
Enter the desired name for the shortcut and click 'Finish'.
Multiple shortcuts can be placed on the desktop to open Cygwin terminals in various often-accessed directories.
Inspired by solution posted on How to open a Cygwin shell at a specific directory from Netbeans? at superuser.com.
I used the following lines of code to start zsh in the current directory in Win7.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash]
#="Open Cygwin Here"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash\command]
#="\"C:\\Programmieren\\cygwin64\\bin\\mintty.exe\" -i /Cygwin-Terminal.ico /bin/zsh --login -c 'cd \"%V\";zsh'"
note that i used %V instead of %L or %1 (since both didn't work for me)
Find file Cygwin.bat and make content like this:
#echo off
set newpath=%cd:\=/%
pushd "%~dp0"
chdir bin
bash --login -i -c "cd \"%newpath%\"; exec bash"
Add path to cygwin.bat to environment PATH.
Now in any folder you can type to address bar:
cygwin
Also you can type it when you in cmd.exe
When a fresh install is needed, I create a Windows "user environment variable " named HOME and assigns it the path of wherever "My Documents" reside.
The cygwin installer detects the HOME variable, automatically translates this into a cygpath and selects this it to be my ~ directory.
This has worked fine for every workstation I have used professionally the last 5 years (about 3 or 4, Win7). I have always been the only user on these machines, cannot say what the effect is.
I have made a registry edit script to open Cygwin at any folder you right click. It's on my GitHub.
Here's my GitHub
Sample RegEdit code from Github for 64-bit machines:
REGEDIT4
[HKEY_CLASSES_ROOT\Directory\shell\CygwinHere]
#="&Cygwin Bash Here"
[HKEY_CLASSES_ROOT\Directory\shell\CygwinHere\command]
#="C:\\cygwin64\\bin\\mintty.exe -i /Cygwin-Terminal.ico C:\\cygwin64\\bin\\bash.exe --login -c \"cd \\\"%V\\\" ; exec bash -rcfile ~/.bashrc\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\CygwinHere]
#="&Cygwin Bash Here"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\Background\shell\CygwinHere\command]
#="C:\\cygwin64\\bin\\mintty.exe -i /Cygwin-Terminal.ico C:\\cygwin64\\bin\\bash.exe --login -c \"cd \\\"%V\\\" ; exec bash -rcfile ~/.bashrc\""
Save the following code as a file: cygwin_bash.reg
This will add opening Cygwin in the current directory and opening Cygwin in the specified folder at the same time.
Use ".bashrc" instead of ".bash_profile" configuration. Because of exec bash. .bashrc is executed for interactive non-login shells. see: https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\z_cygwin_bash]
#="Cygwin Here"
"Icon"="C:\\cygwin64\\Cygwin.ico"
[HKEY_CLASSES_ROOT\Directory\Background\shell\z_cygwin_bash\command]
#="C:\\cygwin64\\bin\\mintty.exe /bin/sh -lc 'cd \"`cygpath \"%V\"`\"; exec bash'"
[HKEY_CLASSES_ROOT\Directory\shell\z_cygwin_bash]
#="Cygwin Here"
"Icon"="C:\\cygwin64\\Cygwin.ico"
[HKEY_CLASSES_ROOT\Directory\shell\z_cygwin_bash\command]
#="C:\\cygwin64\\bin\\mintty.exe /bin/sh -lc 'cd \"`cygpath \"%V\"`\"; exec bash'"
Open Cygwin terminal as Administrator
In powershell (using chocolatey):
choco install cyg-get
In cygwin
Will Install right-click menu
cyg-get install chere
chere -i
Now you can right click and use "Bash Prompt Here" in any folder.
You can add the icon to the shell by adding an Icon field set to the path to your Cygwin.ico file.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash]
#="Cygwin"
"Icon"="\"C:\\cygwin64\\Cygwin.ico\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash\command]
#="C:\\cygwin64\\bin\\mintty.exe -e /bin/xhere /bin/bash.exe"
On my Windows machine it was not taking:
chere -i -t mintty
Because mintty shell was not available,but you might have choice of various other shells like ash bash cmd dash mksh pdksh posh tcsh zsh passwd.
so I used :
chere -i -s bash
In the answer that uses the registry, I found that on Windows 2008 R2 SP1, you need to drop the Background out of the path. Further, since the chere and xhere are not part of cygwin64, here is a solution that works for both, combining the registry and the Send To solutions. Replace 'E:\cygwin64' with your install location:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_bash]
#="Open Cygwin Here"
[HKEY_CLASSES_ROOT\Directory\shell\cygwin_bash\command]
#="E:\\cygwin64\\bin\\mintty.exe -i /Cygwin-Terminal.ico --exec /bin/bash.exe --login -c \"cd '%1' ; exec bash -rcfile ~/.bashrc\""
This is the only Cygwin64 registry solution that worked for me in Windows 8.1:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\mintty]
#="Mintty from Here"
"NoWorkingDirectory"=""
[HKEY_CLASSES_ROOT\Directory\shell\mintty\command]
#="C:\\cygwin64\\bin\\mintty.exe -h always -e /usr/bin/ash -c 'cd \"$(/usr/bin/cygpath \"%L\")\"; exec /usr/bin/bash '"
Make sure you modify your 'C:\cygwin64' path as necessary.
I have created the batch file and put it to the Cygwin's /bin directory. This script was developed so it allows to install/uninstall the registry entries for opening selected folders and drives in Cygwin. For details see the link http://with-love-from-siberia.blogspot.com/2013/12/cygwin-here.html.
update: This solution does the same as early suggestions but all manipulations with Windows Registry are hidden within the script.
Perform the command to install
cyghere.bat /install
Perform the command to uninstall
cyghere.bat /uninstall
I had also problem with git, that used to "steal" my cygwin commands - so i needed to run
C:\cygwin\bin\mintty.exe -
but after installing chere and executing chere -i -t mintty -f as admin (see above), you can simply use :
C:\cygwin\bin\mintty.exe -e /bin/xhere /bin/bash.exe "."
I added this in Total Commander as custom button (right click on panel > add ...) and it works very well.
Create a bash file say move.sh which has the following code
C:\cygwin64\bin\run.exe -p /bin bash runFile.sh
This starts the Cygwin and executes the runFile.sh present in the bin directory of Cygwin
Suppose you want to navigate to a specific directory say E:\code
then runFile.sh has the following code cd E:
cd code
You can just open cygwin terminal and write: cd and after drag n drop the folder you want end enter!
Finally an answer which is independent of Cygwin itself.
This uses the fact that, if I am on the directory C:\\Cool and I call the command C:\\Cygwin\\bin\\mintty.exe, mintty will automatically open on the current directory, i.e., C:\\Cool.
First, you will need to create the file C:\\Cygwin\\silent_run.vbs with the following contents:
Function EnquoteString(argument)
EnquoteString = Chr(34) & argument & Chr(34)
End Function
arglist = ""
With WScript.Arguments
For Each arg In .Unnamed
' Wscript.Echo "Unnamed: " & arg
If InStr(arg, " ") > 0 Then
' arg contains a space
arglist = arglist & " " & EnquoteString(arg)
Else
arglist = arglist & " " & arg
End If
Next
End With
CreateObject("Wscript.Shell").Run Trim( arglist ), 0, False
Next, to install this answer, you will use a Windows Registry file. For that, just put the contents of the following file into a file named C:\\Cygwin\\AddMinttyToContextMenu.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\Terminal Here]
"Icon"="\"C:\\Cygwin\\bin\\mintty.exe\""
"Position"="Middle"
#="Terminal Here"
"CommandFlags"=dword:00000020
[HKEY_CLASSES_ROOT\Directory\Background\shell\Terminal Here\Command]
#="\"C:\\Cygwin\\bin\\mintty.exe\" -w max"
[HKEY_CLASSES_ROOT\Directory\shell\Terminal Here]
"Icon"="\"C:\\Cygwin\\bin\\mintty.exe\""
"Position"="Middle"
#="Terminal Here"
"CommandFlags"=dword:00000020
[HKEY_CLASSES_ROOT\Directory\shell\Terminal Here\Command]
#="cmd.exe /c cd /d \"%V\" && wscript \"C:\\Cygwin\\silent_run.vbs\" \"C:\\Cygwin\\bin\\mintty.exe\" -w max"
Now, Fix all hard coded paths, i.e, C:\\Cygwin to the actual location where your Cygwin installation is on.
Then, just open the file C:\\Cygwin\\AddMinttyToContextMenu.reg to install your new registry entries and you are done.
The file C:\\Cygwin\\AddMinttyToContextMenu.reg works by opening first a cmd.exe, changing to the directory where you are in, then, calling C:\\Cygwin\\silent_run.vbs to open the C:\\Cygwin\\bin\\mintty.exe terminal with the command line options -w max, i.e., to open it maximized.
The script C:\\Cygwin\\silent_run.vbs is required to open the C:\\Cygwin\\bin\\mintty.exe terminal without keeping the first cmd.exe we opened, open.
The first entry of C:\\Cygwin\\AddMinttyToContextMenu.reg does not use C:\\Cygwin\\silent_run.vbs because by default the HKEY_CLASSES_ROOT\Directory\Background\shell keys are already open in the current directory, then, we can just call C:\\Cygwin\\bin\\mintty.exe directly to get it working out of the box.
References:
How add context menu item to Windows Explorer for folders
VBScript pass commandline argument in paths with spaces
How to pass a command with spaces and quotes as a single parameter to CScript?
calling vbscript from another vbscript file passing arguments
https://ss64.com/vb/syntax-args.html
Check if string contains space
Running command line silently with VbScript and getting output?
http://www.vbsedit.com/html/6f28899c-d653-4555-8a59-49640b0e32ea.asp
https://superuser.com/questions/62525/run-a-batch-file-in-a-completely-hidden-way
How to run Batch script received as argument on VBscript?
Can I pass an argument to a VBScript (vbs file launched with cscript)?
#echo off
C:
SET mypath=%~dp0
c:\cygwin\bin\bash -c "cd '%mypath%'; export CHERE_INVOKING=1; exec /bin/bash --login -i"
Copy above commands in a text file and save it as .bat in any of "your folder of interest".
It should open cygwin in "your folder of interest".
based on #LindseyD answer I created a simple BAT file, that opens cygwin in current directory, it may be useful (for me it is). Assuming that You have cygwin's bin directory in PATH.
FOR /F %%x IN ('sh -c pwd') DO bash -l -i -c 'cd %%x; exec bash'
I don't know why I had to wast so much time, but this works for me on win 10, 64 bit:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash]
#="Open Cygwin Here"
[HKEY_CLASSES_ROOT\Directory\Background\shell\cygwin_bash\command]
#="C:\\cygwin64\\bin\\mintty.exe -i /Cygwin-Terminal.ico C:\\cygwin64\\bin\\bash.exe --login -c \"cd \\\"%V\\\" ; exec bash -rcfile ~/.bashrc\""
Probably the simplest one:
1) Create file foo.reg
2) Insert content:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\background\shell\open_mintty]
#="open mintty"
[HKEY_CLASSES_ROOT\Directory\background\shell\open_mintty\command]
#="cmd /C mintty"
3) Execute foo.reg
Now just right-click in any folder, click open mintty and it will spawn mintty in that folder.
Best to do like below:
HKEY_CLASSES_ROOT\Directory\shell\BashHere
Enter Data: Bash Here
HKEY_CLASSES_ROOT\Directory\shell\BashHere\command
Enter Data:
cmd.exe /c C:\cygwin\bin\bash.exe --login -c "cd '%1'; exec /bin/bash"

Resources