Skip to content

Instantly share code, notes, and snippets.

@lis186
Created February 5, 2024 06:51
Show Gist options
  • Select an option

  • Save lis186/b127af9fcb7f1a0d268b8fc256624954 to your computer and use it in GitHub Desktop.

Select an option

Save lis186/b127af9fcb7f1a0d268b8fc256624954 to your computer and use it in GitHub Desktop.
Automating pkl-gen-swift CLI Installation on Apple Silicon Macs with a Shell Script
# Determine the shell being used and set the config file path accordingly
if [ -n "$ZSH_VERSION" ]; then
CONFIG_FILE=~/.zshrc
elif [ -n "$BASH_VERSION" ]; then
CONFIG_FILE=~/.bash_profile
else
echo "Unsupported shell."
exit 1
fi
# Create the directory for local binaries if it doesn't exist
mkdir -p ~/.local/bin
# Download the pkl-gen-swift binary and set it as executable
curl -L https://github.com/apple/pkl-swift/releases/download/0.2.1/pkl-gen-swift-macos.bin -o ~/.local/bin/pkl-gen-swift
chmod +x ~/.local/bin/pkl-gen-swift
# Append the directory to PATH in the appropriate config file, if not already present
if ! grep -q 'export PATH="$HOME/.local/bin:$PATH"' $CONFIG_FILE; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> $CONFIG_FILE
echo "Updated $CONFIG_FILE with PATH settings."
else
echo "$CONFIG_FILE already contains the necessary PATH settings."
fi
# Reload the shell configuration
source $CONFIG_FILE
# Validate the installation by checking if pkl-gen-swift can be executed from anywhere
pkl-gen-swift --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment