www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/08/09/15:53:35

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00
X-Spam-Check-By: sourceware.org
Message-ID: <4C605CAC.4020205@bopp.net>
Date: Mon, 09 Aug 2010 14:53:16 -0500
From: Jeremy Bopp <jeremy AT bopp DOT net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Batch-style variables to detect change in Cygdrive
References: <4C5F7B79 DOT 60805 AT gmail DOT com>
In-Reply-To: <4C5F7B79.60805@gmail.com>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 8/8/2010 10:52 PM, Monte Cabet wrote:
> Is there anyway I can get batch-style relative drive paths in Cygwin? An
> example of what I mean is "%~d0". The reason for is is that I would like
> to mount folders from a USB, so the drive (the variable I showed does
> drive) will change everytime I plug the USB in. After abit of playing
> around I found how to mount folders, but it needs be ran from inside
> Cygwin via a file ran on start-up or written manually. I am attempting
> to set the mounts from a batch script or atleast get a variable/function
> that will find out what drive to use. Below is some examples I've cooked
> up.
> 
> # batch-style
> set "mono1=cygpath --type windows "%~d0\mono\""
> set "mono2=cygpath --type mixed "%~d0/mono/""
> set "mono3=cygpath --type unix "/cygdrive/%~d0/mono/""
> mount -o binary '%mono1%' /mnt
> 
> # Cygwin-style
> mount -o binary "$(cygpath --type windows "%~d0\mono\)" /mnt
> mount -o binary "$(cygpath --type mixed "%~d0/mono/)" /mnt
> mount -o binary "$(cygpath --type unix /cygdrive/%~d0/mono/)" /mnt

Assuming you'll only ever have a single drive with a directory named
mono in the root and assuming that your cygdrive prefix is /cygdrive,
you could simply do the following from within a Cygwin shell:

mount "$(cygpath -m /cygdrive/*/mono)" /mnt

The cygdrive prefix is trivial to change to suit your needs, but if you
have more than a single drive with a directory named mono in the root,
you'll have to get more creative to find a way to select the correct
one.  In any case, this will only remain until all your Cygwin processes
are stopped.


Another option is to create a shell script with the following content:

#!/bin/bash
mount "$(cygpath -m "$1")/mono" /mnt

Say you named the script /home/monte/bin/mount-usb.sh.  Create a
shortcut that starts in C:\cygwin\bin and has the following target:

C:\cygwin\bin\bash.exe /home/monte/bin/mount-usb.sh

Now you can drag the drive you find in your file browser for the USB
drive and drop that onto the shortcut to have it mounted within Cygwin.
 This solution assumes that you installed Cygwin into C:\cygwin.  Feel
free to change that to suit your needs.  It also assumes that you have
at least 1 Cygwin process already running so that the mount is preserved
once the script exits.

BTW, it would be a good idea to make the script more robust so that it
can cleanly handle being run more than once or run with a drive that
does not have the folder you wish to mount.

-Jeremy

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019