Skip to content

Instantly share code, notes, and snippets.

@lexrus
Forked from mikeash/auto-run.swift
Last active March 11, 2023 15:27
Show Gist options
  • Save lexrus/b2a86d4ae99e5509b3af to your computer and use it in GitHub Desktop.
Save lexrus/b2a86d4ae99e5509b3af to your computer and use it in GitHub Desktop.
把这个 swift 文件复制到 /usr/local/bin/ 下,chmod +x /usr/local/bin/auto-run.swift 。然后每次执行 auto-run.swift 都会检查是否需要重新编译,最后会执行编译后的 auto-run.swiftc。需要 Xcode 6.0+,亲测 bash 和 zsh 下可用,fish 下会报错。
/*/../usr/bin/true
source="$0"
compiled="$0"c
if [[ "$source" -nt "$compiled" ]]; then
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer xcrun swiftc -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -g "$source" -o "$compiled" || exit
fi
"$compiled"
exit
*/
println("👍")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment