diff --git a/src/commands/old_cmds.sh b/src/commands/old_cmds.sh index ba7bb8b..0d17385 100644 --- a/src/commands/old_cmds.sh +++ b/src/commands/old_cmds.sh @@ -416,52 +416,6 @@ function atfile.invoke.print() { fi } -function atfile.invoke.toggle_desktop() { - unset desktop_dir - unset mime_dir - - [[ $_os == "haiku" ]] && atfile.die "Not available on Haiku" - [[ $_os == "macos" ]] && atfile.die "Not available on macOS\nThink you could help? See: https://tangled.sh/@zio.sh/atfile/issues/9" - - uid="$(id -u)" - if [[ $uid == 0 ]]; then - desktop_dir="/usr/local/share/applications" - mime_dir="/usr/local/share/mime" - else - desktop_dir="$HOME/.local/share/applications" - mime_dir="$HOME/.local/share/mime" - fi - - desktop_path="$desktop_dir/atfile-handler.desktop" - mkdir -p "$desktop_dir" - mkdir -p "$mime_dir" - - if [[ -f "$desktop_path" ]]; then - atfile.say "Removing '$desktop_path'..." - rm "$desktop_path" - else - atfile.say "Installing '$desktop_path'..." - - echo "[Desktop Entry] -Name=ATFile (Handler) -Description=Handle atfile:/at: URIs with ATFile -Exec=$_prog_path handle %U -Terminal=false -Type=Application -MimeType=x-scheme-handler/at;x-scheme-handler/atfile; -NoDisplay=true" > "$desktop_path" - fi - - if [ -x "$(command -v xdg-mime)" ] &&\ - [ -x "$(command -v update-mime-database)" ]; then - atfile.say "Updating mime database..." - - update-mime-database "$mime_dir" - xdg-mime default atfile-handler.desktop x-scheme-handler/at - xdg-mime default atfile-handler.desktop x-scheme-handler/atfile - fi -} - function atfile.invoke.upload() { file="$1" recipient="$2" diff --git a/src/commands/toggle-desktop.sh b/src/commands/toggle-desktop.sh new file mode 100644 index 0000000..fd6f64b --- /dev/null +++ b/src/commands/toggle-desktop.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +function atfile.toggle_desktop() { + unset desktop_dir + unset mime_dir + + # shellcheck disable=SC2154 + [[ $_os == "haiku" ]] && atfile.die "Not available on Haiku" + [[ $_os == "macos" ]] && atfile.die "Not available on macOS" + + uid="$(id -u)" + if [[ $uid == 0 ]]; then + desktop_dir="/usr/local/share/applications" + mime_dir="/usr/local/share/mime" + else + desktop_dir="$HOME/.local/share/applications" + mime_dir="$HOME/.local/share/mime" + fi + + desktop_path="$desktop_dir/atfile-handler.desktop" + mkdir -p "$desktop_dir" + mkdir -p "$mime_dir" + + if [[ -f "$desktop_path" ]]; then + atfile.say "Removing '$desktop_path'..." + rm "$desktop_path" + else + atfile.say "Installing '$desktop_path'..." + + echo "[Desktop Entry] +Name=ATFile (Handler) +Description=Handle atfile:/at: URIs with ATFile +Exec=$_prog_path handle %U +Terminal=false +Type=Application +MimeType=x-scheme-handler/at;x-scheme-handler/atfile; +NoDisplay=true" > "$desktop_path" + fi + + if [ -x "$(command -v xdg-mime)" ] &&\ + [ -x "$(command -v update-mime-database)" ]; then + atfile.say "Updating mime database..." + + update-mime-database "$mime_dir" + xdg-mime default atfile-handler.desktop x-scheme-handler/at + xdg-mime default atfile-handler.desktop x-scheme-handler/atfile + fi +} diff --git a/src/commands/token.sh b/src/commands/token.sh index 034f0db..26dc37d 100644 --- a/src/commands/token.sh +++ b/src/commands/token.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -function atfile.invoke.token() { +function atfile.token() { atfile.xrpc.pds.jwt } diff --git a/src/shared/invoke.sh b/src/shared/invoke.sh index 21b92c3..4b4daf3 100644 --- a/src/shared/invoke.sh +++ b/src/shared/invoke.sh @@ -139,10 +139,10 @@ function atfile.invoke() { atfile.stream "${args[0]}" "${args[1]}" "${args[2]}" "${args[3]}" ;; "token") - atfile.invoke.token + atfile.token ;; "toggle-mime") - atfile.invoke.toggle_desktop + atfile.toggle_desktop ;; "upload") atfile.util.check_prog_optional_metadata