[PATCH] /etc/profile: strip out cygwin paths from PATH

28 views
Skip to first unread message

Tay Ray Chuan

unread,
Dec 25, 2010, 6:16:03 AM12/25/10
to msysGit Mailinglist, Sebastian Schuberth, Pat Thoyts
This is useful for users on both msys/mingw and cygwin, as it prevents
cygwin executables/libraries from "contaminating" operations on
msys/mingw, like compilation and execution.

Signed-off-by: Tay Ray Chuan <rct...@gmail.com>
---
etc/profile | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/etc/profile b/etc/profile
index 8026e74..6da0224 100644
--- a/etc/profile
+++ b/etc/profile
@@ -21,6 +21,13 @@ else
export PATH=".:/usr/local/bin:/bin:/mingw/bin:$PATH"
fi

+# strip out cygwin paths from PATH
+PATH="$(echo -n $PATH | awk '
+ BEGIN { RS=":"; output="" }
+ !/cygwin/ { output = (output == "") ? $0 : output":"$0 }
+ END { print output }
+')"
+
# check msys-1.0.dll
if test -f /etc/msys-1.0.dll.md5
then
--
1.7.3.2.msysgit.0

Sebastian Schuberth

unread,
Dec 25, 2010, 6:55:53 AM12/25/10
to Tay Ray Chuan, msysGit Mailinglist, Pat Thoyts
On Sat, Dec 25, 2010 at 12:16, Tay Ray Chuan <rct...@gmail.com> wrote:

> This is useful for users on both msys/mingw and cygwin, as it prevents
> cygwin executables/libraries from "contaminating" operations on
> msys/mingw, like compilation and execution.

> +# strip out cygwin paths from PATH


> +PATH="$(echo -n $PATH | awk '
> +       BEGIN { RS=":"; output="" }
> +       !/cygwin/ { output = (output == "") ? $0 : output":"$0 }
> +       END { print output }
> +')"
> +

I haven't tested these, but I find the one-liners at [1] to be more
elegant, e.g.

PATH$(awk -vRS=: -vORS=: '!/cygwin/' <<<$PATH)

[1] http://stackoverflow.com/questions/370047/what-is-the-most-elegant-way-to-remove-a-path-from-the-path-variable-in-bash

--
Sebastian Schuberth

Johannes Schindelin

unread,
Dec 25, 2010, 7:00:47 AM12/25/10
to Tay Ray Chuan, msysGit Mailinglist, Sebastian Schuberth, Pat Thoyts
Hi,

On Sat, 25 Dec 2010, Tay Ray Chuan wrote:

> This is useful for users on both msys/mingw and cygwin, as it prevents
> cygwin executables/libraries from "contaminating" operations on
> msys/mingw, like compilation and execution.

Good idea!

> +# strip out cygwin paths from PATH
> +PATH="$(echo -n $PATH | awk '
> + BEGIN { RS=":"; output="" }
> + !/cygwin/ { output = (output == "") ? $0 : output":"$0 }
> + END { print output }
> +')"
> +

Would

PATH="$(echo "$PATH" |
sed -e 's|[^:]*/cygwin/[^:]*:||g' \
-e 's|:[^:]*/cygwin/[^:]*||')"

also do the job? It's a bit shorter, but I do not care that much.

However, I would like to wrap this into a "case" statement so that another
process is only spawned if necessary (process spawning is super-expensive
on Windows).

Hmm?

Ciao,
Dscho

Johannes Schindelin

unread,
Dec 25, 2010, 7:10:04 AM12/25/10
to Sebastian Schuberth, Tay Ray Chuan, msysGit Mailinglist, Pat Thoyts
From: Tay Ray Chuan <rct...@gmail.com>

This is useful for users on both msys/mingw and cygwin, as it prevents
cygwin executables/libraries from "contaminating" operations on
msys/mingw, like compilation and execution.

[Sebastian suggested a much shorter invocation as per
http://stackoverflow.com/questions/370047/, and to avoid unnecessary
spawning, it is wrapped in a case...esac construct]

Signed-off-by: Tay Ray Chuan <rct...@gmail.com>

Signed-off-by: Johannes Schindelin <johannes....@gmx.de>
---

You can also find this patch here:

http://repo.or.cz/w/msysgit.git/commit/f141adec90fb7e2186ab83eef101bff84052a62b

Can you please test whether it still works as expected?

Merry Christmas,
Dscho

etc/profile | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/etc/profile b/etc/profile
index e8331a5..0750814 100644


--- a/etc/profile
+++ b/etc/profile
@@ -21,6 +21,13 @@ else
export PATH=".:/usr/local/bin:/bin:/mingw/bin:$PATH"
fi

+# strip out cygwin paths from PATH

