Fixing up windows pathnames to use in cygwin
I use emacs within Cygwin, and often I want to paste a pathname from an explorer window into emacs and use it there. Unfortunately you have to edit it by hand before it will work.
So for example a path like:
c:\code\haskell\cats\monkeys
Needs to be converted to:
/cygdrive/c/code/haskell/cats/monkeys
The following interactive elisp function does that with the currently selected text:
Nothing much clever going on here, just two search and replaces for the slashes and to removed the colon, and I insert the cygdrive prefix.
So for example a path like:
c:\code\haskell\cats\monkeys
Needs to be converted to:
/cygdrive/c/code/haskell/cats/monkeys
The following interactive elisp function does that with the currently selected text:
(defun win32-to-cygwin-path()
"Converts a win32 path into a cygwin happy one"
(interactive)
(save-excursion
(save-restriction
(narrow-to-region (point) (mark))
(goto-char (point-min))
(insert "/cygdrive/")
(goto-char (point-min))
(while (search-forward ":" nil t)
(replace-match "" nil t))
(while (search-forward "\\" nil t)
(replace-match "/" nil t)))))
Nothing much clever going on here, just two search and replaces for the slashes and to removed the colon, and I insert the cygdrive prefix.