From 1861b5f175dc8f6d6408772b707c9d6deb28a53f Mon Sep 17 00:00:00 2001 From: YR Chen Date: Fri, 29 Oct 2021 23:40:23 +0800 Subject: [PATCH] feat(xcode): support `Package.swift` as project file in `xc` (#10358) --- plugins/xcode/README.md | 2 +- plugins/xcode/xcode.plugin.zsh | 28 +++++++++------------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/plugins/xcode/README.md b/plugins/xcode/README.md index 37f882638..664a063a3 100644 --- a/plugins/xcode/README.md +++ b/plugins/xcode/README.md @@ -26,7 +26,7 @@ plugins=(... xcode) ### `xc` -Opens the current directory in Xcode as an Xcode project. This will open one of the `.xcworkspace` and `.xcodeproj` files that it can find in the current working directory. You can also specify a directory to look in for the Xcode files. +Opens the current directory in Xcode as an Xcode project or a Swift package. This will open one of the `.xcworkspace`, `.xcodeproj` and `Package.swift` files that it can find in the current working directory. You can also specify a directory to look in for the Xcode files. Returns 1 if it didn't find any relevant files. ### `xx` diff --git a/plugins/xcode/xcode.plugin.zsh b/plugins/xcode/xcode.plugin.zsh index 89703fe3c..41b9e37e4 100644 --- a/plugins/xcode/xcode.plugin.zsh +++ b/plugins/xcode/xcode.plugin.zsh @@ -6,28 +6,18 @@ alias xcsel='sudo xcode-select --switch' # original author: @subdigital # source: https://gist.github.com/subdigital/5420709 function xc { - local xcode_proj - if [[ $# == 0 ]]; then - xcode_proj=(*.{xcworkspace,xcodeproj}(N)) - else - xcode_proj=($1/*.{xcworkspace,xcodeproj}(N)) - fi + local xcode_files + xcode_files=(${1:-.}/{*.{xcworkspace,xcodeproj},Package.swift}(N)) - - if [[ ${#xcode_proj} -eq 0 ]]; then - if [[ $# == 0 ]]; then - echo "No xcworkspace/xcodeproj file found in the current directory." - else - echo "No xcworkspace/xcodeproj file found in $1." - fi + if [[ ${#xcode_files} -eq 0 ]]; then + echo "No Xcode files found in ${1:-the current directory}." >&2 return 1 - else - local active_path - active_path=$(xcode-select -p) - active_path=${active_path%%/Contents/Developer*} - echo "Found ${xcode_proj[1]}. Opening with ${active_path}" - open -a "$active_path" "${xcode_proj[1]}" fi + + local active_path + active_path=${"$(xcode-select -p)"%%/Contents/Developer*} + echo "Found ${xcode_files[1]}. Opening with ${active_path}" + open -a "$active_path" "${xcode_files[1]}" } # Opens a file or files in the Xcode IDE. Multiple files are opened in multi-file browser