From d4d0c196599d36853581bbb956c1af141bbcc852 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Tue, 7 Jul 2026 17:11:14 +0200 Subject: [PATCH] [style] Separate then from if in shell scripts. Move 'then' to its own line after 'if' for readability. Also converts the remaining extended regex patterns in guix-check to basic regex, and fixes a comment case in notify. --- .claude/hooks/guix-build | 12 ++++++++---- .claude/hooks/guix-check | 18 +++++++++++------- .claude/hooks/notify | 2 +- .claude/hooks/status-line | 3 ++- .claude/scripts/ask-build-queue | 3 ++- .claude/scripts/merge-worktree | 3 ++- autorandr/.config/autorandr/postswitch | 3 ++- bash/.bash_profile | 15 ++++++++++----- bash/.config/profile.d/50-bash.sh | 3 ++- claude/.local/bin/get-api-key | 3 ++- scripts/status_bar | 3 ++- 11 files changed, 44 insertions(+), 24 deletions(-) diff --git a/.claude/hooks/guix-build b/.claude/hooks/guix-build index 59ab6b4..911b847 100755 --- a/.claude/hooks/guix-build +++ b/.claude/hooks/guix-build @@ -36,7 +36,8 @@ MAKEFILE="$CLAUDE_PROJECT_DIR/Makefile" if [ -z "$($HOME/.guix-home/profile/bin/git -C "$CLAUDE_PROJECT_DIR" \ - status --porcelain --untracked-files=no)" ]; then + status --porcelain --untracked-files=no)" ] +then $GUIX_BIN/echo '{"systemMessage":"🟢 Working tree clean."}' exit 0 fi @@ -45,15 +46,18 @@ $GUIX_BIN/mkdir --parents "$CLAUDE_PROJECT_DIR/.claude" QUEUE_FILE="$CLAUDE_PROJECT_DIR/.claude/.build-queue.$CLAUDE_CODE_SESSION_ID" # No queue file yet. -if [ ! -f "$QUEUE_FILE" ]; then +if [ ! -f "$QUEUE_FILE" ] +then "$CLAUDE_PROJECT_DIR/.claude/scripts/ask-build-queue" exit 2 fi # Build the first target if the queue is non-empty. -if [ -s "$QUEUE_FILE" ]; then +if [ -s "$QUEUE_FILE" ] +then target=$($GUIX_BIN/head --lines=1 "$QUEUE_FILE") - if ! $GUIX_BIN/grep --quiet "^${target}:" "$MAKEFILE"; then + if ! $GUIX_BIN/grep --quiet "^${target}:" "$MAKEFILE" + then $GUIX_BIN/sed --in-place '1d' "$QUEUE_FILE" exec 1>&2 diff --git a/.claude/hooks/guix-check b/.claude/hooks/guix-check index 19c5402..43c30af 100755 --- a/.claude/hooks/guix-check +++ b/.claude/hooks/guix-check @@ -5,17 +5,19 @@ # guix-check — Checks to be applied after every edit of a guile file. If a check # fails, the script exits with status code 2 to make Claude Code fix the issues. -file=$($GUIX_BIN/sed --regexp-extended --quiet \ - 's/.*"file_path"\s*:\s*"([^"]*)".*/\1/p') +file=$($GUIX_BIN/sed --quiet \ + 's/.*"file_path"\s*:\s*"\([^"]*\)".*/\1/p') [ -z "$file" ] && exit 0 -if ! $GUIX_BIN/guix style --whole-file "$file"; then +if ! $GUIX_BIN/guix style --whole-file "$file" +then exec 1>&2 $GUIX_BIN/echo "❌ guix style failed on $file." exit 2 fi -if $GUIX_BIN/grep --quiet '^unbalanced$' "$file"; then +if $GUIX_BIN/grep --quiet '^unbalanced$' "$file" +then exec 1>&2 $GUIX_BIN/echo "❌ guix style added \`unbalanced\` token to $file for each" $GUIX_BIN/echo "extra closing parenthesis. Remove these tokens AND fix the" @@ -23,8 +25,9 @@ if $GUIX_BIN/grep --quiet '^unbalanced$' "$file"; then exit 2 fi -long_lines=$($GUIX_BIN/grep --line-number --extended-regexp '^.{81,}$' "$file") -if [ -n "$long_lines" ]; then +long_lines=$($GUIX_BIN/grep --line-number '^.\{81,\}$' "$file") +if [ -n "$long_lines" ] +then exec 1>&2 $GUIX_BIN/echo "❌ Lines exceed 80 characters in $file:" $GUIX_BIN/echo "" @@ -65,7 +68,8 @@ out=$( # guild exits non-zero for fatal errors but still exits 0 for warnings so we # check both. -if [ $? -ne 0 ] || $GUIX_BIN/echo "$out" | $GUIX_BIN/grep --quiet warning; then +if [ $? -ne 0 ] || $GUIX_BIN/echo "$out" | $GUIX_BIN/grep --quiet warning +then exec 1>&2 $GUIX_BIN/echo "❌ Compilation issues in $file:" $GUIX_BIN/echo "" diff --git a/.claude/hooks/notify b/.claude/hooks/notify index 4a9ef55..f143e57 100755 --- a/.claude/hooks/notify +++ b/.claude/hooks/notify @@ -2,7 +2,7 @@ # Copyright (c) 2026 Jakub Czajka # License: GPL-3.0 or later. # -# notify — send a desktop notification for Claude Code events. +# notify — Send a desktop notification for Claude Code events. type=$(sed -n \ 's/.*"notification_type":"\([^"]*\)".*/\1/p') diff --git a/.claude/hooks/status-line b/.claude/hooks/status-line index 3475173..da4370b 100755 --- a/.claude/hooks/status-line +++ b/.claude/hooks/status-line @@ -4,7 +4,8 @@ # # status-line - Display current session/worktree in the Claude Code prompt. -if echo "$PWD" | grep -q '/worktrees/'; then +if echo "$PWD" | grep -q '/worktrees/' +then echo "🌿 $CLAUDE_CODE_SESSION_ID" else branch=$(git -C "$PWD" branch --show-current 2>/dev/null) diff --git a/.claude/scripts/ask-build-queue b/.claude/scripts/ask-build-queue index 46d5783..7fa39ea 100755 --- a/.claude/scripts/ask-build-queue +++ b/.claude/scripts/ask-build-queue @@ -12,7 +12,8 @@ QUEUE_FILE="$CLAUDE_PROJECT_DIR/.claude/.build-queue.$CLAUDE_CODE_SESSION_ID" # Print space-separated Makefile targets whose recipe matches the # branch-appropriate guix command: reconfigure on main, build elsewhere. build_targets() { - if [ "$2" = "main" ]; then + if [ "$2" = "main" ] + then pattern="guix.*reconfigure" else pattern="guix.*build" diff --git a/.claude/scripts/merge-worktree b/.claude/scripts/merge-worktree index dfd3496..bc71ed0 100755 --- a/.claude/scripts/merge-worktree +++ b/.claude/scripts/merge-worktree @@ -67,7 +67,8 @@ then exit 1 fi -if [ "$branch" = "main" ]; then +if [ "$branch" = "main" ] +then echo "Error: Cannot merge main into itself." >&2 exit 1 fi diff --git a/autorandr/.config/autorandr/postswitch b/autorandr/.config/autorandr/postswitch index 3f12230..e8a0b53 100755 --- a/autorandr/.config/autorandr/postswitch +++ b/autorandr/.config/autorandr/postswitch @@ -4,7 +4,8 @@ # # postswitch - Script executed after the layout switch. -if [ `which wallpaper` ]; then +if [ `which wallpaper` ] +then wallpaper fi diff --git a/bash/.bash_profile b/bash/.bash_profile index 13aa1ee..789ec40 100644 --- a/bash/.bash_profile +++ b/bash/.bash_profile @@ -7,24 +7,29 @@ # Sources program-specific profiles from $XDG_CONFIG_HOME/profile.d and starts # Xorg. See bash(1) for more information about login shells. -if [ -f ~/.profile ]; then +if [ -f ~/.profile ] +then . ~/.profile fi _confdir=${XDG_CONFIG_HOME:-${HOME}/.config} -if [ -d ${_confdir}/profile.d/ ]; then - for _f in ${_confdir}/profile.d/*.sh; do +if [ -d ${_confdir}/profile.d/ ] +then + for _f in ${_confdir}/profile.d/*.sh + do [ -r ${_f} ] && . ${_f} done unset _f fi -if [ -f ${_confdir}/X11/xbindkeysrc ]; then +if [ -f ${_confdir}/X11/xbindkeysrc ] +then xbindkeys --file "${XDG_CONFIG_HOME}/X11/xbindkeysrc" fi -if [ -f ${_confdir}/X11/Xresources ]; then +if [ -f ${_confdir}/X11/Xresources ] +then xrdb -merge -I"${HOME}" "${XDG_CONFIG_HOME}/X11/Xresources" fi diff --git a/bash/.config/profile.d/50-bash.sh b/bash/.config/profile.d/50-bash.sh index 6b7be62..c2b2698 100644 --- a/bash/.config/profile.d/50-bash.sh +++ b/bash/.config/profile.d/50-bash.sh @@ -3,7 +3,8 @@ # # 50-bash.sh - bash environment variables. -if [ ! -f ${XDG_DATA_HOME}/bash ]; then +if [ ! -f ${XDG_DATA_HOME}/bash ] +then mkdir -p ${XDG_DATA_HOME}/bash fi diff --git a/claude/.local/bin/get-api-key b/claude/.local/bin/get-api-key index c42ed7d..8325980 100755 --- a/claude/.local/bin/get-api-key +++ b/claude/.local/bin/get-api-key @@ -10,7 +10,8 @@ set -o errexit GUIX_BIN="/run/current-system/profile/bin" CACHE="${XDG_RUNTIME_DIR:-/tmp}/claude-apikey" -if [ -f "${CACHE}" ]; then +if [ -f "${CACHE}" ] +then "${GUIX_BIN}/cat" "${CACHE}" else (umask 077; pass show platforms/deepseek \ diff --git a/scripts/status_bar b/scripts/status_bar index 7cc0645..625aea5 100755 --- a/scripts/status_bar +++ b/scripts/status_bar @@ -16,7 +16,8 @@ day() { volume() { VOLUME=$(amixer | awk -F"[][]" '/dB/ { print $2 }' | head -n1) - if [ "${VOLUME}" = "0%" ]; then + if [ "${VOLUME}" = "0%" ] + then echo "🔇 ${VOLUME}" else echo "🔊 ${VOLUME}" -- 2.47.3