aboutsummaryrefslogtreecommitdiff
path: root/scripts/bin
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/bin')
-rwxr-xr-xscripts/bin/ai48
-rwxr-xr-xscripts/bin/cbedit2
-rwxr-xr-xscripts/bin/file-manager2
-rwxr-xr-xscripts/bin/kman3
-rwxr-xr-xscripts/bin/open2
-rwxr-xr-xscripts/bin/tts23
6 files changed, 77 insertions, 3 deletions
diff --git a/scripts/bin/ai b/scripts/bin/ai
new file mode 100755
index 0000000..eb264ea
--- /dev/null
+++ b/scripts/bin/ai
@@ -0,0 +1,48 @@
+#!/usr/bin/env sh
+
+set -e -o pipefail
+
+AI_API_URL=${AI_API_URL:-"http://localhost:9081"}
+AI_API_KEY=${AI_API_KEY:-"no-key"}
+
+system_prompt="
+When responding with code, you are a senior software engineer, output only the raw code, without any enclosing markdown code blocks. Output only the final code. Do not include backticks, comments, or explanations.
+Do not include \`\`\` or any surrounding formatting. If you add anything other than code, you have failed.
+When responding with content, be concise.
+Do not hallucinate facts and respond with accurate information as much as possible.
+If you don't know, just say so. If you are not sure, ask for clarification.
+If the context appears unreadable or of poor quality, tell the user then answer as best as you can.
+"
+
+call_completion() {
+ local opts='"stream": true'
+ local payload="{\"messages\": $1, $opts }"
+ curl --silent --no-buffer \
+ -XPOST "$AI_API_URL/v1/chat/completions" \
+ -H "Content-Type: application/json" \
+ -H "Authorization: Bearer $AI_API_KEY" \
+ --data "$payload" \
+ | tee "$HOME/.local/state/local-ai-last-response" \
+ | stdbuf -oL sed -E 's/^data:\s*//; /^$/d' \
+ | while IFS= read -r line; do
+ printf "%s" "$line" | jq -rj '.choices[0].delta.content // ""' 2>/dev/null || true
+ done;
+}
+
+arg_prompt="$1"
+stdin=""
+if ! [ -t 0 ];
+ then stdin="$(cat)";
+fi
+
+# Start llama server if not started already
+# from: modules/ai/default.nix
+llama-start-server-background
+
+# Call completion api
+call_completion "$(jq -n \
+ --arg system "$system_prompt" \
+ --arg user "$arg_prompt" \
+ --arg user_supplement "$stdin" \
+ '[{ role: "system", content: $system }, { role: "user", content: $user }, { role: "user", content: $user_supplement }]')"
+
diff --git a/scripts/bin/cbedit b/scripts/bin/cbedit
index f4d88fd..b163ecb 100755
--- a/scripts/bin/cbedit
+++ b/scripts/bin/cbedit
@@ -4,7 +4,7 @@ set -e;
read_clipboard() { xclip -selection clipboard -o || echo -n ""; }
update_clipboard() { xclip -selection clipboard -i; }
-edit_file() { st -e nvim "$@"; }
+edit_file() { st -e sensible-editor "$@"; }
tmp_file=$(mktemp /tmp/cbedit-XXXXX);
read_clipboard > $tmp_file;
diff --git a/scripts/bin/file-manager b/scripts/bin/file-manager
index 467d346..016818e 100755
--- a/scripts/bin/file-manager
+++ b/scripts/bin/file-manager
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
-sensible-terminal -d "$1" -e lf
+sensible-terminal -d "$1" -e daffm
diff --git a/scripts/bin/kman b/scripts/bin/kman
new file mode 100755
index 0000000..052d410
--- /dev/null
+++ b/scripts/bin/kman
@@ -0,0 +1,3 @@
+#!/usr/bin/env sh
+
+kak -e "man $@; map global normal q :quit<ret>;"
diff --git a/scripts/bin/open b/scripts/bin/open
index 9daa34a..001d784 100755
--- a/scripts/bin/open
+++ b/scripts/bin/open
@@ -13,7 +13,7 @@ open_by_mimetype() {
echo "Opening $file ($mime)...";
case "$mime" in
- inode/directory) lf "$file" ;;
+ inode/directory) daffm "$file" ;;
application/x-bittorrent) ~/scripts/torrent.sh torrent "$file" ;;
diff --git a/scripts/bin/tts b/scripts/bin/tts
new file mode 100755
index 0000000..ecb4ee2
--- /dev/null
+++ b/scripts/bin/tts
@@ -0,0 +1,23 @@
+#!/usr/bin/env sh
+
+set -e -o pipefail
+
+TTS_MODELS_PATH="$HOME/.config/piper-models"
+
+playaudio() {
+ ffplay -nodisp -autoexit -f s16le -ar 22050 -
+}
+
+text2speech() {
+ # https://huggingface.co/rhasspy/piper-voices/tree/main/en/en_US
+ local tts_model="en_US-lessac-medium.onnx";
+ # local tts_model="en_US-ryan-high.onnx";
+ # local tts_model="en_US-bryce-medium.onnx";
+ local tts_model_path="$TTS_MODELS_PATH/$tts_model";
+ [ -f "$tts_model_path" ] || (echo "Model not found" && exit 1);
+
+ piper --model "$tts_model_path" --sentence_silence 0.4 --output-raw | playaudio
+}
+
+text2speech;
+