profile function to run CR-LF line ended script with mksh, e.g. on Cygwin
authorThorsten Glaser <tg@mirbsd.org>
Sat, 31 Dec 2011 20:04:41 +0000 (20:04 +0000)
committerThorsten Glaser <tg@mirbsd.org>
Sat, 31 Dec 2011 20:04:41 +0000 (20:04 +0000)
Message-ID: <Pine.BSM.4.64L.1112311952120.14351@herc.mirbsd.org>

posix/profile-cygwin [new file with mode: 0644]

diff --git a/posix/profile-cygwin b/posix/profile-cygwin
new file mode 100644 (file)
index 0000000..0bdb3cb
--- /dev/null
@@ -0,0 +1,20 @@
+# put this into ~/.profile on Cygwin to run a CR-LF line ended script with mksh
+
+mkshdos_re=$(printf 's/\r$//')
+mkshdos() {
+       if test -n "$1"; then
+               mkshdos_fn=$1
+               shift
+       else
+               mkshdos_fn=-
+       fi
+       mkshdos_T=$(mktemp /tmp/mkshdos.XXXXXXXXXX) || {
+               echo >&2 mkshdos: Error: Could not create temporary file.
+               return 255
+       }
+       sed "$mkshdos_re" <"$mkshdos_fn" >"$mkshdos_T"
+       mksh "$mkshdos_T" "$@"
+       mkshdos_rv=$?
+       rm -f "$mkshdos_T"
+       return $mkshdos_rv
+}