@@ -65,26 +65,39 @@ Working with packages:
6565EOF
6666 fi
6767
68- # Create acode CLI tool
69- if [ ! -e " $PREFIX /alpine/usr/local/bin/acode" ]; then
70- mkdir -p " $PREFIX /alpine/usr/local/bin"
71- cat << 'ACODE_CLI ' > "$PREFIX/alpine/usr/local/bin/acode"
68+ # Refresh the Acode CLI bridge only when its generated content changes.
69+ mkdir -p " $PREFIX /alpine/usr/local/bin"
70+ acode_cli_path=" $PREFIX /alpine/usr/local/bin/acode"
71+ acode_cli_tmp=" $PREFIX /alpine/usr/local/bin/.acode.tmp"
72+ cat << 'ACODE_CLI ' > "$acode_cli_tmp"
7273#!/bin/bash
7374# acode - Open files/folders in Acode editor
7475# Uses OSC escape sequences to communicate with the Acode terminal
7576
7677usage() {
7778 echo "Usage: acode [file/folder...]"
7879 echo ""
79- echo "Open files or folders in Acode editor ."
80+ echo "Open files, folders, or URLs in Acode."
8081 echo ""
8182 echo "Examples:"
8283 echo " acode file.txt # Open a file"
8384 echo " acode . # Open current folder"
8485 echo " acode ~/project # Open a folder"
86+ echo " acode https://... # Open a URL"
8587 echo " acode -h, --help # Show this help"
8688}
8789
90+ is_url() {
91+ case "$1" in
92+ http://*|https://*|ftp://*|ftps://*|mailto:*|tel:*|sms:*|geo:*)
93+ return 0
94+ ;;
95+ *)
96+ return 1
97+ ;;
98+ esac
99+ }
100+
88101get_abs_path() {
89102 local path="$1"
90103 local abs_path=""
@@ -121,6 +134,13 @@ open_in_acode() {
121134 printf '\e]7777;open;%s;%s\a' "$type" "$path"
122135}
123136
137+ open_url_in_acode() {
138+ # Headless consumers like ACP auth can poll this file when no terminal is
139+ # available to intercept OSC output.
140+ printf '%s\n' "$1" > /tmp/.acode_open_url
141+ printf '\e]7777;open;%s;%s\a' "url" "$1"
142+ }
143+
124144if [[ $# -eq 0 ]]; then
125145 open_in_acode "."
126146 exit 0
@@ -133,19 +153,28 @@ for arg in "$@"; do
133153 exit 0
134154 ;;
135155 *)
136- if [[ -e "$arg" ]]; then
156+ if is_url "$arg"; then
157+ open_url_in_acode "$arg"
158+ elif [[ -e "$arg" ]]; then
137159 open_in_acode "$arg"
138160 else
139- echo "Error: '$arg' does not exist" >&2
161+ echo "Error: '$arg' does not exist or is not a supported URL " >&2
140162 exit 1
141163 fi
142164 ;;
143165 esac
144166done
145167ACODE_CLI
146- chmod +x " $PREFIX /alpine/usr/local/bin/acode"
168+ if [ ! -e " $acode_cli_path " ] || ! cmp -s " $acode_cli_tmp " " $acode_cli_path " ; then
169+ mv " $acode_cli_tmp " " $acode_cli_path "
170+ chmod +x " $acode_cli_path "
171+ else
172+ rm -f " $acode_cli_tmp "
147173 fi
148174
175+ # Make xdg-open use the Acode CLI bridge inside the terminal environment.
176+ ln -sfn acode " $PREFIX /alpine/usr/local/bin/xdg-open"
177+
149178 # Create initrc if it doesn't exist
150179 # initrc runs in bash so we can use bash features
151180if [ ! -e " $PREFIX /alpine/initrc" ]; then
0 commit comments