Created
          August 26, 2014 11:15 
        
      - 
      
- 
        Save tanakahisateru/3b768a364021fe13ea71 to your computer and use it in GitHub Desktop. 
    Shell command escape by CoffeeScript
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # replacement of node-shell-quote | |
| # quote ['echo', '"Oh"', '>_<;'] # ==> echo '"Oh"' \>_\<\; | |
| quote = (xs)-> | |
| (for s in xs | |
| if /["\s]/.test(s) and !/'/.test(s) | |
| "'" + s.replace(/(['\\])/g, '\\$1') + "'" | |
| else if /["'\s]/.test(s) | |
| '"' + s.replace(/(["\\$`(){}!#&*|])/g, '\\$1') + '"' | |
| else | |
| String(s).replace(/([\\$`(){}!#&*|<>;])/g, '\\$1') | |
| ).join ' ' | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment