1
0
Fork 0

xdg-open: bugfix and simplify

main
urosm 2024-09-21 18:05:52 +02:00
parent 3ad7c69a56
commit 711172dca9
1 changed files with 10 additions and 10 deletions

View File

@ -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