]> git.ekhem.eu.org Git - guix.git/commitdiff
[style] Separate then from if in shell scripts.
authorJakub Czajka <jakub@ekhem.eu.org>
Tue, 7 Jul 2026 15:11:14 +0000 (17:11 +0200)
committerJakub Czajka <jakub@ekhem.eu.org>
Thu, 9 Jul 2026 12:34:55 +0000 (14:34 +0200)
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.

14 files changed:
.claude/hooks/block-worktrees
.claude/hooks/create-worktree
.claude/hooks/guix-build
.claude/hooks/guix-check
.claude/hooks/notify
.claude/hooks/status-line
.claude/scripts/ask-build-queue
.claude/scripts/branch-summary
.claude/scripts/merge-worktree
autorandr/.config/autorandr/postswitch
bash/.bash_profile
bash/.config/profile.d/50-bash.sh
claude/.local/bin/get-api-key
scripts/status_bar

index 7cec6cf78c100cb6195d5862d1dcddc1b6743ac8..0d6c25c67d31efd7e45508de7bf0b25c53e13336 100755 (executable)
@@ -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
 
index a5bd6e31479accda278f19b6d6568955943122e0..cf996ff706f830a84a7555c6f8c1fcf36de42beb 100755 (executable)
@@ -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
 
index 59ab6b4b991353dd55d928d9038b8f21499cd7f5..911b847384a8557e618541a520afb4687e1c927d 100755 (executable)
@@ -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
index 19c540298b9e07e18e6021413a0a03bdf5fbc515..43c30af10703e0ce4fe3c82d6740e415baad5e23 100755 (executable)
@@ -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 ""
index 4a9ef55b58eae909ca7cea9a6be713c668a66bc1..f143e5789a7555ab4dd7a6b1edc6b1b6cba1b86f 100755 (executable)
@@ -2,7 +2,7 @@
 # Copyright (c) 2026 Jakub Czajka <jakub@ekhem.eu.org>
 # 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')
index 3475173fff968611e9737eff344a2a45463d60be..da4370b5fcfc93f775a50af284ce7b150f57d162 100755 (executable)
@@ -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)
index 46d57833fb80edf0d251966b78a4d9d1961318bd..7fa39ea470d86ec1ccf33bd2ac50c428f117c85f 100755 (executable)
@@ -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"
index 0623773c0b8e36ad3832723eccea162ab498bbdf..2da0ddfeed1b1163ff6e033139f43d2728628927 100755 (executable)
@@ -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")
index 492e45a345823aa19fa95733203dd67718a673c3..aff8fba72674273b3381240b09b14e7659ba581e 100755 (executable)
@@ -13,7 +13,8 @@
 set -eu
 
 branch="${1:-}"
-if [ -z "$branch" ]; then
+if [ -z "$branch" ]
+then
     echo "Usage: merge-worktree <branch-name>" >&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
index 3f12230fb9ab6b1a5ed52a8e038ed373568aa224..e8a0b53521740c44c0aa41b41c4c6e25fd885a28 100755 (executable)
@@ -4,7 +4,8 @@
 #
 # postswitch - Script executed after the layout switch.
 
-if [ `which wallpaper` ]; then
+if [ `which wallpaper` ]
+then
     wallpaper
 fi
 
index 13aa1ee53d6189fa398837f6ee5946446e697e6f..789ec40b26954f5ced87d0acd45dab3dd74aacfa 100644 (file)
@@ -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
 
index 6b7be622c02efc5869c367306958c096ae267581..c2b2698102bb0fc4efed14a09cd7ce8c1bb51c4b 100644 (file)
@@ -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
 
index c42ed7d75eeee251333cdc630142b4b540f8e14a..8325980bf3daad696a9d8948f355d13e9ce4fda1 100755 (executable)
@@ -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 \
index 7cc06455c4e5ab4d3b81b56e4c7045e5f5e358a2..625aea593b5524cdb6e4ba4574bf7f707d74b0cb 100755 (executable)
@@ -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}"