From 18142abc064aa3075ea9558481328bcaca39c8ab 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/block-worktrees | 9 ++++++--- .claude/hooks/create-worktree | 6 ++++-- .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/branch-summary | 9 ++++++--- .claude/scripts/merge-worktree | 18 ++++++++++++------ 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 ++- 14 files changed, 70 insertions(+), 37 deletions(-) diff --git a/.claude/hooks/block-worktrees b/.claude/hooks/block-worktrees index 7cec6cf..0d6c25c 100755 --- a/.claude/hooks/block-worktrees +++ b/.claude/hooks/block-worktrees @@ -9,7 +9,8 @@ tool=$($GUIX_BIN/sed --quiet \ case "$tool" in Bash) # Deny git checkout/switch. - if $GUIX_BIN/grep -q '"command".*"git checkout"'; then + if $GUIX_BIN/grep -q '"command".*"git checkout"' + then $GUIX_BIN/echo \ '{"hookSpecificOutput": {' \ ' "hookEventName": "PreToolUse",' \ @@ -18,7 +19,8 @@ Bash) '}}' exit 0 fi - if $GUIX_BIN/grep -q '"command".*"git switch"'; then + if $GUIX_BIN/grep -q '"command".*"git switch"' + then $GUIX_BIN/echo \ '{"hookSpecificOutput": {' \ ' "hookEventName": "PreToolUse",' \ @@ -58,7 +60,8 @@ ExitWorktree) branch --show-current 2>/dev/null) if $HOME/.guix-home/profile/bin/git -C "$CLAUDE_PROJECT_DIR" \ - merge-base --is-ancestor "$branch" main 2>/dev/null; then + merge-base --is-ancestor "$branch" main 2>/dev/null + then exit 0 fi diff --git a/.claude/hooks/create-worktree b/.claude/hooks/create-worktree index a5bd6e3..cf996ff 100755 --- a/.claude/hooks/create-worktree +++ b/.claude/hooks/create-worktree @@ -8,13 +8,15 @@ # unless already in this session's worktree. # Let EnterWorktree pass through. -if $GUIX_BIN/grep -q '"tool_name"[[:space:]]*:[[:space:]]*"EnterWorktree"'; then +if $GUIX_BIN/grep -q '"tool_name"[[:space:]]*:[[:space:]]*"EnterWorktree"' +then exit 0 fi # Allow if already is this session's worktree. if $GUIX_BIN/echo "$PWD" | $GUIX_BIN/grep --quiet \ - "/worktrees/${CLAUDE_CODE_SESSION_ID}"; then + "/worktrees/${CLAUDE_CODE_SESSION_ID}" +then exit 0 fi 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/branch-summary b/.claude/scripts/branch-summary index 0623773..2da0ddf 100755 --- a/.claude/scripts/branch-summary +++ b/.claude/scripts/branch-summary @@ -10,7 +10,8 @@ branches=$($HOME/.guix-home/profile/bin/git \ --format='%(refname:short)' refs/heads/ \ | $GUIX_BIN/grep -v '^main$') -if [ -z "$branches" ]; then +if [ -z "$branches" ] +then $GUIX_BIN/echo "No other branches." exit 0 fi @@ -31,11 +32,13 @@ $GUIX_BIN/echo '| Branch | Commits | Summary |' $GUIX_BIN/echo '|--------|---------|---------|' # One row per branch. -echo "$branches" | while read -r b; do +echo "$branches" | while read -r b +do count=$($HOME/.guix-home/profile/bin/git \ -C "$CLAUDE_PROJECT_DIR" rev-list --count \ main.."$b" 2>/dev/null) - if [ -z "$count" ] || [ "$count" -eq 0 ]; then + if [ -z "$count" ] || [ "$count" -eq 0 ] + then summary="(even with main)" else summary=$(format_commits "$b") diff --git a/.claude/scripts/merge-worktree b/.claude/scripts/merge-worktree index 492e45a..aff8fba 100755 --- a/.claude/scripts/merge-worktree +++ b/.claude/scripts/merge-worktree @@ -13,7 +13,8 @@ set -eu branch="${1:-}" -if [ -z "$branch" ]; then +if [ -z "$branch" ] +then echo "Usage: merge-worktree " >&2 exit 1 fi @@ -22,19 +23,22 @@ PROJECT_DIR="${CLAUDE_PROJECT_DIR:-$(pwd)}" # Validate branch. if ! $HOME/.guix-home/profile/bin/git -C "$PROJECT_DIR" rev-parse \ - --verify "$branch" >/dev/null 2>&1; then + --verify "$branch" >/dev/null 2>&1 +then echo "Error: Branch '$branch' does not exist." >&2 exit 1 fi -if [ "$branch" = "main" ]; then +if [ "$branch" = "main" ] +then echo "Error: Cannot merge main into itself." >&2 exit 1 fi # Check main worktree is clean. if [ -n "$($HOME/.guix-home/profile/bin/git -C "$PROJECT_DIR" \ - status --porcelain --untracked-files=no)" ]; then + status --porcelain --untracked-files=no)" ] +then echo "Error: Main worktree has uncommitted changes." >&2 echo " Commit or stash them first." >&2 exit 1 @@ -51,7 +55,8 @@ $HOME/.guix-home/profile/bin/git -C "$PROJECT_DIR" fetch origin # Rebase branch onto main. echo "=== Rebasing $branch onto main ===" if ! $HOME/.guix-home/profile/bin/git -C "$PROJECT_DIR" \ - rebase main "$branch"; then + rebase main "$branch" +then rc=$? echo "Error: Rebase failed (conflicts)." >&2 echo " Resolve them in the main worktree:" >&2 @@ -71,7 +76,8 @@ $HOME/.guix-home/profile/bin/git -C "$PROJECT_DIR" checkout main # Fast-forward merge. echo "=== Merging $branch into main (fast-forward) ===" if ! $HOME/.guix-home/profile/bin/git -C "$PROJECT_DIR" \ - merge --ff-only "$branch"; then + merge --ff-only "$branch" +then rc=$? echo "Error: Fast-forward merge failed." >&2 echo " This should not happen after a successful rebase." >&2 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