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