From 711172dca9d5cb764688941aa58be1e2894fe134 Mon Sep 17 00:00:00 2001 From: urosm Date: Sat, 21 Sep 2024 18:05:52 +0200 Subject: [PATCH] xdg-open: bugfix and simplify --- .local/bin/xdg-open | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.local/bin/xdg-open b/.local/bin/xdg-open index fa6f764..9328c2d 100755 --- a/.local/bin/xdg-open +++ b/.local/bin/xdg-open @@ -1,17 +1,17 @@ #!/bin/sh -[ -z "$1" ] && exit - -FILEPATH="$(realpath "$1")" - -case "$(file -i "$FILEPATH")" in - ${FILEPATH}:\ text/*) - DIRPATH="$(dirname "$FILEPATH")" +case "$(file -i "$1" 2>/dev/null)" in + *": text/"* | *": application/javascript"*) + DIRPATH="$(dirname "$1")" while :; do + [ "$DIRPATH" = "/" ] && DIRPATH=$HOME [ "$DIRPATH" = "$HOME" ] || [ -n "$(find "$DIRPATH" ! -path "$DIRPATH" -prune -type d -name .git)" ] && break - [ "$DIRPATH" = "$(dirname "$DIRPATH")" ] && DIRPATH=$HOME || DIRPATH="$(dirname "$DIRPATH")" + DIRPATH="$(dirname "$DIRPATH")" done - exec $TERMINAL -D "$DIRPATH" "$EDITOR" "$FILEPATH" + exec $TERMINAL -D "$DIRPATH" "$EDITOR" "$1" ;; - *) exec xdg-open "$FILEPATH" ;; + *": inode/directory;"*) + exec $TERMINAL -D "$1" + ;; + *) exec /usr/bin/xdg-open "$1" ;; esac