-
-
Save roktas/e99592a6ea8730c0ad4e to your computer and use it in GitHub Desktop.
This file contains 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 | |
herestring() { | |
local lines lead start cur end | |
mapfile -t lines < <(echo "$1") | |
while [[ $start -lt ${#lines[@]} ]] && [[ ${lines[$start]} =~ ^[[:space:]]*$ ]]; do | |
((start++)) | |
done | |
end=$((${#lines[@]} - 1)) | |
while [[ $end -gt 0 ]] && [[ ${lines[$end]} =~ ^[[:space:]]*$ ]]; do | |
((end--)) | |
done | |
if [[ ${lines[$start]} =~ ^([[:space:]]+) ]]; then | |
lead=${BASH_REMATCH[1]} | |
fi | |
for ((cur = start; cur <= end; cur++)); do | |
echo "${lines[$cur]/$lead/}" | |
done | |
} | |
herestring ' | |
foo | |
bar | |
baz | |
quux | |
' | |
unexpand <<-EOF | |
# encoding: utf-8 | |
preload_app true | |
before_fork do |server, worker| | |
Signal.trap 'TERM' do | |
puts 'Unicorn master intercepting TERM and sending myself QUIT instead' | |
Process.kill 'QUIT', Process.pid | |
end | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment