Skip to content

Instantly share code, notes, and snippets.

@schwa
Created July 29, 2022 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schwa/abd5ae8e1e87aee02a14090ed0fb1ff4 to your computer and use it in GitHub Desktop.
Save schwa/abd5ae8e1e87aee02a14090ed0fb1ff4 to your computer and use it in GitHub Desktop.
CLI tool using gum (https://github.com/charmbracelet/gum) to streamline Swift Package creation…
#!/usr/bin/env fish
# brew tap charmbracelet/tap && brew install charmbracelet/tap/gum
function spm-init
gum style --foreground 11 "Package Type:"
set TYPE (gum choose "library" "executable" "empty" "system module" "manifest")
gum style --foreground 10 $TYPE
gum style --foreground 11 "Package Name:"
set NAME (gum input --placeholder "Package Name" --value "MyPackage")
gum style --foreground 10 $NAME
set DIRECTORY (pwd)
if gum confirm "Create new directory"
if test -e $NAME
gum style --foreground 9 "File already exists"
return -1
end
gum style --foreground 14 "Making directory"
mkdir $NAME
set DIRECTORY $NAME
end
pushd $DIRECTORY
gum spin --title "Installing package" -- swift package init --type $TYPE --name $NAME
if gum confirm "Initialize git"
gum style --foreground 14 "Initializing git"
git init --quiet .
git commit --quiet --allow-empty -m "Initial commit."
if gum confirm "Add default .gitignore"
gum style --foreground 14 "Fetching .gitignore"
gum spin --title "Fetching .gitignore" -- curl --silent -o .gitignore https://raw.githubusercontent.com/github/gitignore/main/Swift.gitignore
end
git add --all .
git commit --quiet -a -m "Initial swift package."
end
popd $DIRECTORY
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment