Back to Skills

shfmt-configuration

verified

Use when configuring shfmt for shell script formatting including .shfmt.toml setup, EditorConfig integration, and project-specific settings.

View on GitHub

Marketplace

han

TheBushidoCollective/han

Plugin

jutsu-shfmt

Technique

Repository

TheBushidoCollective/han
60stars

jutsu/jutsu-shfmt/skills/shfmt-configuration/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-shfmt/skills/shfmt-configuration/SKILL.md -a claude-code --skill shfmt-configuration

Installation paths:

Claude
.claude/skills/shfmt-configuration/
Powered by add-skill CLI

Instructions

# shfmt Configuration

Master shfmt configuration for consistent shell script formatting across projects, including configuration files, EditorConfig integration, and team standardization.

## Overview

shfmt is a shell parser, formatter, and interpreter that supports POSIX Shell, Bash, and mksh. Configuration allows you to define consistent formatting rules for your shell scripts.

## Configuration Methods

shfmt supports multiple configuration approaches, in order of precedence:

1. Command-line flags (highest precedence)
2. EditorConfig settings
3. `.shfmt.toml` or `shfmt.toml` file

## TOML Configuration File

### Basic Configuration

Create `.shfmt.toml` or `shfmt.toml` in your project root:

```toml
# Shell dialect (posix, bash, mksh, bats)
shell = "bash"

# Indent with spaces (0 for tabs)
indent = 2

# Binary operators at start of line
binary-next-line = true

# Switch cases indented
switch-case-indent = true

# Redirect operators followed by space
space-redirects = false

# Keep column alignment paddings
keep-padding = false

# Function opening brace on next line
func-next-line = false
```

### Configuration Options Explained

#### shell

Specifies the shell dialect for parsing:

```toml
# POSIX-compliant shell (most portable)
shell = "posix"

# Bash (default for .bash files)
shell = "bash"

# MirBSD Korn Shell
shell = "mksh"

# Bats (Bash Automated Testing System)
shell = "bats"
```

Auto-detection based on shebang if not specified:

- `#!/bin/sh` -> posix
- `#!/bin/bash` or `#!/usr/bin/env bash` -> bash
- `#!/bin/mksh` -> mksh

#### indent

Controls indentation style:

```toml
# 2 spaces (common)
indent = 2

# 4 spaces
indent = 4

# Tabs (use 0)
indent = 0
```

#### binary-next-line

Controls binary operator positioning:

```toml
# Operators at end of line (default)
binary-next-line = false
```

```bash
# Result:
if [ "$a" = "foo" ] &&
   [ "$b" = "bar" ]; then
    echo "match"
fi
```

```toml
# Operators at start of next line
binary-next-line = true
```

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
7409 chars