Access linux paths in windows git powershell - linux

I am running a Windows Powershell provided through the git for windows installation. This shell provides many unix style commands (i.e. "ls", "mv", etc.).
My question is: How do I access Unix style paths from the powershell cmd line on Windows?
Consider this example: the "ls" program is installed and works in the powershell. The path is shown as "/usr/bin/ls" if I type "which ls" as the cmd prompt. But if I try to change my current directory using "cd /usr/bin/", the shell complains that the path is not found.
I can't see any mounted volumes or anything like that using "mount" (perhaps in PowerShell it is a different command?).
I'm asking this question because I have other files that I need to get to which are listed under unix-style paths, and right now I can't get to anything. I figure if I can get to /usr/bin, then I can figure out how to get where I really need to go.

Powershell is not Unix. It may have a few familiar commands like "ls" and "ps", but that's where the similarity ends.
When you installed Git For Windows, you likely installed the Git Bash shell as well. Run that instead to get a more Unix like atmosphere. (Re-install Git For Windows if you didn't select this option on install).
But even with Git Bash, there's still no such folder as /usr/bin. That folder doesn't exist on Windows. If you want a Unix emulation on Windows that includes the traditional folder structure, use Cygwin. And you can run Git on that environment too and access an emulated /usr/bin folder.

Related

configure git in pycharm through WSL

It seems like something went wrong when I set git inside pycharm like this:
my git installed inside WSL is version-2.17.1; pycharm is professional version
You can't directly invoke Linux programs from a Win32 program like this. You may have better luck creating a batch file that invokes the wsl binary and use that. Something like the following in the batch file may be useful:
wsl git %*
Then invoke your batch file as the Git binary.
Do note that your Linux Git binary will expect Unix paths, not Win32 paths, so if you can't guarantee that Unix paths will be passed, you'll need to either switch both your editor and Git to be Linux programs, switch them both to be Windows programs, or not use Git inside your editor.

Setting Working Directory to Desktop in Cygwin

The current directory on cygwin is home/myuser. I navigated to cygwin and found it has a directory called home/myuser and could not figure out how I would navigate to the desktop. I did not want to add a desktop directory there and I could not navigate above the root folder (cygwin). Any idea on how I could do this?
This is essentially covered in the Cygwin FAQ under "How can I access other drives?". No, you're not trying to access another drive, but you are trying to access a folder outside of the Cygwin tree. As the FAQ item says, Cygwin maps your Windows drives as /cygdrive/<drive-letter>, so your desktop is likely something like /cygdrive/c/Users/<username>/Desktop. Note that the path has changed over the years with various versions of Windows and you didn't specify what version you're running, so it may not be exactly that.
Anyway, what I would do, would be to create a symbolic link to that from my Cygwin home folder. Something like this:
ln -s "/cygdrive/c/Users/<username>/Desktop" Desktop
I put the quotes in because depending on what version of windows you have, this path may include spaces.
You'll probably notice from the FAQ that the Cygwin version of bash accepts DOS-style pathnames, so you can actually do the following:
cd "C:/Users/<username>/Desktop"
But I recommend avoiding such syntax. Not all Cygwin apps understand DOS-style paths, and you'll only end up confusing yourself if you have to try to figure out whether what you're doing will work with a DOS-style path or not. It's best to just use the Unix-style paths for everything when in the Cygwin environment, unless you have a very good reason not to.
Add
cd "/cygdrive/c/Users/<username>/Desktop"
to .bashrc file located in <cygwin install directory>/home/<username>. This will change working directory to desktop every time you open Cygwin terminal.

Run build script in Code::Blocks instead of building a target

Background:
I recently joined a software development company as an intern and am getting used to a new build system. The software is for an embedded system, and lets just say that all building and compiling is done on a buildbox. The building makes use of code generation using xml files, and then makes use of make files, spec files, and version files as well.
We develop on our own comps, (linux - mandriva distro) and build using the following methods:
ssh buildserver
use mount to mount drive on personal computer to the buildserver
set the environment using . ./set_env (may not be exactly that)
cd app_dir/obj (where makefile is)
make spec_clean
make spec_all
make clean
make
The Question:
I am a newbie to Code::Blocks and linux and was wondering how to set up a project file so that it can simply run a script file to execute these commands, instead of actually invoking the build process on my actual computer. Sort of like a pre-build script. I want to pair the execution of this script simply to Ctrl-F9 (build) and capture any output from the above commands in the build log window.
In other words, there is no build configuration or target that the project needs to worry about. I don't even need a compiler installed on my computer! I wish to set this up so that I can have the full features of an IDE.
Appreciate any suggestions!
put your script in a shell script file. E.g.,
#!/bin/sh
mount ... /mnt/path/buildserver
. ./set_env
cd app_dir/obj
make spec_clean
make spec_all
make clean
make
Say you name it as /path/to/my_build_script, then chmod 755 /path/to/my_build_script and invoke the following from your ssh client machine:
script -c ssh buildserver "path/to/my_build_script"
When finish, then check for the file typescript under current directory.
HTH

Configuring PATH globally for SSH remote commands

I have a problem with the PATH variable on Debian Linux when executing commands via SSH. This happens for example when I use GIT or Mercurial and I have them installed in /opt instead of /usr/local. But I can also reproduce this easily like this:
When I login to the server via SSH in a normal way and then do echo $PATH then I get the PATH which I have configured in /etc/profile:
/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/maven/bin:/opt/ant/bin:/opt/mercurial/bin:/opt/git/bin
But when I do ssh user#server 'echo $PATH' instead then I get this:
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
The same happens when I use GIT or Mercurial with an ssh URL. It can't find hg or git executable on the server because it don't get the PATH from /etc/profile.
So the question is: Is there a "more global" way to configure the PATH so it also works with SSH remote execution? Configuring the PATH per user is not an option. Specifying the full path to git/hg executables when using git/hg on the client is also not an option. And I know that I could use symlinks or wrapper scripts in /usr/local/bin to get it working but I'm searching explicitly for a possibility to have a correct PATH when executing commands remotely via SSH.
On Debian, the standard environment is setup through pam_env (in /etc/pam.d/sshd), which will read /etc/environment and /etc/security/pam_env.conf. You can either edit those, or you add another pam_env line to the pam configuration, pointing to an environment file specific to SSH logins.
While not an answer to your problem, from this link, it looks like ssh has a path settings of its own.
The ssh server set some environment variables at the start of the session. You can create a ~/.ssh/environment file on the ssh server to set additional variables (assuming there is a BSD openssh server on the server), but the server must be configured to allow to change the environment.
If the above doesn't work, you can set the remote command. In mercurial this is the --remotecmd switch for push and pull.
I solved this issue by including all necessary files to the .bashrc
For instance:
. /etc/profile.d/rvm.sh
. /etc/profile.d/bash_completion.sh

Accessing a cygwin symlink from windows

I am quite new to cygwin. I created a symlink as follows
$ ln -s /var/www /cygdrive/d/foo
and when I check the D drive via windows, I see a system file called foo. Is there a way to make foo act as a folder for Windows instead of a system file?
Windows won't be able to read Cygwin-created symlinks, but you can create Windows symlinks using Windows commands, and Cygwin will treat those as symlinks.
On Vista and 7, this can be done with 'mklink'. This is a cmd.exe builtin rather than a standalone utility, so if you want to invoke it from a bash shell you have to do 'cmd /c mklink', and of course it will only understand Windows paths.
For XP, the 'Windows Resource Kit Tools' contain a utility called linkd that can be used to create directory links.
Not that I know of. Cygwin doesn't update the OS to have symlinks, rather, it allows you to 'fake' symlinks from within the Cygwin shell. You can set up the shell to use Windows LNK files, which may do what you want, but ...
From the Cygwin Documentation:
Creating shortcuts with cygutils
Another problem area is between
Unix-style links, which link one file
to another, and Microsoft .lnk files,
which provide a shortcut to a file.
They seem similar at first glance but,
in reality, are fairly different. By
default, Cygwin does not create
symlinks as .lnk files, but there's an
option to do that, see the section
called “The CYGWIN environment
variable”. These symlink .lnk files
are compatible with Windows-created
.lnk files, but they are still
different. They do not include much of
the information that is available in a
standard Microsoft shortcut, such as
the working directory, an icon, etc.
The cygutils package includes a
mkshortcut utility for creating
standard native Microsoft .lnk files.
But here's the problem. If Cygwin
handled these native shortcuts like
any other symlink, you could not
archive Microsoft .lnk files into tar
archives and keep all the information
in them. After unpacking, these
shortcuts would have lost all the
extra information and would be no
different than standard Cygwin
symlinks. Therefore these two types of
links are treated differently.
Unfortunately, this means that the
usual Unix way of creating and using
symlinks does not work with native
Windows shortcuts.
One alternative way to call mklink (/d creates directory link) without function:
link_name="/cygdrive/c/TestLink"
target_dir="/cygwin/c/Windows"
cmd /c mklink /d "`cygpath -w \"$link_name\"`" "`cygpath -w \"$target_dir\"`"
This example uses backticks (`command`) for command substitution.

Resources