xc

打开指定版本的 Xcode 项目文件

用法

使用首选 Xcode 版本打开项目文件

xc

使用 Xcode 14.2.0 打开项目文件

xc -v 14.2.0
xc list

---
Available Xcode:
14.2    /Applications/Xcode.app         <xcode-select>
14.1    /Applications/Xcode14.1.app
13.4.1  /Applications/Xcode13.4.1.app
13.2.1  /Applications/Xcode13.2.1.app

功能

自动项目文件搜索 (优先级)

  1. 用户指定路径
  2. .xcworkspace
  3. .xcodeproj
  4. Package.swift

自动 Xcode 版本搜索 (优先级)

  1. 用户指定版本
  2. .xcode-version
  3. $ xcode-select

显示所有已安装的 Xcode 列表

通过 NSWorkspace.shared.urlsForApplications(withBundleIdentifier: "com.apple.dt.Xcode") 自动搜索 Xcode。

xc list

---
Available Xcode:
14.2    /Applications/Xcode.app         <xcode-select>
14.1    /Applications/Xcode14.1.app
13.4.1  /Applications/Xcode13.4.1.app
13.2.1  /Applications/Xcode13.2.1.app

打开 Xcode.app 但不打开项目

只需运行

xc -n

通过 xcode-select 自动更改开发者目录

当你执行 xcxc open 命令时,自动执行 sudo xcode-select --switch。这需要 sudo 密码。你可以通过 $ xc config 设置 sudo 密码

警告

此功能默认禁用。

你可以通过执行以下命令启用此功能。

$ xc config write --sudo-password <sudo-password> --auto-xcode-select-enabled true

命令补全

此命令构建于 swift-argument-parser 之上。

请参考 这篇文章

example 替换为 xc

安装

Homebrew

brew install s2mr/tap/xc

Swift Package Manager

将以下内容添加到你的 Package.swift 文件的依赖项中

dependencies: [
    .package(url: "https://github.com/s2mr/xc.git", from: "xc version"),
]

运行命令

swift run -c release xc [COMMAND] [OPTIONS]

Mint

通过以下命令使用 Mint 安装

mint install s2mr/xc

运行命令

mint run s2mr/xc [COMMAND] [OPTIONS]

使用预构建的二进制文件

你也可以通过从最新的 GitHub 版本下载 xc.zip 来安装 xc。

帮助

xc --help

---
OVERVIEW: This tool launches the Xcode application and opens the given documents.

USAGE: xc <subcommand>

OPTIONS:
  --version               Show the version.
  -h, --help              Show help information.

SUBCOMMANDS:
  list                    Available Xcodes list
  open (default)          Shows available versions of Xcode
  config                  Read and write xc command config. Config json is stored at `~/.config/xc/config.json`
  env                     Current environment

  See 'xc help <subcommand>' for detailed help.
xc open --help

---
OVERVIEW: Shows available versions of Xcode

USAGE: xc open [-v <v>] [<path>]

ARGUMENTS:
  <path>                  File path

OPTIONS:
  -v <v>                  Open with specific Xcode version
  --version               Show the version.
  -h, --help              Show help information.