summaryrefslogtreecommitdiff
path: root/ar/.local/bin/gpt
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-24 20:35:27 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-01-24 20:35:27 +0900
commitc80a54e42b52ce297f0f2f71af23c562832025c7 (patch)
treedcce8bb977a770f473325d48f6f70b21d9818a40 /ar/.local/bin/gpt
init
Diffstat (limited to 'ar/.local/bin/gpt')
-rwxr-xr-xar/.local/bin/gpt26
1 files changed, 26 insertions, 0 deletions
diff --git a/ar/.local/bin/gpt b/ar/.local/bin/gpt
new file mode 100755
index 0000000..393916a
--- /dev/null
+++ b/ar/.local/bin/gpt
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+set -e
+
+# Check if input is piped
+if [ -t 0 ]; then
+ input="$1"
+else
+ input=$(cat | sed -E "s/\x1b\[[0-9;]*m//g")
+fi
+
+# Use a temporary file for the processed content
+tmpfile=$(mktemp /tmp/nvim_buffer_cleaned.XXXXXX)
+
+# Save the input to the temporary file
+echo "$input" >"$tmpfile"
+
+# Process the input and open Neovim directly, ensuring it doesn't suspend
+nvim \
+ -c "GpChatNew" \
+ -c "call append(line('\$')-1, readfile('$tmpfile'))" \
+ -c "normal! Gdd" \
+ -c "startinsert"
+
+# Remove the temporary file after usage
+rm "$tmpfile"