Conversation
Pulls cmd_rooms + cmd_part + cmd_send_file + cmd_invite + cmd_peers
(413 lines combined) out of the airc top-level into
lib/airc_bash/cmd_rooms.sh.
airc: 2300 → 1898 lines (-402)
lib/airc_bash/cmd_rooms.sh: +441 (413 body + 28 header)
Bundled because in IRC mental model these are all the same conceptual
surface ("what rooms exist? who's in this one? how do I leave/invite/
transfer?"). One domain = one file.
Verified: airc rooms / peers / invite all dispatch correctly.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Refactors the Bash CLI by extracting the “channel/peer” command cluster (rooms/list, part, send-file, invite, peers) out of the airc monolith into a dedicated library script, and updates airc to source it via the existing lib-dir resolver.
Changes:
- Added
lib/airc_bash/cmd_rooms.shcontainingcmd_rooms,cmd_part,cmd_send_file,cmd_invite, andcmd_peersplus small helpers. - Removed the inlined implementations from
aircand replaced them with asourceblock pointing at the new lib file.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| lib/airc_bash/cmd_rooms.sh | New extracted implementation for rooms/part/send-file/invite/peers commands. |
| airc | Sources the new cmd_rooms.sh instead of embedding these commands inline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| local raw; raw=$(gh gist list --limit 50 2>/dev/null \ | ||
| | awk -F'\t' ' | ||
| /airc room:/ { print "room\t" $1 "\t" $2 "\t" $5 } | ||
| /airc invite for/ { print "invite\t" $1 "\t" $2 "\t" $5 } | ||
| ') |
There was a problem hiding this comment.
Because airc runs with set -e, this unguarded command substitution will cause the whole script to exit if gh gist list returns non-zero (e.g., not authenticated / missing gist scope / network error). That can make airc list fail silently since stderr is redirected. Please wrap this in an if raw=$(...) block (or add || true + explicit error handling) so the command can emit a clear message and return a controlled exit code.
| local raw; raw=$(gh gist list --limit 50 2>/dev/null \ | |
| | awk -F'\t' ' | |
| /airc room:/ { print "room\t" $1 "\t" $2 "\t" $5 } | |
| /airc invite for/ { print "invite\t" $1 "\t" $2 "\t" $5 } | |
| ') | |
| local raw | |
| if raw=$(gh gist list --limit 50 2>/dev/null \ | |
| | awk -F'\t' ' | |
| /airc room:/ { print "room\t" $1 "\t" $2 "\t" $5 } | |
| /airc invite for/ { print "invite\t" $1 "\t" $2 "\t" $5 } | |
| '); then | |
| : | |
| else | |
| echo " Failed to list gists from the gh CLI." >&2 | |
| echo " Check that you are authenticated and that gh has gist access." >&2 | |
| return 1 | |
| fi |
| # joiner, just local teardown. Records parted_rooms | ||
| # so re-join doesn't auto-resume. | ||
| # cmd_send_file — host-mediated file transfer to a peer. Pre-pairing- | ||
| # aware: writes to the host's files/<peer>/ dir. |
There was a problem hiding this comment.
The header comment says send-file writes to files/<peer>/, but the implementation writes to files/${my_name}/ (sender). Either adjust the comment to match the actual behavior (as exercised by the integration test expecting files/beta/... on the host) or change the implementation if the destination directory is meant to be keyed by the recipient.
| # aware: writes to the host's files/<peer>/ dir. | |
| # aware: writes to the host's files/<sender>/ dir. |
| scp_out=$(scp -i "$ssh_key" -o StrictHostKeyChecking=accept-new -q "$filepath" "${target_host}:${rhome}/files/${my_name}/${filename}" 2>&1) | ||
| else | ||
| scp_out=$(scp -o StrictHostKeyChecking=accept-new -q "$filepath" "${target_host}:${rhome}/files/${my_name}/${filename}" 2>&1) | ||
| fi | ||
| if [ $? -ne 0 ]; then | ||
| die "Failed to transfer $filename: $scp_out" | ||
| fi |
There was a problem hiding this comment.
With set -e enabled, if scp fails these command substitutions will terminate the script immediately, so the subsequent if [ $? -ne 0 ] check (and the helpful die message) will never run. Capture the exit status using an if scp_out=$(scp ...); then ... else ... pattern (or temporarily disable -e) so failures surface as the intended error message.
| scp_out=$(scp -i "$ssh_key" -o StrictHostKeyChecking=accept-new -q "$filepath" "${target_host}:${rhome}/files/${my_name}/${filename}" 2>&1) | |
| else | |
| scp_out=$(scp -o StrictHostKeyChecking=accept-new -q "$filepath" "${target_host}:${rhome}/files/${my_name}/${filename}" 2>&1) | |
| fi | |
| if [ $? -ne 0 ]; then | |
| die "Failed to transfer $filename: $scp_out" | |
| fi | |
| if scp_out=$(scp -i "$ssh_key" -o StrictHostKeyChecking=accept-new -q "$filepath" "${target_host}:${rhome}/files/${my_name}/${filename}" 2>&1); then | |
| : | |
| else | |
| die "Failed to transfer $filename: $scp_out" | |
| fi | |
| else | |
| if scp_out=$(scp -o StrictHostKeyChecking=accept-new -q "$filepath" "${target_host}:${rhome}/files/${my_name}/${filename}" 2>&1); then | |
| : | |
| else | |
| die "Failed to transfer $filename: $scp_out" | |
| fi | |
| fi |
| local ts="${1:-}" | ||
| local threshold_hours="${AIRC_STALE_HOURS:-24}" | ||
| [ -z "$ts" ] && return 1 | ||
| local epoch; epoch=$(iso_to_epoch "$ts") | ||
| [ -z "$epoch" ] && return 1 | ||
| local now; now=$(date -u +%s) | ||
| local diff=$((now - epoch)) | ||
| [ "$diff" -gt $((threshold_hours * 3600)) ] |
There was a problem hiding this comment.
threshold_hours comes from $AIRC_STALE_HOURS and is used in arithmetic expansion. If it’s unset or non-numeric, $((threshold_hours * 3600)) will raise an arithmetic error and (because airc uses set -e) abort airc list. Consider validating/sanitizing threshold_hours to an integer (fallback to 24) before doing arithmetic.
| else | ||
| echo "ERROR: airc_bash/cmd_rooms.sh not found via lib-dir resolver." >&2 | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
This source failure path is less actionable than the other lib extraction blocks (which print the resolved lib_dir and suggest reinstalling/checking AIRC_DIR). Consider including ${_airc_lib_dir:-<empty>} in the error output and a next-step hint to make failures easier to debug.
Pulls cmd_rooms + cmd_part + cmd_send_file + cmd_invite + cmd_peers (413 lines) into lib/airc_bash/cmd_rooms.sh. airc: 2300 → 1898 (-402). Stacks alongside merged #213-#219.