New to Cygwin and trying to launch the batch file from the current working directory. I've done similar things before for .exe files in Windows 10 using the Registry Editor (see link):
https://www.windowscentral.com/how-launch-bash-shell-right-click-context-menu-windows-10
My Cygwin.bat file looks like this:
#echo off
SETLOCAL
set HOME=C:\path\to\home
C:
chdir C:\cygwin64\bin
bash --login -i
ENDLOCAL
However, when I right click on a directory in order to "Open Cygwin.bat here", the terminal opens at C:\path\to\home. How can I make sure the terminal opens in the current working directory?
To obtain the expected result you need to use the chere package.
chere -i
is usually enough to create a proper Bash Prompt Here entry in Explorer left mouse button menu.
Please note that the usage of the cygwin.bat is not recommended anyway as does not use mintty as terminal
Related
I'm trying to run code on Linux environment
Here's the code (saved as hello.pl):
#!/usr/bin/perl
use strict;
use warnings;
print "Hello You\n";
Here's what I tried on my linux environment:
%perl hello.pl
I tried listing out the path starting from C:\Users\... and so on
I keep getting error that says:
Can't open perl script "hello.pl": No such file or directory
You have to be located in the same folder with the hello.pl in the "window" (aka terminal, or console) that you try to execute perl hello.pl.
On linux, you can determine the folder that you're in by issuing pwd.
If you're not in the same folder (the most probable cause of your error), you have 2 options:
Navigate to that folder with cd /path/to/your/script/location you have to replace the /path/to/your/script/location in the example, with your actual path
Execute the file with perl /path/to/hello.pl - of course, you have to replace the /path/to/ in the example, with your ac
Also, you can try and view the file from the console running a less hello.pl
In cygwin you might try: /cygdrive/c/Users/bonan/Desktop/perl/hello.pl.
Alternatively at your prompt try tying in just perl without hitting enter, and then drag the hello.pl file from its file explorer location into the terminal window. That should paste the full file path to the file as text into the command prompt. If you're using cygwin I forget it if properly pastes the path with forward-slashes, like /cygdrive/c/Users/bonan/Desktop/perl/hello.pl, or if it pastes what it would in cmd with backslashes as you've indicated you typed yourself.
The other thing to do that's relatively easy is right click the file and choose to open a terminal or shell here, which for cygwin you can get in your context menu by running chere -i once (it actually says "Bash prompt here" I think). And there's similar context menu options for cmd, powershell, an actual linux bash, or mac os x's terminal ... once you're in the same path as the file, you can just type perl heltab and autocomplete the filename assuming no other files in the same folder start with "hel".
I use phpstorm and it's terminal facility.
In terminal section I typed F:\Projects\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico - so it uses Cygwin as terminal. But it opens it in home folder. Is it possible to open it in different folder? By typing a command or by doing something else.
Because I have a folder called F:\Projects\Local in this folder I have vagrant and I want to open phpstorm, open terminal within php storm and just type vagran up. I don't want to open cgywin again.
thanks
If you just want to open Cygwin with Mintty in the project directory then you can execute the command:
F:\Projects\cygwin64\bin\mintty.exe /bin/env CHERE_INVOKING=1 /bin/bash -l
This will avoid automatically changing to the home directory. See https://code.google.com/p/mintty/wiki/Tips#Starting_in_a_particular_directory for more information on this command.
If you want to use the embedded PhpStorm terminal, then you can modify the Shell path in the terminal settings. Open File > Settings... > Tools > Terminal. Replace the shell path with F:\Projects\cygwin64\bin\env.exe CHERE_INVOKING=1 /bin/bash -l. You may need to restart PhpStorm after this change.
Note: this is assuming that your Cygwin Root Directory is F:\Projects\cygwin64\.
For whome the above way ain't work anymore, like in PhpStorm v. 2016.3. The shell path have to be enclosed in quotes
"C:\Users\MyUser\.babun\cygwin\bin\env.exe" CHERE_INVOKING=1 /bin/zsh.exe
For the PhpStorm that I'am using (v10.0.4) in Windows 10 I use this command works:
D:\tools\.babun\cygwin\bin\env.exe CHERE_INVOKING=1 /bin/bash.exe
I'm using Babun which installs the Cygwin in D:\tools\.babun\cygwin.
How do you install Vim such that it runs in the command line?
I saw a post here and it said to make sure that
[✓] Create .bat files for command line use
was checked. I did make sure that it was checked, but vim won't open in the command line. However,
gvim
will open gvim from the command line, which is a pop-up window. How do I open Vim so that I can edit files directly from the command line? I think that I need to edit the PATH, but I don't know what that is or how to edit it.
EDIT: I also looked at this and followed the directions, tailored to my system. Now vimtutor will briefly open the vimtutor for less than a second and close it! But Vim still doesn't work. Gvim will open Gvim still.
EDIT: I don't think I was clear when I wrote my post. Running
vim
does not open Vim on my computer. Neither does
vim.exe
Use the bottom right Win8 gesture and go as following: Settings > PC Info > Advanced System Settings > Advanced > Environment Variables. Under system variables find Path in the list.
Path is just a semicolon separated list of directories. Append vim.exe to the list and it's now in your path.
You want to run vim.exe, not gvim.exe.
Add this to the Path under system variables "C:\Program Files\Vim\vim82" . Then you are all done.
To Edit Environment Variables:
Click on Start Menu -> Type Environment Variables and Press Enter Supporting Image -> In bottom Right Corner you will find "Environment Variables" Supporting Image -> Under System Variables Search for Path Supporting Image -> Double Click To Edit -> Click on new and Paste the file address given AboveSupporting Image
Now you're done. Test it just by writing vim in Command Prompt or Windows Terminal.
I have installed mintty. After that I am not able to open gvim. As suggested in same question for emacs I use:
1) mintty gvim
this opens a new window with message :
E233: cannot open displayE852: The child process failed to start the GUI
Press ENTER or type command to continue
Also I have set : export DISPLAY=":0"
what I am doing wrong
You probably don't have an X server running. Look here for instructions on setting it up. Personally, I find it easier to just uninstall the cygwin version of gvim and use the windows version instead.
I had the same problem when starting gvim and was getting the error message as above.
My default DISPLAY setting is :0.0
However, I noticed in the output of my startxwin, that it said
"""
Rules = "base" Model = "pc105" Layout = "us" Variant = "none" Options = "none"
winMultiWindowXMsgProc - DISPLAY=:2.0
winInitMultiWindowWM - DISPLAY=:2.0
winProcEstablishConnection - winInitClipboard returned.
"""
I set my display to :2.0 and it works now.
ie
export DISPLAY=:2.0
Hope this helps.
[Further to this, the script seems to check /tmp/.X11-unix/Xn where n in Xn is a number.
It seems I had X0 and X1 already there, probably leftover from an older bad shutdown.
Deleting this seems to restore it back to using :0.0
]
you can define a function in your .bash_profile (you need to make sure gvim.exe is in your $PATH)
vim() {
echo "cygstart gvim.exe --remote-tab-silent $(cygpath -w "$#")"
cygstart gvim.exe --remote-tab-silent $(cygpath -w "$#")
}
For me, gvim was being picked up from /usr/bin/gvim
I installed gvim as a windows application and then invoked it from its windows path directly as
[cygwin$] /cygdrive/C/Program\ Files\ \(x86\)/Vim/vim74/gvim
And it worked.
Like user2250246, I just punted on trying to get cygwin's gvim to start working again, but I didn't want to type or alias gvim. (Which I probably should've. The alias is easier.)
I added the Windows app's gvim's path to my Windows environment variables:
Get the path to gvim by finding its icon in your Start menu and
right-clicking on it, then opening Properties. Find the Target link
and copy all but the final 'gvim.exe'.
Go to Control Panel -> System -> Advanced System Settings -> Environment
Variables -> System variables. Select Path. Click Edit.
Paste in that path at the start. Click OK. Click OK.
Then Cygwin will put your Windows gvim on its path, but it will put /usr/bin ahead of it on its own path. So
mv /usr/bin/gvim /usr/bin/gvim-screwed-up
mv /usr/bin/gvimdiff /usr/bin/gvimdiff-screwed-up
and your cygwin will find & run the Windows-installed gvim, with or without your cygwin X server running.
Unfortunately, it will no longer load your cygwin .vimrc! You'll have to fix that yourself.
Whenever I start my console gnome-terminal in Ubuntu, it starts in the home directory. How can I make it start in a different directory say ~/myfolder?
I tried to write cd ~/myfolder in ~/.profile but nothing happens.
If you start gnome-terminal like gnome-terminal --working-directory=myfolder it will start with the working directory at ~/myfolder so you could add a new entry to your menu to use that command instead of the other one.
I did this way - with script:
open 3 tabs in the same window size 170x40, each "tab" starts in a different directory.
gnome-terminal --geometry=170x40 --working-directory=myfolder1 \
--tab --working-directory=myfolder2 \
--tab --working-directory=myfolder3
Add the following to your ~/.bashrc
cd ~/myfolder
You could use the nautilus-open-terminal extension. This allows you to right-click on a folder in nautilus and open a terminal window with that directory as its working directory.
You can also run a terminal in the normal way, type "cd ", and drag a folder icon from nautilus to the window. This will paste the path of the folder into the command line and you then type return to change to that directory. You can do the same thing with regular files to paste their path and run commands on them.
Directory option
There is the option --working-directory to specify the startup directory of the terminal (no short option form).
The basic approach to open the terminal in /some/dir is
gnome-terminal --working-directory=/some/dir
but there is a trap...
Bad trap
Assuming we want to start the terminal in the directory ~/dir.
This does not work:
gnome-terminal --working-directory=~/dir
The command looks perfectly fine according to the option syntax, but the terminal starts in the home directory.
It's because it does not expand the tilde (~), for confusing reasons - see below.
Thesse do work:
gnome-terminal --working-directory=/home/auser/dir
gnome-terminal --working-directory=$HOME/dir
gnome-terminal --working-directory ~/dir
Tilde expansion
Note there is no = in the last variant. Because of this, the ~ is at the start of a shell word, and therefore is handeled by tilde expansion.
The problem is that ~ does not get expanded everywhere, but only in certain places. One of them is in variable assignments, like directory=~/dir. That's ok, ~ gets expanded to $HOME, but --working-directory=~/dir does not expand ~, because that is not a variable assignment, it only looks very similar.
Actually, this is how I turn it off for everyone by default.
gconftool-2 --direct \
--config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory/ \
--set -- type=bool /apps/nautilus-open-terminal/desktop_opens_home_dir true
From GNOME Terminal - Getting Started:
You can also specify a command that runs automatically when you start GNOME Terminal in the profile.
If the folder has a complicated path, ie not just ~/myfolder, you could create a symlink to it in your home directory so you can get to it quickly. You can also set the CDPATH environment variable to tell bash to search a list of directories when you type cd myfolder.
To open in my desired directory as root user I ran:
gnome-terminal --working-directory=/home/my-project/ -x bash -c "sudo su"
I'm impressed by
Neil's Mayhew comment
and
Volker's Siegel answer. I've tried to not only set default directory for
gnome-terminal but preserve habitual behavior of desktop environment as well (I'm using Linux Mint 17.1 Cinnamon,
GNOME Terminal 3.6.2, perhaps it also can be applied for other Gnome-congenered DEs). So let me put my two cents in.
Adding cd ~/myfolder at the very end of ~/.bashrc does the job. But as already mentioned it will affect every
interactive shell. Even more, if you open some directory in a file manager (Nemo or Nautilus or something like
this) and appeal to the context menu from there (e.g. right click and then select Open in Terminal) new instance of
gnome-terminal will be started in ~/myfolder regardless of the folder which was loaded in the file manager.
Even if you run gnome-terminal --working-directory=/some/other/folder explicitly it will still open ~/myfolder. Seems that the
approach with .bashrc is unusable.
gnome-terminal --working-directory=myfolder works fine but only when you use custom menu entry in you DE
(or custom shortcut on desktop) which runs terminal with this parameter. If you would like to run gnome-terminal from command line
or from mini-launcher (press Alt + F2), you have to type the parameter every time. Anyway this approach is more-or-less usable.
How gnome-terminal determines which folder to open? When --working-directory is not specified it opens current
working directory (e.g. $PWD) otherwise it opens directory specified explicitly.
I've found the following solution.
Create a file named gnome-terminal in your ~/bin folder. It will act as shortcut but from everywhere (start menu,
mini-launcher, other terminal instance, etc) because ~/bin is already in $PATH (at least in Linux Mint...). Make this file
executable. Then put the following content into the script:
#!/bin/bash
home_directory=~
if [ "$PWD" == "$home_directory" ]; then
# When 'gnome-terminal' was ran from either
# - start menu
# - mini-launcher
# ...
# parent directory is set to $HOME.
#
# We respect original command line arguments.
# For example, when terminal is ran from another
# terminal instance and '--working-directory' is
# specified explicitly we should left it as it is.
# If there are two '--working-directory' switches
# in the command line 'gnome-terminal' will pick up
# the last one.
#
# Also we use full path to executable here in order
# to prevent recursive calling of 'gnome-terminal' from
# '~/bin'.
/usr/bin/gnome-terminal --working-directory=/ "$#"
else
# 'gnome-terminal' was from another directory.
# We don't change anything.
/usr/bin/gnome-terminal "$#"
fi
If you run gnome-terminal from start menu you will see that current folder in new terminal is / (you can use any folder, for example, ~/myfolder because our custom wrapper is a Bash-script, so shell's expansion with work fine).
If you appeal to Open in Terminal in a file manager you will get current directory in the new terminal.
If you run gnome-terminal with explicit --working-directory parameter (perhaps, from existing terminal instance) new terminal instance will be opened in the directory you specified.