Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

java-format-scripts

Portable Bash tooling for installing and using google-java-format.

Install / 安裝

Install the latest version / 安裝最新版

The one-line installer downloads the versioned java-format.sh release asset to ~/.local/bin/java-format, then installs the latest google-java-format release for the current user.

這行指令會下載已發佈版本的 java-format.sh~/.local/bin/java-format,再為目前使用者安裝最新版的 google-java-format。

curl -fsSL https://github.com/samzhu/java-format-scripts/releases/latest/download/install.sh | bash

The installer saves the script at a permanent path because install-hook records that path in the Git pre-commit hook. Do not run the main formatter only from a temporary directory.

安裝程式會把腳本存放在固定路徑,因為 install-hook 會將該路徑寫入 Git pre-commit hook。請勿只從暫存目錄執行主腳本。

Pin google-java-format / 指定 google-java-format 版本

To install a particular google-java-format version instead of its latest release:

若不想安裝最新版,可在一鍵安裝指令最後指定 google-java-format 的版本:

curl -fsSL https://github.com/samzhu/java-format-scripts/releases/latest/download/install.sh | bash -s -- --version 1.35.0

Pin this installer / 指定本工具版本

To install a fixed version of this script, replace latest with a release tag such as 1:

若要固定此工具本身的版本,請把 latest 改成 Release tag,例如 1

curl -fsSL https://github.com/samzhu/java-format-scripts/releases/download/1/install.sh | bash

curl | bash executes remote code. Review the tagged release before running it in environments you do not control.

curl | bash 會直接執行遠端程式碼;在非自行控制的環境執行前,請先檢閱指定版本的 Release 內容。

Add the command to PATH / 將指令加入 PATH

The installer uses ~/.local/bin. If it is not already on your PATH, add it once for zsh:

安裝程式使用 ~/.local/bin。若此目錄尚未在 PATH 中,zsh 使用者可執行一次:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

You can then run java-format format from any directory.

完成後,就能在任何目錄直接執行 java-format format

Commands

java-format install [--version <x.y.z>] [--force]
java-format format [path...]
java-format diff [--staged | --base <git-ref>]
java-format check [path...]
java-format install-hook
java-format uninstall-hook
  • format recursively formats all *.java files below the supplied paths, excluding .git.
  • diff formats every Java file in the unstaged Git diff; --staged formats only index content and preserves any unstaged changes to the same file.
  • check exits nonzero if google-java-format would make a change.
  • install-hook safely preserves an existing pre-commit hook and only updates staged Java blobs. uninstall-hook restores the prior hook.

Platform support

  • macOS Apple Silicon, Linux x64/arm64, and Windows x64 through Git Bash/MSYS/WSL use official native binaries.
  • Intel Mac and other unsupported architectures use the all-deps JAR and require a JDK 21+.
  • The script defaults to the newest google-java-format release. It records the known version when the script was released at the top of java-format.sh.

Maintenance / 維護說明

  • Shell comments explain design and safety decisions, such as platform fallback, the stable hook launcher, and preserving partial staging; they intentionally do not narrate every line of syntax.

  • Runtime output reports command scope, file counts, installation targets, and hook changes. Detailed formatter output is shown only for errors or files that need attention.

  • Keep install.sh, README.md, and the Release assets in sync whenever changing the installer name, path, or Release tag.

  • Shell 註解用於說明平台 fallback、穩定 hook launcher、保留部分暫存等設計與安全原因,不逐行解釋語法。

  • 執行訊息會顯示命令範圍、檔案數量、安裝位置與 hook 變更;只有錯誤或需處理的檔案才會顯示 formatter 詳細輸出。

  • 修改安裝程式名稱、路徑或 Release tag 時,必須同步更新 install.shREADME.md 與 Release assets。

Publishing a new script release

  1. Update RELEASE_TAG in install.sh to the new tag, then update the README's fixed-version example if needed.

  2. Commit and push the change, then create and push the tag.

  3. Upload both shell files as assets with the same names:

    gh release create 1 java-format.sh install.sh --title 1 --generate-notes

The latest installation URL works because GitHub provides a stable URL for a release asset with a fixed filename.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages