Token导航 LogoToken导航

Agent Skill · 开发

shfmt-formatting(移动格式)

shfmt-formatting 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

shfmt-formatting 是开发类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为执行命令;许可证为 MIT,第三方扫描已通过,按安装量在开发类的 21,746 个 Skill 里排第 16,566。

总安装 490周安装 20GitHub Stars 142下载 157核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:shfmt-formatting(移动格式)
来源仓库:https://github.com/thebushidocollective/han
仓库路径:skills/shfmt-formatting
安装命令:
npx skills add https://github.com/thebushidocollective/han --skill shfmt-formatting
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/thebushidocollective/han --skill shfmt-formatting

这个 Skill 是做什么的

开发类 Skill 面向写代码、改代码和排查问题,一般会读写仓库文件,部分还会执行构建或测试命令。

用于处理 GitHub 仓库、Issue 和 Pull Request 协作信息。适合整理代码变更、跟踪任务状态或分析协作流程。可通过 GitHub API 获取仓库元数据和事件历史。安装前需确认账号权限,避免越权访问敏感仓库。shfmt-formatting 属于开发类 Skill,可作为该场景下的辅助能力补充。

建议结合原始 README 了解具体命令和数据格式。

来源仓库内路径:skills/shfmt-formatting

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/thebushidocollective/han --skill shfmt-formatt…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要执行命令,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

shfmt-formatting 怎么安装?

在终端执行 npx skills add https://github.com/thebushidocollective/han --skill shfmt-formatting。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

shfmt-formatting 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

shfmt-formatting 需要什么权限?

权限级别是执行命令。安装流程涉及命令执行,可能通过 npx skills add https://github.com/thebushidocollective/han --skill shfmt-formatting;npx skills add thebushidocollective/han --skill "shfmt-formatting" 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

shfmt-formatting 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

shfmt-formatting 用的人多吗?

公开数据是累计安装 490 次,近一周安装 20 次,下载 157 次,GitHub 142 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

shfmt-formatting 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要执行命令,装到常用环境前要先评估影响面。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理开发类任务、又不想每次都手写提示词的人。
  • 需要许可证清楚、并且有第三方扫描结果的团队项目。

不太适合

  • 不能接受 Skill 在你机器上执行命令的人。
  • 需要厂商级技术支持和 SLA 的生产系统。

开发类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
skill-vetter

技能审查员 · OpenClaw

8,779,018986操作浏览器MIT-0通过
ontology

本体论 · OpenClaw

6,636,960576只读MIT-0通过
entra-app-registration

内部应用程序注册 · Codex、Claude

6,631,872764接触敏感数据未明确通过
entra-app-registration

内部应用程序注册 · Codex、Claude

3,757,680201接触敏感数据未明确通过
nano-banana-pro

纳米香蕉专业版 · OpenClaw

3,526,898364接触敏感数据MIT-0有提醒
shfmt-formatting

移动格式 · 本页

490142执行命令MIT通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

shfmt Formatting

Expert knowledge of shfmt's formatting capabilities, patterns, and integration with development workflows for consistent shell script formatting.

Overview

shfmt formats shell scripts for readability and consistency. It parses scripts into an AST and prints them in a canonical format, eliminating style debates and ensuring uniformity across codebases.

Supported Shell Dialects

shfmt supports multiple shell dialects with different syntax rules:

POSIX Shell

Most portable, works with /bin/sh on any Unix system:

#!/bin/sh
# POSIX-compliant syntax only

# No arrays
# No [[ ]] tests
# No $() must work in all contexts

if [ "$var" = "value" ]; then
    echo "match"
fi

Bash

Most common for scripts, supports extended features:

#!/usr/bin/env bash
# Bash-specific features allowed

declare -a array=("one" "two" "three")

if [[ "$var" == "value" ]]; then
    echo "match"
fi

result=$((1 + 2))

mksh (MirBSD Korn Shell)

Korn shell variant with its own extensions:

#!/bin/mksh
# mksh-specific syntax

typeset -A assoc
assoc[key]=value

Bats (Bash Automated Testing System)

For Bats test files:

#!/usr/bin/env bats

@test "example test" {
    run my_command
    [ "$status" -eq 0 ]
}

Formatting Patterns

Indentation

shfmt normalizes indentation throughout scripts:

Before:

if [ "$x" = "y" ]; then
  echo "two spaces"
    echo "four spaces"
 echo "tab"
fi

After (with -i 2):

if [ "$x" = "y" ]; then
  echo "two spaces"
  echo "four spaces"
  echo "tab"
fi

Spacing

shfmt normalizes spacing around operators and keywords:

Before:

if[$x="y"];then
echo "no spaces"
fi
x=1;y=2;z=3

After:

if [ $x = "y" ]; then
    echo "no spaces"
fi
x=1
y=2
z=3

Semicolons and Newlines

Multiple statements are split to separate lines:

Before:

if [ "$x" ]; then echo "yes"; else echo "no"; fi

After:

if [ "$x" ]; then
    echo "yes"
else
    echo "no"
fi

Here Documents

Here-docs are preserved but indentation is normalized:

Before:

cat <<EOF
    line 1
    line 2
EOF

After (preserved):

cat <<EOF
    line 1
    line 2
EOF

Indented here-docs with <<- allow tab stripping:

if true; then
    cat <<-EOF
 indented content
 more content
 EOF
fi

Function Definitions

Functions are formatted consistently:

Before:

function my_func
{
echo "old style"
}
my_func2 () { echo "one liner"; }

After:

function my_func {
    echo "old style"
}
my_func2() {
    echo "one liner"
}

With -fn (function next line):

function my_func
{
    echo "brace on new line"
}

Case Statements

Case statements are formatted consistently:

Before:

case "$1" in
start) do_start;;
stop)
do_stop
;;
*) echo "unknown";;
esac

After:

case "$1" in
start)
    do_start
    ;;
stop)
    do_stop
    ;;
*)
    echo "unknown"
    ;;
esac

With -ci (case indent):

case "$1" in
    start)
        do_start
        ;;
    stop)
        do_stop
        ;;
esac

Binary Operators

Line continuation with binary operators:

Default:

if [ "$a" = "foo" ] &&
    [ "$b" = "bar" ]; then
    echo "match"
fi

With -bn (binary next line):

if [ "$a" = "foo" ] \
    && [ "$b" = "bar" ]; then
    echo "match"
fi

Redirections

Redirection formatting:

Default:

echo "hello" >file.txt
cat <input.txt 2>&1

With -sr (space redirects):

echo "hello" > file.txt
cat < input.txt 2>&1

Common Formatting Issues

Issue: Mixed Tabs and Spaces

Problem: Script has inconsistent indentation

Solution:

# Convert all to spaces (2-space indent)
shfmt -i 2 -w script.sh

# Or convert all to tabs
shfmt -i 0 -w script.sh

Issue: Trailing Semicolons

Problem: Unnecessary semicolons at end of lines

Before:

echo "hello";
x=1;

After (shfmt removes them):

echo "hello"
x=1

Issue: Inconsistent Quotes

shfmt preserves quote style but normalizes unnecessary quotes:

Before:

echo 'single' "double" $'ansi'
x="simple"

After (preserved):

echo 'single' "double" $'ansi'
x="simple"

Issue: Long Lines

shfmt does not wrap long lines automatically. Use manual line continuation:

# Long command with continuation
very_long_command \
    --option1 value1 \
    --option2 value2 \
    --option3 value3

Issue: Array Formatting

Arrays are formatted on single or multiple lines as written:

# Single line (preserved)
array=(one two three)

# Multi-line (preserved)
array=(
    one
    two
    three
)

Editor Integration

VS Code

Install "shell-format" extension:

// settings.json
{
  "shellformat.path": "/usr/local/bin/shfmt",
  "shellformat.flag": "-i 2 -ci -bn",
  "[shellscript]": {
    "editor.defaultFormatter": "foxundermoon.shell-format",
    "editor.formatOnSave": true
  }
}

Vim/Neovim

Using ALE:

" .vimrc
let g:ale_fixers = {
\   'sh': ['shfmt'],
\}
let g:ale_sh_shfmt_options = '-i 2 -ci -bn'
let g:ale_fix_on_save = 1

