Skip to content

Instantly share code, notes, and snippets.

@mikeslattery
Last active July 24, 2020 18:52
Show Gist options
  • Save mikeslattery/9b618669b63fe9dc984d5924bbb3aaee to your computer and use it in GitHub Desktop.
Save mikeslattery/9b618669b63fe9dc984d5924bbb3aaee to your computer and use it in GitHub Desktop.
#!/bin/bash
# Workaround docker wrapper for git-bash/Msys/Cygwin quirks
# Copy this to ~/bin/docker or /usr/local/bin/docker
set -euo pipefail
export MSYS_NO_PATHCONV=1
export MSYS2_ARG_CONV_EXCL='*'
os="$(uname -o)"
realdocker="$(which -a docker | grep -v "$(readlink -f "$0")" | head -1)"
if [[ "$os" == "Msys" ]] || [[ "$os" == "Cygwin" ]]; then
printf "%s\0" "$@" > /tmp/args.txt
# --tty or -t requires winpty
if grep -ZE '^--tty|^-[^-].*t|^-t.*' /tmp/args.txt; then
exec winpty /bin/bash -c "xargs -0a /tmp/args.txt '$realdocker'"
fi
fi
exec "$realdocker" "$@"
@DrVanScott
Copy link

Isn't there a "return" missing after line 16?

@mikeslattery
Copy link
Author

@DrVanScott No. The exec builtin transfers control to another program (winpty).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment