···11+#!/usr/bin/env bash
22+33+function atfile.handle() {
44+ uri="$1"
55+ handler="$2"
66+77+ function atfile.handle.is_temp_file_needed() {
88+ handler="${1//.desktop/}"
99+ type="$2"
1010+1111+ handlers=(
1212+ "app.drey.EarTag"
1313+ "com.github.neithern.g4music"
1414+ )
1515+1616+ if [[ ${handlers[*]} =~ $handler ]]; then
1717+ echo 1
1818+ elif [[ $type == "text/"* ]]; then
1919+ echo 1
2020+ else
2121+ echo 0
2222+ fi
2323+ }
2424+2525+ [[ $_output_json == 1 ]] && atfile.die "Command not available as JSON"
2626+2727+ actor="$(echo "$uri" | cut -d "/" -f 3)"
2828+ key="$(echo "$uri" | cut -d "/" -f 4)"
2929+3030+ atfile.util.create_dir "$_path_blobs_tmp"
3131+3232+ if [[ -n "$actor" && -n "$key" ]]; then
3333+ atfile.util.override_actor "$actor"
3434+3535+ atfile.say.debug "Getting record...\nโณ NSID: $_nsid_upload\nโณ Repo: $_username\nโณ Key: $key"
3636+ record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")"
3737+ error="$(atfile.util.get_xrpc_error $? "$record")"
3838+ [[ -n "$error" ]] && atfile.die.gui.xrpc_error "Unable to get '$key'" "$error"
3939+4040+ blob_cid="$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")"
4141+ blob_uri="$(atfile.util.build_blob_uri "$_username" "$blob_cid")"
4242+ file_type="$(echo "$record" | jq -r '.value.file.mimeType')"
4343+4444+ if [[ $_os == "linux"* ]] && \
4545+ [ -x "$(command -v xdg-mime)" ] && \
4646+ [ -x "$(command -v xdg-open)" ] && \
4747+ [ -x "$(command -v gtk-launch)" ]; then
4848+4949+ # HACK: Open with browser if $file_type isn't set
5050+ [[ -z $file_type ]] && file_type="text/html"
5151+5252+ if [[ -z $handler ]]; then
5353+ atfile.say.debug "Querying for handler '$file_type'..."
5454+ handler="$(xdg-mime query default "$file_type")"
5555+ else
5656+ handler="$handler.desktop"
5757+ atfile.say.debug "Handler manually set to '$handler'"
5858+ fi
5959+6060+ # shellcheck disable=SC2319
6161+ # shellcheck disable=SC2181
6262+ if [[ -n $handler ]] || [[ $? != 0 ]]; then
6363+ atfile.say.debug "Opening '$key' ($file_type) with '${handler//.desktop/}'..."
6464+6565+ # HACK: Some apps don't like http(s)://; we'll need to handle these
6666+ if [[ $(atfile.handle.is_temp_file_needed "$handler" "$file_type") == 1 ]]; then
6767+ atfile.say.debug "Unsupported for streaming"
6868+6969+ download_success=1
7070+ # shellcheck disable=SC2154
7171+ tmp_path="$_path_blobs_tmp/$blob_cid"
7272+7373+ if ! [[ -f "$tmp_path" ]]; then
7474+ atfile.say.debug "Downloading '$blob_cid'..."
7575+ atfile.http.download "$blob_uri" "$tmp_path"
7676+ [[ $? != 0 ]] && download_success=0
7777+ else
7878+ atfile.say.debug "Blob '$blob_cid' already exists"
7979+ fi
8080+8181+ if [[ $download_success == 1 ]]; then
8282+ atfile.say.debug "Launching '$handler'..."
8383+ gtk-launch "$handler" "$tmp_path" </dev/null &>/dev/null &
8484+ else
8585+ atfile.die.gui \
8686+ "Unable to download '$key'"
8787+ fi
8888+ else
8989+ atfile.say.debug "Launching '$handler'..."
9090+ gtk-launch "$handler" "$blob_uri" </dev/null &>/dev/null &
9191+ fi
9292+ else
9393+ atfile.say.debug "No handler for '$file_type'. Launching URI..."
9494+ atfile.util.launch_uri "$blob_uri"
9595+ fi
9696+ else
9797+ atfile.say.debug "Relevant tools not installed. Launching URI..."
9898+ atfile.util.launch_uri "$blob_uri"
9999+ fi
100100+ else
101101+ atfile.die.gui \
102102+ "Invalid ATFile URI\nโณ Must be 'atfile://<actor>/<key>'" \
103103+ "Invalid ATFile URI"
104104+ fi
105105+}
+1-2
src/commands/help.sh
···7575 bsky [<actor>]
7676 Get Bluesky profile for <actor>\n
7777 handle <at-uri>
7878- Open at:// URI with relevant App\n
7878+ Open at:// URI with PDSls\n
7979 handle <atfile-uri> [<handler>]
8080 Open atfile:// URI with relevant App
8181 โน๏ธ Set <handler> to a .desktop entry (with '.desktop') to force the
···191191192192Usage
193193 $_prog <command> [<arguments>]
194194- $_prog at://<actor>[/<collection>/<rkey>]
195194 $_prog atfile://<actor>/<key>\n\n"
196195197196 [[ $ATFILE_DEVEL == 1 ]] && usage+="$usage_commands_devel\n\n"
-128
src/commands/old_cmds.sh
···289289 fi
290290}
291291292292-function atfile.invoke.handle_atfile() {
293293- uri="$1"
294294- handler="$2"
295295-296296- function atfile.invoke.handle_atfile.is_temp_file_needed() {
297297- handler="${1//.desktop/}"
298298- type="$2"
299299-300300- handlers=(
301301- "app.drey.EarTag"
302302- "com.github.neithern.g4music"
303303- )
304304-305305- if [[ ${handlers[*]} =~ $handler ]]; then
306306- echo 1
307307- elif [[ $type == "text/"* ]]; then
308308- echo 1
309309- else
310310- echo 0
311311- fi
312312- }
313313-314314- [[ $_output_json == 1 ]] && atfile.die "Command not available as JSON"
315315-316316- actor="$(echo "$uri" | cut -d "/" -f 3)"
317317- key="$(echo "$uri" | cut -d "/" -f 4)"
318318-319319- atfile.util.create_dir "$_path_blobs_tmp"
320320-321321- if [[ -n "$actor" && -n "$key" ]]; then
322322- atfile.util.override_actor "$actor"
323323-324324- atfile.say.debug "Getting record...\nโณ NSID: $_nsid_upload\nโณ Repo: $_username\nโณ Key: $key"
325325- record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")"
326326- error="$(atfile.util.get_xrpc_error $? "$record")"
327327- [[ -n "$error" ]] && atfile.die.gui.xrpc_error "Unable to get '$key'" "$error"
328328-329329- blob_cid="$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")"
330330- blob_uri="$(atfile.util.build_blob_uri "$_username" "$blob_cid")"
331331- file_type="$(echo "$record" | jq -r '.value.file.mimeType')"
332332-333333- if [[ $_os == "linux"* ]] && \
334334- [ -x "$(command -v xdg-mime)" ] && \
335335- [ -x "$(command -v xdg-open)" ] && \
336336- [ -x "$(command -v gtk-launch)" ]; then
337337-338338- # HACK: Open with browser if $file_type isn't set
339339- [[ -z $file_type ]] && file_type="text/html"
340340-341341- if [[ -z $handler ]]; then
342342- atfile.say.debug "Querying for handler '$file_type'..."
343343- handler="$(xdg-mime query default "$file_type")"
344344- else
345345- handler="$handler.desktop"
346346- atfile.say.debug "Handler manually set to '$handler'"
347347- fi
348348-349349- # shellcheck disable=SC2319
350350- # shellcheck disable=SC2181
351351- if [[ -n $handler ]] || [[ $? != 0 ]]; then
352352- atfile.say.debug "Opening '$key' ($file_type) with '${handler//.desktop/}'..."
353353-354354- # HACK: Some apps don't like http(s)://; we'll need to handle these
355355- if [[ $(atfile.invoke.handle_atfile.is_temp_file_needed "$handler" "$file_type") == 1 ]]; then
356356- atfile.say.debug "Unsupported for streaming"
357357-358358- download_success=1
359359- # shellcheck disable=SC2154
360360- tmp_path="$_path_blobs_tmp/$blob_cid"
361361-362362- if ! [[ -f "$tmp_path" ]]; then
363363- atfile.say.debug "Downloading '$blob_cid'..."
364364- atfile.http.download "$blob_uri" "$tmp_path"
365365- [[ $? != 0 ]] && download_success=0
366366- else
367367- atfile.say.debug "Blob '$blob_cid' already exists"
368368- fi
369369-370370- if [[ $download_success == 1 ]]; then
371371- atfile.say.debug "Launching '$handler'..."
372372- gtk-launch "$handler" "$tmp_path" </dev/null &>/dev/null &
373373- else
374374- atfile.die.gui \
375375- "Unable to download '$key'"
376376- fi
377377- else
378378- atfile.say.debug "Launching '$handler'..."
379379- gtk-launch "$handler" "$blob_uri" </dev/null &>/dev/null &
380380- fi
381381- else
382382- atfile.say.debug "No handler for '$file_type'. Launching URI..."
383383- atfile.util.launch_uri "$blob_uri"
384384- fi
385385- else
386386- atfile.say.debug "Relevant tools not installed. Launching URI..."
387387- atfile.util.launch_uri "$blob_uri"
388388- fi
389389- else
390390- atfile.die.gui \
391391- "Invalid ATFile URI\nโณ Must be 'atfile://<actor>/<key>'" \
392392- "Invalid ATFile URI"
393393- fi
394394-}
395395-396396-function atfile.invoke.handle_aturi() {
397397- uri="$1"
398398-399399- [[ $_output_json == 1 ]] && atfile.die "Command not available as JSON"
400400- [[ "$uri" != "at://"* ]] && atfile.die.gui \
401401- "Invalid AT URI\nโณ Must be 'at://<actor>[/<collection>/<rkey>]'" \
402402- "Invalid AT URI"
403403-404404- atfile.say.debug "Resolving '$uri'..."
405405- app_uri="$(atfile.util.get_app_url_for_at_uri "$uri")"
406406- [[ -z "$app_uri" ]] && atfile.die.gui \
407407- "Unable to resolve AT URI to App"
408408-409409- app_proto="$(echo "$app_uri" | cut -d ":" -f 1)"
410410-411411- atfile.say.debug "Opening '$app_uri' ($app_proto)..."
412412-413413- if [[ $app_proto == "atfile" ]]; then
414414- atfile.invoke.handle_atfile "$app_uri"
415415- else
416416- atfile.util.launch_uri "$app_uri"
417417- fi
418418-}
419419-420292function atfile.invoke.list() {
421293 cursor="$1"
422294 unset error
+7-15
src/shared/invoke.sh
···6868 uri="${args[0]}"
6969 protocol="$(atfile.util.get_uri_segment "$uri" protocol)"
70707171- if [[ $protocol == "https" ]]; then
7272- http_uri="$uri"
7373- uri="$(atfile.util.map_http_to_at "$http_uri")"
7474-7575- atfile.say.debug "Mapping '$http_uri'..."
7676-7777- if [[ -z "$uri" ]]; then
7878- atfile.die "Unable to map '$http_uri' to at:// URI"
7979- else
8080- protocol="$(atfile.util.get_uri_segment "$uri" protocol)"
8181- fi
8282- fi
8383-8471 atfile.say.debug "Handling protocol '$protocol://'..."
85728673 case $protocol in
8787- "at") atfile.invoke.handle_aturi "$uri" ;;
8888- "atfile") atfile.invoke.handle_atfile "$uri" "${args[1]}" ;;
7474+ "at")
7575+ atfile.say.debug "Launching '$uri' in PDSls..."
7676+ atfile.util.launch_uri "https://pdsls.dev/$uri"
7777+ ;;
7878+ "atfile")
7979+ atfile.handle "$uri" "${args[1]}"
8080+ ;;
8981 esac
9082 ;;
9183 "help")