Using native formatting:

" .vimrc
autocmd FileType sh setlocal formatprg=shfmt\ -i\ 2\ -ci

Emacs

Using reformatter:

;; init.el
(use-package reformatter
  :config
  (reformatter-define shfmt
    :program "shfmt"
    :args '("-i" "2" "-ci")))

(add-hook 'sh-mode-hook 'shfmt-on-save-mode)

JetBrains IDEs

Install "Shell Script" plugin, configure in: Settings -> Tools -> Shell Scripts -> Formatter

Path to shfmt: /usr/local/bin/shfmt
Options: -i 2 -ci -bn

Diff and Check Modes

Check Formatting (CI Mode)

# Show diff of what would change (exit 1 if changes needed)
shfmt -d script.sh
shfmt -d .

# List files that need formatting
shfmt -l .

# Exit codes:
# 0 = no changes needed
# 1 = changes needed or error

Format in Place

# Overwrite files with formatted version
shfmt -w script.sh
shfmt -w .

Preview Changes

# Output formatted version to stdout
shfmt script.sh

# Output formatted version to file
shfmt script.sh > formatted.sh

Working with Git

Format Staged Files

# Format only staged shell scripts
git diff --cached --name-only --diff-filter=ACM | \
    grep '\.sh$' | \
    xargs -r shfmt -w

Pre-commit Hook

#!/usr/bin/env bash
# .git/hooks/pre-commit

# Check if shfmt is available
if ! command -v shfmt &>/dev/null; then
    echo "shfmt not found, skipping format check"
    exit 0
fi

# Get staged shell files
files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.sh$')

if [ -n "$files" ]; then
    # Check formatting
    if ! echo "$files" | xargs shfmt -d; then
        echo "Shell scripts need formatting. Run: shfmt -w <files>"
        exit 1
    fi
fi

Format Changed Files

# Format files changed since main branch
git diff --name-only main...HEAD | \
    grep '\.sh$' | \
    xargs -r shfmt -w

Minification (Advanced)

shfmt can minify scripts by removing whitespace:

# Minify script
shfmt -mn script.sh > script.min.sh

Before:

#!/bin/bash
# Comment
function hello {
    echo "Hello, World!"
}
hello

After (minified):

#!/bin/bash
function hello { echo "Hello, World!"; }
hello

Note: Minification removes comments and most whitespace. Use only for distribution, not development.

Best Practices

  1. Format on Save - Configure editor to format automatically
  2. CI Validation - Run shfmt -d in CI pipelines
  3. Consistent Team Settings - Commit .shfmt.toml to repository
  4. Match Shebang - Ensure shell dialect matches script shebang
  5. Review After Formatting - Verify changes make sense
  6. Don't Mix Styles - Use same settings across all scripts
  7. Pre-commit Hooks - Prevent unformatted code from being committed

Troubleshooting

Parse Errors

If shfmt fails to parse a script:

# Check syntax first
bash -n script.sh

# Or for POSIX
sh -n script.sh

Wrong Dialect Detection

Force the correct dialect:

shfmt -ln bash script.sh
shfmt -ln posix script.sh

Preserving Intentional Formatting

For code that should not be reformatted, consider:

  1. Moving it to a separate file not processed by shfmt
  2. Using # shfmt:ignore comments (not supported - use file exclusion)
  3. Accepting the formatted version

When to Use This Skill

  • Formatting shell scripts for consistency
  • Integrating shfmt into development workflow
  • Resolving formatting issues in scripts
  • Setting up format-on-save in editors
  • Configuring CI/CD format checks
  • Understanding shfmt's formatting decisions

平台分布

Claude Code

29.17%
按下载量换算46

Codex

24.54%
按下载量换算39

OpenCode

19.58%
按下载量换算31

Antigravity

12.17%
按下载量换算19

windsurf

8.99%
按下载量换算14

Gemini CLI

3.61%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

执行命令

安装流程涉及命令执行,可能通过 npx skills add https://github.com/thebushidocollective/han --skill shfmt-formatting;npx skills add thebushidocollective/han --skill "shfmt-formatting" 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

继续浏览同类 Skills