When I copy a windows path from windows explorer's location bar, C:\Users\Administrator\Links, it gets automatically translated to one of the following:
Cygwin in Conemu:
/mnt/c/Users/Administrator/Links
Git bash in Conemu:
/mnt/c/Users/Administrator/Links
Cygwin64 Terminal:
(no translation)
C:\Users\Administrator\Links
Git Bash on Windows:
(no translation)
C:\Users\Administrator\Links
But Cygwin actually wants C:/Users/Administrator/nextcloud/diary
or
/cygdrive/c/Users/Administrator/nextcloud/diary
and Git Bash actually wants /c/Users/Administrator/Links
So each time I try to cd into that directory, I get bash: cd: /mnt/c/Users/Administrator/Links: No such file or directory. Then I have to manually change the path.
Is there a way to change Conemu's "translation" rule? Do you experience the same problems when using linux terminals with/without Conemu? How did you cope with this?
Edit:
The Git Bash is started in Conemu by setting up a task with commands:
C:\Program Files\Git\git-cmd.exe --no-cd --command=usr/bin/bash.exe -l -i -new_console:t:"Git Bash"
and Cygwin is started in Conemu with commands D:\app\cygwin64\Cygwin.bat -new_console:t:"cygwin"
I ran into the same problem using Cmder (which uses Conemu).
In the launch options (in Cmder, it's in Startup - Tasks), you must select the task (for example bash :: bash) and add:
-cur_console: m: "".
Indeed, according to the documentation:
https://conemu.github.io/en/NewConsole.html#syntax
in the options of -cur_console, we can read:
m: / mnt - defines ‘/ mnt’ prefix for Unix-path conversion, m: "" - no
prefix
Related
Background
I'm a Front End Web Developer that has started moving to PortableApps where I can; at least for the desktop machines I use (Windows) after building a machine and having to re-install Windows multiple times.
It's getting more and more important to use the command line with build automation tools, testing software with a CLI etc.
I have just got portable versions of Git (Bash) and ConEmu working from my Dropbox (but ideally this would work from USB too). This means I have access to a Unix shell on Windows with Git, but the .bash_profile (and .bashrc) I have saved I need to manually copy to the '~' (home) directory for each machine I use.
Question
Is there a way to link my portable console with bash files not located in the home directory of the user on each machine used?
For instance when my console opens and looks for these files, can I ask it to check a different directory without setting any config on each machine? And then get the .bash_history to save here too instead?
You can use symbolic links for .bash_profile and .bashrc:
ln -s /path/to/.bashrc ~/.bashrc
ln -s /path/to/.bash_profile ~/.bash_profile
And inside your .bashrc you can define where your history file is located:
export HISTFILE=/path/to/.bash_history
I don't think there's any way around having .bashrc and .bash_profile in your home directory. Unless you start bash with the --rcfile option:
bash --rcfile /path/to/.bashrc
There is also the system wide file located at /etc/bashrc.
I am using ConEmu 64bit with Cygwin 64bit on a Windows 7 machine.
I don't want to set the working directory for cygwin in my .bashrc, as I like to setup more than one Task for Cygwin with different path parameters.
I set up the "home directory" in the task parameters:
\dir "D:\Downloads\Programming\Selenium\"
and added this line in the commands window:
C:\cygwin64\Cygwin.bat --login -i
Nevertheless Cygwin does not start in the "cygwinized" version of the given directory (/cygdrive/d/Downloads/Programming/Selenium) but in "normal" home directory of my user (~).
I only found howto's on how to add a new path in bashrc. Maybe one of you can enlighten me.
First of all, have you look at contents of your C:\cygwin64\Cygwin.bat? Why not?
#echo off
C:
chdir C:\cygwin64\bin
bash --login -i
Obviously, Cygwin.bat will never open bash in your desired dir.
Also, Cygwin ignores user defined startup directory! That is because cygwin always do cd "${HOME}" from /etc/profile script.
But, for example, bash from msysgit works properly.
Solution
However, /etc/profile script checks for CHERE_INVOKING environment variable before CD doing. So, the proper command line for starting cygwin will be:
set CHERE_INVOKING=1 & c:\cygwin64\bin\sh.exe --login -i
Another workarounds you may find in the project wiki page.
I had a similar demand (opening a new Cygwin-Tab in the folder currently viewed in explorer via the context menu) and found the following solution:
As stated by Maximus the Cygwin-Bash is usually opened by C:\cygwin64\Cygwin.bat which includes the login process. My approach was to change the working directory through the login.
.bash_profile:
if [ -f "${HOME}/startup.sh" ] ; then
source "${HOME}/startup.sh"
fi
startup.sh
cdc "D:\Downloads\Programming\Selenium\"
#cdc is a custom function, see .bashrc
.bashrc
cdc()
{
# converts a double-quoted windows-path and changes directory to it
p=$(cygpath -u "$1")
cd "$p"
}
The login progress thus changes the path of you bash to the one you've set in startup.sh. You might of course just type a Cygwin-compatible path in startup.sh without using the custom-function of .bashrc. It's still quite useful, especially if you want to want to use a dynamic startup.sh.
More Dynamic-approach:
Create a Cygwin.bat in C:\opt\ConEmu\ConEmu with the following content:
Cygwin.bat
#echo off
C:
echo cdc %1 > C:\opt\cygwin64\home\%USERNAME%\startup.sh
:: Your ConEmu-Task-definition here
C:\opt\ConEmu\ConEmu64.exe /Single /cmd {Cygwin}
This one writes a cdc-command followed by the path you provide into your startup.sh and starts an new instance of the ConEmu-Task Cygwin. The task itself does not do anything but starting an instance of Cygwin in my configuration:
ConEmu Task {Cygwin}
"C:\opt\cygwin64\Cygwin.bat"
I invocate the Cygwin.bat through the context-menu of the explorer. Another way would be to make a Windows-Shortcut pointing to Cygwin.bat with you path appended.
Added to ~/.bash_profile
PATH=c:/Python27:$PATH
and
env | grep PATH
shows the path c:/Python27
However I cannot run python interpreter from command line in bash. I'm on Windows 7 and I can run python from any directory in command prompt after doing
path %path%;C:\Python
Or adding the path to my Environment Variables
In bash I am able to do other commands from any directory in terminal after adding their path to ~/.bash_profile given the path is a sub-directory of ~/
If the path in .bash_profile is C:/ rather than ~/ it doesn't work. So my question is when adding a path to .bash_profile where the location is in C:/ rather than ~/ how do i do it?
Bash uses : as the path separator, so you actually just added "c" and "/Python27" to your PATH.
Different Windows GNU toolset ports have different ways of working around this. You can try ls /c/, ls /cygdrive/c or read your port's documentation to see how it handles this.
If you find that e.g. /c/Python27 is mapped to c:\Python27, then you can add that to your path instead.
I start the msysGit Bash using the provided batch file (the one that simulates a Linux environment). Bash starts up in msysGit's home directory (on my flashdrive). I would like to leave this directory to go to my project's directory (also on my flashdrive). So, I enter "$ cd .." This has no effect at all. I type "$ ls" and I'm definitely still in the Git folder. I try "cd ~" which brings me to my user folder, but I can't get to the root directory of my flashdrive. How can I get there with msysGit Bash?
I cannot use git-cmd.bat because the computers at my school deny access to cmd.exe.
Alternative question: How can I run git-cmd without needing administrator permissions?
If there is another distributed-model version control system that works better on portable devices (especially on systems where cmd is restricted and I'm not an administrator), I'll gladly switch to it (if you know of one, please tell).
You should be able to access the root directory of any drive by specify its driver letter:
(for instance)
cd /e
Operating system: Windows XP SP3 (Unfortunately)
I have downloaded and installed the latest version of Cygwin and Git. I also have configured my environment to include the "bin" folders for each in my system path and also set a user variable TERM=msys. I can now go into cmd and use the following command, for example:
git status
and get colored output, i.e. for status, changes to be committed are green, while untracked files and such are red. This was not the case without having set TERM=msys.
However, since I also added the Cygwin bin to my path, I can use
ls
to get a directory listing, but not with colored output. Am I correct in assuming that, since I'm only using the binaries through cmd, and not Cygwin itself, that getting colored output would have to be done differently from just configuring a BASH profile? Assuming this is possible; however it would seem to follow that if it can be done with Git, then it can also be done with the Cygwin binaries.
I'd be happy to elaborate or clarify any details. Thanks.
The basic colors should still work when you do ls --color. Since you can't use alias in cmd.exe, you can use the doskey windows utility.
doskey ls=ls --color
There are various ways you can make it so the command gets run automatically every time you start a cmd.exe shell. Here's one: http://www.tildemark.com/loading-doskey-automatically-with-cmd/