agentleFS
ivangrynenkoivangrynenko/cursorrules/.cursor/rules/generic_bash_style.mdc

cursorrules / rules

Cursor rule88 starsChanged 13 months agoMITView on GitHub

Enforce general Bash scripting standards with enhanced logging

The file

We split this generic_bash_style.mdc into the rules it gives an agent

7 rules. About 0 are common, 4 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Error Handling: Use set -eu to catch errors and undefined variables early.

    line 34
  2. Distinctive:

    Logging Functions: Use colorized logging for better script output readability:

    line 36
  3. Very specific:

    Security: Avoid using eval or similar constructs.

    line 42
  4. Very specific:

    Portability: Use /usr/bin/env bash for the shebang to ensure script runs with bash on any system.

    line 44
  5. Distinctive:

    Variable Checks: Ensure necessary variables are set, enhancing script reliability.

    line 45
  6. Distinctive:

    Exit Codes: Use explicit exit codes for different failure scenarios.

    line 46
  7. Distinctive:

    Color Support: Ensure logging functions check for terminal color support before applying colors.

    line 47

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
generic_bash_style.mdc
---
description: Enforce general Bash scripting standards with enhanced logging
globs: 
---
# Enhanced Bash Scripting Standard with Colorized Logging

This rule enforces best practices for writing Bash scripts, with an emphasis on using colorized logging for better output readability.

## Rule Details

- **Name:** enhanced_bash_style

- **Description:** Enforce Bash scripting standards with colorized logging

## Filters
- file extension pattern: `\\.sh$`

## Enforcement Checks
- Conditions:
  - pattern `^#!/usr/bin/env bash$` – All scripts should start with the shebang '#!/usr/bin/env bash'.
  - pattern `^set -eu$` – Enable 'set -eu' for script robustness.
  - pattern `^set -x$` – negated `^\\[ \"\\${DEBUG-}\" = \"1\" ] && set -x$` – Use conditional 'set -x' based on debug flag.
  - pattern `^# @formatter:off$` – Start of formatting block for log functions.
  - pattern `note\\(\\) { printf \"       %s\\n\" \"\\${1}\"; }$` – Include 'note' function for plain messages.
  - pattern `info\\(\\) { \\[ \"\\${TERM:-}\" != \"dumb\" ] && tput colors >/dev/null 2>&1 && printf \"\\\\033\\[34m\\[INFO] %s\\\\033\\[0m\\n\" \"\\${1}\" || printf \"\\[INFO] %s\\n\" \"\\${1}\"; }$` – Include 'info' function for blue informational messages.
  - pattern `pass\\(\\) { \\[ \"\\${TERM:-}\" != \"dumb\" ] && tput colors >/dev/null 2>&1 && printf \"\\\\033\\[32m\\[ OK ] %s\\\\033\\[0m\\n\" \"\\${1}\" || printf \"\\[ OK ] %s\\n\" \"\\${1}\"; }$` – Include 'pass' function for green success messages.
  - pattern `fail\\(\\) { \\[ \"\\${TERM:-}\" != \"dumb\" ] && tput colors >/dev/null 2>&1 && printf \"\\\\033\\[31m\\[FAIL] %s\\\\033\\[0m\\n\" \"\\${1}\" || printf \"\\[FAIL] %s\\n\" \"\\${1}\"; }$` – Include 'fail' function for red error messages.
  - pattern `warn\\(\\) { \\[ \"\\${TERM:-}\" != \"dumb\" ] && tput colors >/dev/null 2>&1 && printf \"\\\\033\\[33m\\[WARN] %s\\\\033\\[0m\\n\" \"\\${1}\" || printf \"\\[WARN] %s\\n\" \"\\${1}\"; }$` – Include 'warn' function for yellow warning messages.
  - pattern `^# @formatter:on$` – End of formatting block for log functions.

## Suggestions
- Guidance:
**Bash Scripting Best Practices:**
- **Error Handling:** Use `set -eu` to catch errors and undefined variables early.
- **Debugging:** Implement conditional debugging with `set -x` using a DEBUG variable.
- **Logging Functions:** Use colorized logging for better script output readability:
  - `note()` for plain notes
  - `info()` for blue informational messages
  - `pass()` for green success messages
  - `fail()` for red error messages
  - `warn()` for yellow warnings, ensuring users can distinguish different types of messages easily
- **Security:** Avoid using `eval` or similar constructs; use safe alternatives.
- **Documentation:** Include descriptive comments, especially for complex logic.
- **Portability:** Use `/usr/bin/env bash` for the shebang to ensure script runs with bash on any system.
- **Variable Checks:** Ensure necessary variables are set, enhancing script reliability.
- **Exit Codes:** Use explicit exit codes for different failure scenarios.
- **Color Support:** Ensure logging functions check for terminal color support before applying colors.

## Metadata
- Priority: medium
- Version: 1.2

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.