Skip to content

Instantly share code, notes, and snippets.

@stokito
Last active March 25, 2024 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stokito/1cb8ab50722673adccaac6997c7b5f7f to your computer and use it in GitHub Desktop.
Save stokito/1cb8ab50722673adccaac6997c7b5f7f to your computer and use it in GitHub Desktop.
quickly select a file and then edit it. If needed ask for a root password
FILE=$(zenity --file-selection);
if [ -z "$FILE" ]; then
exit
fi
if [ ! -f "$FILE" ]; then
dir=$(dirname "$FILE")
if [ -w "$dir" ]; then
if [ -x /usr/bin/gedit ]; then
gedit "$FILE"
else
pluma "$FILE"
fi
else
if [ -x /usr/bin/gedit ]; then
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY gedit "$FILE"
else
pkexec pluma "$FILE"
fi
fi
else
if [ -w "$FILE" ]; then
if [ -x /usr/bin/gedit ]; then
gedit "$FILE"
else
pluma "$FILE"
fi
else
if [ -x /usr/bin/gedit ]; then
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY gedit "$FILE"
else
pkexec pluma "$FILE"
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment