From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12767 invoked by alias); 9 Sep 2014 09:15:37 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 12749 invoked by uid 89); 9 Sep 2014 09:15:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_BL_SPAMCOP_NET,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-in-06.arcor-online.net Received: from mail-in-06.arcor-online.net (HELO mail-in-06.arcor-online.net) (151.189.21.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Tue, 09 Sep 2014 09:15:34 +0000 Received: from mail-in-19-z2.arcor-online.net (mail-in-19-z2.arcor-online.net [151.189.8.36]) by mx.arcor.de (Postfix) with ESMTP id A5FBF10C27C for ; Tue, 9 Sep 2014 11:15:30 +0200 (CEST) Received: from mail-in-14.arcor-online.net (mail-in-14.arcor-online.net [151.189.21.54]) by mail-in-19-z2.arcor-online.net (Postfix) with ESMTP id 970B73F8400 for ; Tue, 9 Sep 2014 11:15:30 +0200 (CEST) X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-14.arcor-online.net 728E69BE21 Received: from Rainer.invalid (pD9EB301E.dip0.t-ipconnect.de [217.235.48.30]) (Authenticated sender: stromeko@arcor.de) by mail-in-14.arcor-online.net (Postfix) with ESMTPSA id 728E69BE21 for ; Tue, 9 Sep 2014 11:15:30 +0200 (CEST) From: Achim Gratz To: cygwin@cygwin.com Subject: Re: latest cygwin: 'run' problem References: <54060378.2070108@gmail.com> <5406680D.4030105@verizon.net> <540761FA.1040902@verizon.net> <87ppfcqyc7.fsf@Rainer.invalid> <540A600A.6090201@verizon.net> <540A6817.9080207@verizon.net> <20140906201229.GA9220@phoenix> <20140908174606.GA4187@phoenix> <1448944831.20140909024857@yandex.ru> <20140909011413.GC4187@phoenix> <20140909030238.GD4187@phoenix> Date: Tue, 09 Sep 2014 09:15:00 -0000 In-Reply-To: <20140909030238.GD4187@phoenix> (Gary Johnson's message of "Mon, 8 Sep 2014 20:02:38 -0700") Message-ID: <87oaup6tpk.fsf@Rainer.invalid> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.93 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2014-09/txt/msg00154.txt.bz2 Gary Johnson writes: > After much fiddling (programming by successive approximation), You should drop the cargo-cult programming before it hurts you. > I came up with this: > > @START "" "C:\cygwin\bin\mintty.exe" /bin/bash --login -c "cd $(cygpath -u $0); exec bash -i" "%~p1\" You want at least %~dp1 there (in an CMD window, type HELP CALL). But you can start mintty directly from the shortcut without any intervention of START or run and you don't need a batch file or shell script either. Things get a lot simpler if you cut out the intermediaries, although you still need to be careful. If you go through CMD or a shell script, there are more levels of quoting involved and more processes to start. Doing this through both a CMD and a shell script is seriously overcomplicated and keeping track of what needs to go where is much more difficult to figure out, so just don't do it. > Using an explicit path to mintty lets me put the script itself > someplace other than /bin. > > Because %~p1 ends with a backslash, I had to add another backslash > before the closing quote to prevent the quote from being included in > the path. (See http://ss64.com/nt/syntax-args.html and > http://ss64.com/nt/syntax-esc.html#escape.) > > I haven't tried it yet with a path that includes a space. Tomorrow. It won't work because you did not quote the result from cygpath. If you want to get this right, you should work it out from the inside. You want the cd command to get a directory name from a subcommand that may contain spaces, so you need to quote the result: cd "$( ... )" Since the argument you're getting may actually be a filename, you need to use the dirname command and quote its argument again: cd "$(/bin/dirname "$(...)")" and dirname gets its argument from cygpath, and the argument to cygpath must itself be quoted again: cd "$("$(/bin/dirname "$(/bin/cygpath -u "$1")")")" If that suceeds you want to replace the current interpreter with an interactive bash: cd "$("$(/bin/dirname "$(/bin/cygpath -u "$1")")")" && exec /bin/bash -i That is in entirety the command that you need to give to the "-c" option of the outer bash invocation as a single argument. The remaining arguments are filled in from $0 and since I specified $1 to cygpath, there's a dummy parameter to be placed, let's call it "BashHere". So that outer bash needs to get started like this: /bin/bash -lc cmd_argument BashHere dir_argument Since you're actually starting it from a shortcut, you need to keep in mind that the quoting rules for the shortcut target are those of the MS CRT, which means you need to wrap single arguments containing whitespace in double quotes and then backslash escape any double quotes (and backslashes, of which we don't have any) inside those arguments. This will then be put into argv from mintty, which will exec bash with those arguments it didn't consume itself, which means there needs to be no extra level of quoting. So that shortcut target becomes (undo the linewrap): C:\Freeware\Cygwin\bin\mintty.exe -e "cd \"$(\"$(/bin/dirname \"$(/bin/cygpath -u \"$1\")\")\")\" && exec /bin/bash -i" BashHere The dir_argument gets filled in as the last argument by the drag&drop or SendTo operation. Regards, Achim. -- +<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+ Factory and User Sound Singles for Waldorf Blofeld: http://Synth.Stromeko.net/Downloads.html#WaldorfSounds -- 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