Alec the Geek

Reflections on software and related things from an older geek

  • Twitter Ramplings

  • My Bookmarks

  • RSS Alec’s GitHub

    • An error has occurred; the feed is probably down. Try again later.

Archive for the ‘Cygwin’ Category

Handy hack: Make changes to the Cygwin mount prefix permanent

Posted by Alec The Geek on 13 January 2010

If you’re like me then the one of the first things you do after installing Cygwin is to issue the command mount -c / so that mounts appear directly under / instead of /cygdrive. However the recent upgrade to Cygwin DLL means that this change is no longer persistent. In order to make it permanent you need to edit the file /etc/fstab and add a line

none /  cygdrive binary,posix=0,user 0 0

Further details on the Cygwin site

Posted in Cygwin | 5 Comments »

Top Tip: Windows Perl CPAN slows to crawl using network drives

Posted by Alec The Geek on 8 January 2010

I noticed this when using Cygwin Perl, however I suspect the issue exists with any Perl distro on Windows.

The problem occurred when I had set the HOME environment variable to point to a network share. When I ran the CPAN utility it placed all the CPAN files on the network. As a result some modules would not install (I have no idea why) and it ran very very slowly.

The solution I adopted was to to move my home directory to the local PC drive which then made CPAN use the local drive as well.  Changing  cpan_home in  /usr/lib/perl5/5.10/CPAN/Config.pm would probably have been simpler, but I was happy to use the local disk for everything.

YMMV

Posted in Cygwin, Perl | Comments Off

Handy Hack: Scripts to run Saxon XSLT processor

Posted by Alec The Geek on 5 January 2010

To save people having to reinvent the wheel here are a) a Windows batch file and b) Cygwin shell script to run the Saxon XSLT processor

@echo off

rem Run Saxon

c:\Progra~1\java\jre6\bin\java.exe -jar c:\Progra~1\Saxon9.2\saxon9he.jar %*
#!/bin/sh

# Run Saxon

/Progra~1/java/jre6/bin/java.exe -jar c:\\Progra~1\\Saxon9.2\\saxon9he.jar "$@"
echo

On UNIX or Linux

#!/bin/sh

# Run Saxon

/usr/bin/java -jar /usr/local/saxonhe/saxon9he.jar "$@"

You’ll obvioulsy need to modify the paths to suite the locations where you have things installed

Posted in Cygwin, Windows | Comments Off

Easy Introduction to Git

Posted by Alec The Geek on 4 September 2009

I’ve just had an article published by Sitepoint that aims to introduce Git to people who may not have programming experience and are more comfortable using a GUI rather the command Line. “Git: Your New Best Friend

Posted in Cygwin, Git, Open Source Software, Software Development, Web, Windows, Work Practices | Comments Off

Top Tip: Upgrade Git on Cygwin

Posted by Alec The Geek on 21 January 2009

The current version of git installed with Cygwin (1.5.x) has at least one annoying bug so it’s worth building  the latest version (NB I have almost all of Cygwin installed – you may need to install additional development tools and libs):

  1. Download and unpack the source code. Pointer here
  2. Run ‘./configure –prefix=/usr/local’
  3. Run ‘make test’
  4. Ignore errors relating to not detecting unwritable repos
  5. run ‘make install’
  6. run ‘hash -r’
  7. Make sure it’s installed with ‘type git’ and ‘git –version’

Update March/09 — I found more detailed instructions

Posted in Cygwin, Git, LinkedIn, Open Source Software, Software Development | 2 Comments »

Handy Hack: Run vim for Windows under Cygwin

Posted by Alec The Geek on 9 October 2008

UPDATED 30/Jan/09. With apologies for any confusion, previous example was completely wrong

For reasons I cant quite remember running the Windows gvim.exe binary directly from bash can lead to problems parsing path names. So I created an function as follows:

function gvim() { (
unset a
for i in "$@"; do
    case $i in
        -*)a=" $i $a";;
         *) if [[ -f $i ]] ; then
  a=" $a $(cygpath --absolute --dos "$i" )"
     else
  touch "$i" &&
  a=" $a $(cygpath --absolute "$i" )" &&
  rm -f "$i"|| echo "failed"
     fi
    esac
done
/progra~1/vim/vim72/gvim.exe $a&)}

Posted in Cygwin, Work Practices | Comments Off

Top Tip: Installing Cygwin on Windows

Posted by Alec The Geek on 1 August 2008