+case "$PATH" in
+*/cygwin/*)
+ export PATH$(awk -vRS=: -vORS=: '!/SDE/' <<<$PATH)
+ ;;
+esac


+
# check msys-1.0.dll
if test -f /etc/msys-1.0.dll.md5
then
--

1.7.3.4.3624.g2f68

Sebastian Schuberth

unread,
Dec 25, 2010, 7:13:17 AM12/25/10
to Johannes Schindelin, Tay Ray Chuan, msysGit Mailinglist, Pat Thoyts
On Sat, Dec 25, 2010 at 13:10, Johannes Schindelin
<Johannes....@gmx.de> wrote:

> +# strip out cygwin paths from PATH
> +case "$PATH" in
> +*/cygwin/*)
> +       export PATH$(awk -vRS=: -vORS=: '!/SDE/' <<<$PATH)
> +       ;;
> +esac
> +

Dscho, I believe there's a copy and paste error: "SDE" needs to be
replaced with "cygwin" above.

--
Sebastian Schuberth

Johannes Schindelin

unread,
Dec 25, 2010, 7:13:29 AM12/25/10
to Sebastian Schuberth, Tay Ray Chuan, msysGit Mailinglist, Pat Thoyts
Hi,

On Sat, 25 Dec 2010, Johannes Schindelin wrote:

> +# strip out cygwin paths from PATH
> +case "$PATH" in
> +*/cygwin/*)
> + export PATH$(awk -vRS=: -vORS=: '!/SDE/' <<<$PATH)

Whoa. I really should learn to read. Please find the fixed patch here:

http://repo.or.cz/w/msysgit.git/commitdiff/b235c1ccdb1a62ddabacdf960c9137a65cbdd4e9

Ciao,
Dscho

Sebastian Schuberth

unread,
Dec 25, 2010, 7:24:45 AM12/25/10
to Johannes Schindelin, Tay Ray Chuan, msysGit Mailinglist, Pat Thoyts
On Sat, Dec 25, 2010 at 13:13, Johannes Schindelin
<Johannes....@gmx.de> wrote:

>> +# strip out cygwin paths from PATH
>> +case "$PATH" in
>> +*/cygwin/*)
>> +     export PATH$(awk -vRS=: -vORS=: '!/SDE/' <<<$PATH)
>
> Whoa. I really should learn to read. Please find the fixed patch here:
>
> http://repo.or.cz/w/msysgit.git/commitdiff/b235c1ccdb1a62ddabacdf960c9137a65cbdd4e9

Turns out this does not work all to well for me. First of all, it is
missing an "=" between "PATH" and "$", but even then, it appends a
space and a ":" after the last path.

--
Sebastian Schuberth

Tay Ray Chuan

unread,
Dec 25, 2010, 7:29:17 AM12/25/10
to Sebastian Schuberth, Johannes Schindelin, msysGit Mailinglist, Pat Thoyts

Back to echo -n ?

export PATH=$(echo -n $PATH | awk -vRS=: -vORS=: '!/cygwin/')

--
Cheers,
Ray Chuan

Sebastian Schuberth

unread,
Dec 25, 2010, 7:35:03 AM12/25/10
to Tay Ray Chuan, Johannes Schindelin, msysGit Mailinglist, Pat Thoyts
On Sat, Dec 25, 2010 at 13:29, Tay Ray Chuan <rct...@gmail.com> wrote:

>> Turns out this does not work all to well for me. First of all, it is
>> missing an "=" between "PATH" and "$", but even then, it appends a
>> space and a ":" after the last path.
>
> Back to echo -n ?
>
>  export PATH=$(echo -n $PATH | awk -vRS=: -vORS=: '!/cygwin/')

Yes, that seems to work fine for me. It still appends a trailing ":",
but that does not do any harm.

Dscho, could you please update your path accordingly? Thanks!

--
Sebastian Schuberth

Johannes Schindelin

unread,
Dec 25, 2010, 8:35:14 AM12/25/10
to Sebastian Schuberth, Tay Ray Chuan, msysGit Mailinglist, Pat Thoyts
Hi,

Oops. The trailing separator comes from awk, even with "echo -n". I fixed
it by using the ${...%...} operator, pushed out to 'devel' and deleted the
topic branch.

Thank you, Tay Ray & Sebastian!

Ciao,
Dscho

Tay Ray Chuan

unread,
Dec 25, 2010, 9:15:06 AM12/25/10
to Johannes Schindelin, Sebastian Schuberth, msysGit Mailinglist, Pat Thoyts
On Sat, Dec 25, 2010 at 9:35 PM, Johannes Schindelin
<Johannes....@gmx.de> wrote:
> Oops. The trailing separator comes from awk, even with "echo -n". I fixed
> it by using the ${...%...} operator, pushed out to 'devel' and deleted the
> topic branch.

I thought of piping through

sed 's/:$//'

but the shell expansion was much neater. I never stop being amazed at
what bash can do.

> Thank you, Tay Ray & Sebastian!

You're most welcome!

--
Cheers,
Ray Chuan

Reply all
Reply to author
Forward
0 new messages