Skip to content

Instantly share code, notes, and snippets.

@seantunwin
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save seantunwin/81127112ccee9dfe7675 to your computer and use it in GitHub Desktop.

Select an option

Save seantunwin/81127112ccee9dfe7675 to your computer and use it in GitHub Desktop.
When using Nodejs with Cygwin it is sometimes helpful to convert DOS paths to linux with the Cygwin prefix.
/**
* Convert slashes in DOS path strings to linux
* @use replace(/\\/g, '/')
*
* And
*
* Replace drive letter and colon with 'cygwin/' then the drive letter
* @use .replace(/^(\w):/i, 'cygwin/$1')
**/
var dir = process.cwd().replace(/\\/g, '/').replace(/^(\w):/i, 'cygwin/$1');
/* NOTE: If using in a script, (i.e. not CLI), it is possible to substitute 'process.cwd()'
* With '__dirname'
* Or
* If using 'require('path') then 'path.resolve() will also work
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment