xdg-open: bugfix and simplify
parent
3ad7c69a56
commit
711172dca9
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue