Skip to content

Commit d922564

Browse files
committed
aichat: apply changes by using pipe command instead of sed
1 parent dae528b commit d922564

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

.helix-wezterm.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
actions:
22
ai:
33
position: right
4-
command: pbpaste | aichat --code --session "$session" $(gum input --placeholder "prompt") && gum confirm "Accept suggestion?" && aichat --session "$session" --info | yq '.messages | map(select(.role == "assistant")) | .[-1].content' | gsed -i "${cursor_line}r /dev/stdin" $buffer_name && bash -x helix-reload.sh $WEZTERM_PANE
4+
command: cat /tmp/aichat | HX_PANE_ID=$WEZTERM_PANE hxide-aichat.sh "$session"
55
blame:
66
description: Show blame for the current file and line number
77
command: tig blame $buffer_name +$cursor_line

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,5 @@ p = ":sh helix-wezterm.sh present %{buffer_name}"
9999
t = ":sh helix-wezterm.sh test %{buffer_name}"
100100
101101
[keys.select.";"]
102-
a = [
103-
"yank_to_clipboard",
104-
":sh helix-wezterm.sh ai %{buffer_name}"
105-
]
102+
a = ":sh echo '%{selection}' > /tmp/aichat; helix-wezterm.sh ai %{buffer_name}"
106103
```

helix-reload.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

helix-wezterm.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ command=$(yq e ".actions.$action.command" "$config_file")
4848

4949
case "$action" in
5050
"ai")
51+
export selection=$(cat)
5152
export session=$(basename "$pwd")_$(echo "$buffer_name" | tr "/" "_")
5253
;;
5354
"mock")
@@ -155,6 +156,6 @@ if [ "$act" != "null" ]; then
155156
command=$(yq e ".actions.$action.extensions.$extension" "$config_file")
156157
fi
157158

158-
expanded_command=$(echo $command | envsubst '$WEZTERM_PANE,$basedir,$binary_output,$buffer_name,$cursor_line,$interface_name,$test_name,$session,$entry')
159+
expanded_command=$(echo $command | envsubst '$WEZTERM_PANE,$basedir,$binary_output,$buffer_name,$cursor_line,$selection,$interface_name,$test_name,$session,$entry')
159160
echo "$expanded_command\r" | $send_to_pane
160161
fi

hxide-aichat-last-reply.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#/usr/bin/env bash
2+
3+
session=$1
4+
aichat --session "$session" --info | yq '.messages | map(select(.role == "assistant")) | .[-1].content' | awk '/^```/{f=!f; next} f'

hxide-aichat.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#/usr/bin/env bash
2+
3+
selection=$(cat)
4+
session=$1
5+
6+
while true; do
7+
prompt="$(gum input --placeholder 'Ask anything')"
8+
if [ $? -ne 0 ]; then
9+
exit 0
10+
fi
11+
12+
echo "$selection" | aichat --code --session "$session" "$prompt" || exit 1
13+
14+
echo
15+
16+
gum confirm "Accept suggestion?" --default=No
17+
exit_code=$?
18+
19+
if [ $exit_code -eq 0 ]; then
20+
break
21+
elif [ $exit_code -eq 1 ]; then
22+
continue
23+
else
24+
exit 0
25+
fi
26+
done
27+
28+
wezterm cli send-text --pane-id $HX_PANE_ID --no-paste -- ":"
29+
wezterm cli send-text --pane-id $HX_PANE_ID -- "pipe hxide-aichat-last-reply.sh $session"
30+
printf "\r" | wezterm cli send-text --pane-id $HX_PANE_ID --no-paste

0 commit comments

Comments
 (0)