From 5f297e69e00dde84d9c297a6c4a38182e859c0c0 Mon Sep 17 00:00:00 2001 From: n0tori <188390306+n0tori@users.noreply.github.com> Date: Thu, 8 Jan 2026 22:54:12 +0000 Subject: added compact option --- README.md | 5 +++++ langbreak | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cff0b45..7f685c8 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,11 @@ Custom bar width: ./langbreak --width 50 ``` +Compact output: +```bash +./langbreak --compact +``` + Redirect to a file: ```bash ./langbreak --json > stats.json diff --git a/langbreak b/langbreak index ee18c18..b58114d 100644 --- a/langbreak +++ b/langbreak @@ -12,6 +12,7 @@ # ./langbreak --json # ./langbreak --max-depth 2 # ./langbreak --width 50 +# ./langbreak --compact # Color constants (ANSI 256-color codes) readonly COLOR_RESET='\033[0m' @@ -21,6 +22,7 @@ declare -A LANGUAGE_FILES declare -A EXTENSION_MAP MAX_DEPTH="" BAR_WIDTH="" +COMPACT_MODE=false ####################################### # Initialize language-to-color mapping (GitHub linguist colors) @@ -332,6 +334,7 @@ export_yaml() { # LANGUAGE_COLORS # COLOR_RESET # BAR_WIDTH +# COMPACT_MODE # Arguments: # None ####################################### @@ -375,14 +378,28 @@ render_output() { done echo "" - # Render the legend - for language in ${sorted_languages}; do - local bytes="${LANGUAGE_BYTES[${language}]}" - local percentage=$(awk "BEGIN {printf \"%.1f\", ${bytes} * 100.0 / ${total_bytes}}") - local color="${LANGUAGE_COLORS[${language}]:-7}" - - printf "\033[38;5;%sm■\033[0m %-15s %6s%%\n" "${color}" "${language}" "${percentage}" - done + if [[ "${COMPACT_MODE}" == "true" ]]; then + # Compact mode: just print language names separated by commas + local first=true + for language in ${sorted_languages}; do + if [[ "${first}" == "true" ]]; then + echo -n "${language}" + first=false + else + echo -n ", ${language}" + fi + done + echo "" + else + # Normal mode: print detailed legend + for language in ${sorted_languages}; do + local bytes="${LANGUAGE_BYTES[${language}]}" + local percentage=$(awk "BEGIN {printf \"%.1f\", ${bytes} * 100.0 / ${total_bytes}}") + local color="${LANGUAGE_COLORS[${language}]:-7}" + + printf "\033[38;5;%sm■\033[0m %-15s %6s%%\n" "${color}" "${language}" "${percentage}" + done + fi } ####################################### @@ -427,6 +444,10 @@ main() { BAR_WIDTH="$2" shift 2 ;; + --compact) + COMPACT_MODE=true + shift + ;; --help) echo "Usage: ./langbreak [OPTIONS]" echo "" @@ -435,6 +456,7 @@ main() { echo "Options:" echo " --json Export as JSON to stdout" echo " --yaml Export as YAML to stdout" + echo " --compact Compact output (bar + language names on one line)" echo " --max-depth Limit directory traversal to N levels deep" echo " --width Override bar width to N characters (default: terminal width)" echo " --help Show this help message" -- cgit v1.2.3