Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining aliases in Cygwin under Windows

Tags:

cygwin

I am trying to define some aliases in cygwin, but with no success. I am doing so like this at the end of the .bashrc file.

alias foo='pwd'

I have tried to add this line in a .bashrc file in both inside the home folder of cygwin and in the home folder for the Windows user I am on C:\Users\Nuno\. In both cases I have just appended this line to a copy of the /etc/skel/.bashrc file. In either cases, it didn't work.

I had this working before. I had to reinstall Cygwin and ever since it never worked properly again. I have removed all files (or at least think so, when doing the reinstallation). I have also noticed that in the first install (when it was working) cygwin already was creating .bash files in the home folder. Now, it doesn't.

I am on a machine running Windows 7.

EDIT: My cygwin home folder is set to the Windows home folder C:\Users\Nuno\. I have placed what I think is a valid .bashrc file there, but it still doesn't work.

Thanks in advance.

like image 606
nunos Avatar asked Mar 26 '13 15:03

nunos


People also ask

How do I add a PATH in Cygwin?

From the Start menu, select Parameters > Control Panel > System. Select the Advanced tab and click Environment variables. Edit the PATH environment variable to add the Cygwin installation directory, for example c:\cygwin\bin; and click OK.

How do I add a user to my home directory in Cygwin?

Click Start > Settings > Control Panel > User Accounts. Make each user a member of the Administrators group. Complete this step for each user that you want to add before you create the corresponding Cygwin accounts. Make a backup copy of the /etc/passwd file.


2 Answers

As me_and already explained what's going on I just want to add a workaround should you for whatever reason not be able or willing to remove Windows' HOME environment variable.

Normally the shortcut for Cygwin executes

C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -

Instead you can create a batchfile with the following content and start that:

@echo off
set HOME=
start C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -

That will start a a Cygwin windows whose home directory settings are not overridden by a Windows environment variable.

like image 115
fvu Avatar answered Oct 09 '22 05:10

fvu


Your .bashrc file will be loaded from wherever Cygwin Bash thinks your home directory is when it starts. You've mentioned in your edit that you've changed your home directory, but not how, so it's possible you've made a mistake there.

Cygwin will load your home directory from one of two places, and if they differ it can cause problems:

  • The HOME environment variable. This will be picked up from however you launch Cygwin, so normally from Windows itself. You can see what environment variables you have defined by pressing Win+Pause, going to "Advanced system settings", "Environment Variables…". If "HOME" is in either "User variables" or "System variables", delete it – it's unnecessary and only causes problems.

  • Cygwin's /etc/passwd file (normally C:\Cygwin\etc\passwd from Windows). This will have a number of lines containing details of each user on the system; the seventh : separated field is the home directory. You can tell which user it's looking at by running whoami from a Cygwin bash shell.

If whoami reports nunos, you should have a line in Cygwin's /etc/passwd that looks something like the following:

nunos:unused:1001:513:U-System\nunos:S-1-2-34-567890-123456-7890123-1001:/home/nunos:/bin/bash

It's that /home/nunos that's important; if it's something different you should probably reset it to that, at which point you want to use the .bashrc in Cygwin's /home/nunos/.

You should also be very wary of directories that contain spaces for this. C:\Users\nunos should be fine, but beware in particular C:\Documents and Settings\nunos, which just won't work with Cygwin.

like image 29
me_and Avatar answered Oct 09 '22 05:10

me_and