1
0
Fork 0
dot/.local/bin/xdg-open

18 lines
477 B
Bash
Executable File

#!/bin/sh
[ -z "$1" ] && exit
FILEPATH="$(realpath "$1")"
case "$(file -i "$FILEPATH")" in
${FILEPATH}:\ text/*)
DIRPATH="$(dirname "$FILEPATH")"
while :; do
[ "$DIRPATH" = "$HOME" ] || [ -n "$(find "$DIRPATH" ! -path "$DIRPATH" -prune -type d -name .git)" ] && break
[ "$DIRPATH" = "$(dirname "$DIRPATH")" ] && DIRPATH=$HOME || DIRPATH="$(dirname "$DIRPATH")"
done
exec $TERMINAL -D "$DIRPATH" "$EDITOR" "$FILEPATH"
;;
*) exec xdg-open "$FILEPATH" ;;
esac