function::indent_depth - Linux


Overview

indent_depth is a command-line utility that measures the indentation depth of text, typically used for source code analysis and text processing tasks. It calculates the indentation level for each line of text, helping to identify the structure and organization of the code or text.

Syntax

indent_depth [options] <file>

Options/Flags

  • -h, –help: Display help information
  • -v, –version: Display version information
  • -t TABWIDTH: Specify the tab width (default: 8)
  • -s SPACES: Use spaces instead of tabs (default: false)
  • -e EDGE: Hide or show lines with no indentation (default: hide)
  • -S STYLE: Specify the indentation style (default: c)
  • c: C-style indentation (spaces only)
  • j: Java-style indentation (tabs & spaces)
  • p: Python-style indentation (spaces only)
  • v: Vim-style indentation (tabs & spaces)
  • -i IGNORES: Ignore lines matching the specified pattern (e.g., -i '^\s*$')

Examples

Basic usage:

indent_depth my_file.txt

Use spaces instead of tabs:

indent_depth -s my_file.txt

Show lines with no indentation:

indent_depth -e show my_file.txt

Ignore empty lines:

indent_depth -i '^\s*$' my_file.txt

Count indentation depth using Java-style indentation:

indent_depth -S j my_file.java

Common Issues

  • Incorrect tab width: Ensure that the specified tab width matches the actual tab width in the text to obtain accurate indentation depths.
  • Unrecognized indentation style: The specified indentation style should be one of the supported options (c, j, p, v).

Integration

Combine with grep: Filter indentation depths based on a specific pattern:

indent_depth my_file.txt | grep '^10$'

Use with sed: Modify indentation depths using sed commands:

indent_depth -e show my_file.txt | sed -r 's/^([[:space:]]+)[[:space:]]+/\1/' > new_file.txt

Related Commands

  • cloc – A tool for counting lines of code in various programming languages
  • indent – A C code beautifier and formatter