Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # synopsis: bashfill FILE ... [-- TEMPLATEOPTIONS ... ]
- function include() {
- lastline=$(tail -n 1 $1; echo x);
- lastline=${lastline%x};
- sanitize='';
- [[ "${lastline: -1}" != $'\n' ]] && sanitize=$'\n';
- read; [[ "$REPLY" =~ ^'#!' ]] || {
- cat <(echo "$REPLY") - <(echo -n "$sanitize");
- } && cat - <(echo -n "$sanitize");
- }
- declare -a BASHFILL;
- while [[ $1 != '--' ]] && [[ $# -gt 0 ]]; do
- BASHFILL[index++]=$1; shift;
- done
- [[ $1 == '--' ]] && shift;
- source <(echo 'cat <<ENDOFASSEMBLY';
- for (( order=0; order != index; ++order )); do
- [[ -e "${BASHFILL[order]}" ]] && {
- include "${BASHFILL[order]}" < "${BASHFILL[order]}";
- } || { [[ -n "${BASHFILL[order]}" ]] &&
- echo ${BASHFILL[0]}: error: unable to include $(pwd)/${BASHFILL[order]} >&2;
- }; done; echo 'ENDOFASSEMBLY');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement