Skip to content

Instantly share code, notes, and snippets.

@HaleTom
Created October 1, 2016 03:21
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Quote a single- or multi-line string for use in git's aliases
#!/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