If you are like me, a *nix user (sometimes) trapped in MS Windows land, then you’ll come to depend on the Cygwin utilities. Their use is pretty straight forward, but you can make life a little bit easier for yourself:

  • When installing Cygwin select the option for default UNIX / binary style line endings for files. When selecting DOS style text files I’ve had subsequent problems with Perl CPAN modules failing unit tests and bash failing to process login scripts
  • After the install issue a mount -c / command, this means that you can access drives without using the /cygdrive mount point (i.e. /c/Program\ Files instead of /cygdrive/c/Program\ Files)
  • NB This is not recommended practice, but for years I have been installing cygwin into the root of my C: drive, apparently without ill effects, and it does make life slightly easier. However you will need to modify startxwin.bat (and startxdmcp.bat if used) and make sure that the environment variable CYGWIN_ROOT is defined as an empty string.
  • Create a shortcut to invoke bash, I use “C:\bin\run.exe C:\bin\rxvt.exe -sl 2500 -fg lightblue -geometry 80x25 -bg midnightblue -sbt 10 -title bash -e /bin/xhere /bin/bash.exe %HOME%” (noting of course that I install into the root of the C: drive). You can also use chere to install a ‘Open Bash here’ option in Windows Explorer

Anyone else have anything to pass on?

Posted in Cygwin, Windows, Work Practices | 8 Comments »

Top Tip: Cygwin Perl has problems running with UNC path names

Posted by Alec The Geek on 10 July 2008

When running Cygwin Perl using libraries that live on UNC paths (e.g. when running prove with the -l option) Perl will croak because it is unable to load the library. An example error message will look something like:

t/00.load.............Can't open perl script ""-I//server/sharename/work/mymodule/lib"": No such file or directory

The fix is to map the UNC path to a drive letter and use the Cygwin mount point (e.g. ‘/cygdrive/z/work/mymodule’) as the path instead.

The command is

net use z: '\\server\sharename'

Posted in Cygwin, Perl | Comments Off

Handy Hack: How to configure the cpan utility to use Windows proxies

Posted by Alec The Geek on 29 May 2008

When using cpan.bat the following may be helpful. Please note that this is for a Windows corporate network infrastructure and was tested using both Strawberry and Cygwin Perl in the current network environment where I work. YMMV!

BEWARE THAT THIS APPROACH STORES YOUR LAN PASSWORD ON YOU LOCAL HARD DISK. THIS IS INSECURE!

Step 1: Information Gathering

  1. Discover the address of your proxy: If using a PAC file (look in IE Tools->Internet Options-> Connections -> LAN Settings and identify the setting ‘Use automatic configuration script’) then download the PAC file and open in a text editor. The default proxy address (e.g. proxy.corp) and port (e.g. 80) will probably be at the bottom of the PAC script. If you are not using a PAC script then the proxy address will be in the LAN Settings dialog.
  2. Know your domain name (e.g. corpdom) and lan ID (e.g. lanname)
  3. You will also need your lan password (e.g. secret)

Step 2: Configure CPAN

  1. From the command line ensure that you running the correct version of perl (perl –version)
  2. run the command cpan
  3. You may be asked some configuration questions — answer as best you can and take defaults if not sure
  4. At the CPAN Prompt type the following commands:
    1. o conf proxy_user corpdom\\lanname (NB Double slash required)
    2. o conf proxy_pass secret
    3. o conf ftp_proxy http://proxy.corp:80 (NB No trailling slash on URL)
    4. o conf http_proxy http://proxy.corp:80 (NB No trailling slash on URL)
  5. Now try and install something (e.g. i Bundle::Perl::Critic)

[Update: July 2008 -- tested on Strawberry and Cygwin Perl. See also]

Posted in Cygwin, Perl | Comments Off

Handy Hack: Can’t run perldoc on Cygwin

Posted by Alec The Geek on 28 May 2008

When running perldoc on certain Windows systems using Perl under Cygwin it is possible to get an error message

Error in tempfile() using ./XXXXXXXXXX: Parent directory (./) is not writable

This is more likely to happen if your system has been ‘hardned’ by a corporate IT department. The fix is as follows:

  1. Make sure $TMPDIR is defined and points to somewhere sensible (e.g. $TMP)
  2. Make sure you have read/write permissions (chmod 777 $TMPDIR)

Posted in Cygwin, Perl, Windows | Comments Off

emacs Tramp on Windows

Posted by Alec The Geek on 15 May 2008

Updated Oct/08

I am using emacs with the tramp extension to edit files on a remote server using ssh. I had to pull in various hacks to get it to work so I hope these notes might help others.

  1. Install Emacs for Windows and Cygwin with OpenSSH
  2. Upgrade emacs Tramp to the latest version. This is best done using Cygwin bash and Cygwin make (in particular ensure that –with-lispdir and –infodir options are set correctly when running configure).
    • Handy tip — leave the tramp build directory hanging around. When you next upgrade Emacs it’s just make install (providing you use same directory names)
  3. Ensure that the Cygwin bin directory is on the Windows system path
  4. At the Cygwin bash prompt test ssh connection to your host
  5. Generate public/private keys and upload to the host
  6. Test ssh again to see if public authentication works (it did not for me because it had been disabled by the UNIX admin)
  7. Configure emacs to use tramp
    (require 'tramp)
    ;;(setq tramp-debug-buffer t)
    ;;(setq tramp-verbose 10)
    (setq tramp-auto-save-directory "c:\\tmp")
    (setq tramp-default-method "plink")
  8. Start emacs and test connection (C-x C-f) using cygwin ssh/scp/sftp. If it works skip to step 14. I had issues so I continued with step 9
  9. Install the Putty program suite
  10. Test the connection using putty
  11. Ensure the Putty install directory is on the system PATH
  12. In emacs visit the host (C-x C-f) using the method ‘plink’. If that does not work you are on your own (but see troubleshooting below)
  13. If the public keys worked in ssh then import your OpenSSH keys into Putty
  14. Use emacs bookmarks to save your common host locations

Troubleshooting:

  1. Getting rid of the “Couldn’t find exit status of `test -e …” error message by deleting ~/emacs.d/tramp file. This clears cached settings as documented at http://www.nabble.com/Emacs-tramp-troubles-with-old-Sun-tt13607411.html.
  2. If Tramp and Emacs does not work for you try these alternatives:
    1. Vim has a netrw plugin
    2. Both FileZilla and WinSCP have options to edit a file from the remote file system which then invokes a local Windows editor of your choice.
    3. jEdit has an ftp plugin that supports sftp and bookmarks

YMMV

With many thanks to all the folks on the web who documented their experiences and Michael Albinus on the tramp-devl mailing list.

Posted in Cygwin, LinkedIn, Open Source Software, Security, Software Development, Windows, Work Practices | 1 Comment »

Windows Explorer ‘Open Bash Here’

Posted by Alec The Geek on 19 October 2006

Updated May 2008

As mentioned by Andrew below this is all too hard now that we have the chere utility. At the cygwin shell prompt try the following

chere -i -c -n -t rxvt -s bash -o "-sl 2500 -fg lightblue -geometry 80x25 -bg midnightblue -sbt 10 -title bash" -e "Open Bash shell here"

If you want a shortcut to run bash for your home directory try

C:\bin\run.exe C:\bin\rxvt.exe -sl 2500 -fg lightblue -geometry 80x25 -bg midnightblue -sbt 10 -title bash -e /bin/xhere /bin/bash.exe %HOME%

——————————————————————————-
For users of Cygwin on Windows who like the Open Command Window Here power toy

I took this hack and this hack and combined them to make the following hack. It works on both directories and drives in Windows Explorer, and creates a visually attractive login shell (at least I think so).

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\bash]

@="Open Bash Shell Here"

[HKEY_CLASSES_ROOT\Directory\shell\bash\command]

@="c:\\\\bin\\\\bash.exe --login -i -c 'cd \"`cygpath \"$*\"`\";exec rxvt -sr -sl 2500 -fg lightblue --geometry 80x25 -bg midnightblue -sb -e bash' bash %L"

[HKEY_CLASSES_ROOT\Drive\shell\bash]

@="Open Bash Shell Here"

[HKEY_CLASSES_ROOT\Drive\shell\bash\command]

@="c:\\\\bin\\\\bash.exe --login -i -c 'cd \"`cygpath \"$*\"`\";exec rxvt -sr -sl 2500 -fg lightblue --geometry 80x25 -bg midnightblue -sb -e bash' bash %L"

Posted in Cygwin, LinkedIn, Work Practices | 9 Comments »

 
Follow

Get every new post delivered to your Inbox.

Join 272 other followers

%d bloggers like this: