From 08be7b1683da94cfb2e435b63b0fbd6840ad7a8d Mon Sep 17 00:00:00 2001 From: Benjamin Lupton Date: Wed, 6 Dec 2023 12:39:49 +0800 Subject: [PATCH] fix noisy app detection on headless environments /close #192 --- commands/edit | 4 ++-- commands/get-app | 13 +++++++++++-- commands/git-helper | 10 +++++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/commands/edit b/commands/edit index 1528c3b32..9266130d2 100755 --- a/commands/edit +++ b/commands/edit @@ -119,7 +119,7 @@ function edit_() ( # grab options local editors=() - if test "$terminal" = 'yes' -o "$sudo" = 'yes'; then + if test "$terminal" = 'yes'; then editors=("${TERMINAL_EDITORS[@]}") else editors=("${GUI_EDITORS[@]}") @@ -159,7 +159,7 @@ function edit_() ( # it exists, use it break - elif get-app "$command" >/dev/null; then + elif test "$terminal" = 'no' && get-app "$command" >/dev/null; then # apps require prompts if test "$prompt" = 'yes'; then mapfile -t array < <(echo-split ' ' -- "$string") diff --git a/commands/get-app b/commands/get-app index 6a030acb8..d5c43ec7f 100755 --- a/commands/get-app +++ b/commands/get-app @@ -106,13 +106,22 @@ function get_app() ( fi fi if test "$can_find" = 'no'; then - echo-error 'Install Winget or Scoop to be able to detect applications on WSL' + if test "$quiet" != 'yes'; then + echo-error "Unable to detect application [$name] on WSL. Install Winget or Scoop." + fi return 6 # ENXIO 6 Device not configured fi # wasn't found return 1 + elif is-headless; then + if test "$quiet" != 'yes'; then + echo-style --notice="Skipping detection of application [$name] on headless system." >/dev/stderr + fi + return 1 else - echo-error 'Support for Applications not added yet for this platform.' + if test "$quiet" != 'yes'; then + echo-error "Unable to detect application [$name] on Linux. Submit a PR to support it." + fi return 19 # ENODEV 19 Operation not supported by device fi ) diff --git a/commands/git-helper b/commands/git-helper index 516394afe..77d4a3a03 100755 --- a/commands/git-helper +++ b/commands/git-helper @@ -466,14 +466,14 @@ function git_helper() ( } function git_review { - if get-app --quiet 'Gitfox.app'; then - open-app 'Gitfox.app' -- "$@" - elif get-app --quiet 'Tower.app'; then - open-app 'Tower.app' -- "$@" - elif command-exists gf; then + if command-exists gf; then gf "$@" + elif get-app --quiet 'Gitfox.app'; then + open-app 'Gitfox.app' -- "$@" elif command-exists tower; then tower "$@" + elif get-app --quiet 'Tower.app'; then + open-app 'Tower.app' -- "$@" else help "No supported git reviewers installed." fi