- 
      
- 
        Save allex/517f8cc6038b8e20a49f94324cea1db6 to your computer and use it in GitHub Desktop. 
    Quote a single- or multi-line string for use in git's aliases
  
        
  
    
      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
    
  
  
    
  | #!/bin/bash -eu | |
| # Quote a single- or multi-line string for use in git's aliases | |
| # Copyright (c) 2016 Tom Hale under https://en.wikipedia.org/wiki/MIT_License | |
| quote() { | |
| printf %s "$1" | sed -r 's/(["\\])/\\\1/g'; | |
| } | |
| IFS=$(printf '\n') | |
| printf '\n!"' | |
| read -r previous | |
| while read -r line; do | |
| quote "$previous" | |
| printf ' \\n\\\n' | |
| previous="$line" | |
| done | |
| quote "$previous" | |
| printf " #\"\n"; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment