Skip to content

Commit ced9e5b

Browse files
committed
fix(claude-code): handle missing trailing newline and fix directory ownership
Ensure rc files end with a newline before appending alias to prevent concatenation onto the previous line. Chown fish config directories individually so non-root users can manage their fish config.
1 parent cc08fcd commit ced9e5b

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/claude-code/install.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ if [ "${YOLOALIAS:-false}" = "true" ]; then
7070
fi
7171

7272
touch "$rc_file"
73+
# Ensure the file ends with a newline before appending
74+
if [ -s "$rc_file" ] && [ "$(tail -c 1 "$rc_file" | wc -l)" -eq 0 ]; then
75+
printf '\n' >> "$rc_file"
76+
fi
7377
printf '%s\n' "$alias_cmd" >> "$rc_file"
7478
}
7579

@@ -82,6 +86,7 @@ if [ "${YOLOALIAS:-false}" = "true" ]; then
8286
# fish — create a function file (idiomatic for fish)
8387
FISH_FUNC_DIR="$TARGET_HOME/.config/fish/functions"
8488
FISH_FUNC_FILE="$FISH_FUNC_DIR/yolo.fish"
89+
FISH_CREATED=false
8590
if [ -f "$FISH_FUNC_FILE" ]; then
8691
echo "Skipping $FISH_FUNC_FILE: function already exists."
8792
else
@@ -91,12 +96,15 @@ function yolo --description "claude --allow-dangerously-skip-permissions"
9196
claude --allow-dangerously-skip-permissions $argv
9297
end
9398
FISHEOF
99+
FISH_CREATED=true
94100
fi
95101

96102
# Fix ownership if installing for non-root user
97103
if [ -n "$_REMOTE_USER" ] && [ "$_REMOTE_USER" != "root" ]; then
98104
chown "$_REMOTE_USER" "$TARGET_HOME/.bashrc" "$TARGET_HOME/.zshrc"
99-
chown "$_REMOTE_USER" "$FISH_FUNC_FILE"
105+
if [ "$FISH_CREATED" = true ]; then
106+
chown "$_REMOTE_USER" "$TARGET_HOME/.config" "$TARGET_HOME/.config/fish" "$FISH_FUNC_DIR" "$FISH_FUNC_FILE"
107+
fi
100108
fi
101109

102110
echo "yolo alias configured for bash, zsh, and fish."

test/claude-code/claude_code_yolo_alias_with_custom_user.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ check "yolo alias in zshrc" bash -c "grep -Fq 'claude --allow-dangerously-skip-p
1515
check "fish yolo function body" bash -c "test -f ~/.config/fish/functions/yolo.fish && grep -Fq 'claude --allow-dangerously-skip-permissions' ~/.config/fish/functions/yolo.fish"
1616
check "bashrc owned by current user" bash -c "test \"$(stat -c '%U' ~/.bashrc)\" = \"$(whoami)\""
1717
check "zshrc owned by current user" bash -c "test \"$(stat -c '%U' ~/.zshrc)\" = \"$(whoami)\""
18+
check "fish functions dir owned by current user" bash -c "test \"$(stat -c '%U' ~/.config/fish/functions)\" = \"$(whoami)\""
1819
check "fish function owned by current user" bash -c "test \"$(stat -c '%U' ~/.config/fish/functions/yolo.fish)\" = \"$(whoami)\""
1920
check "yolo resolves in bash" bash -ic "type yolo"
2021

0 commit comments

Comments
 (0)