shfmt-formatting
БесплатноБез исполняемых скриптовНе проверенUse when formatting shell scripts with shfmt. Covers consistent formatting patterns, shell dialect support, common issues, and editor integration.
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
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
Установить shfmt-formatting в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditBashGrepGlobFAQ
Что делает скилл shfmt-formatting?
Use when formatting shell scripts with shfmt. Covers consistent formatting patterns, shell dialect support, common issues, and editor integration.
Как установить скилл shfmt-formatting?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл shfmt-formatting запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic