Last active
October 13, 2023 00:53
-
-
Save lzlrd/040743fe718324796820dc071c529bdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
args="$@" | |
argsUnsupported="false" | |
asUser="root" | |
if [[ $@ == "" ]]; then | |
echo "usage: xsudo [command [arg ...]]" | |
echo "usage: xsudo [-u user] [command [arg ...]]" | |
exit 1 | |
fi | |
if [[ $1 == -u ]]; then | |
args="${@:3}" | |
asUser="$2" | |
fi | |
for arg in "$args"; do | |
if [[ $arg == -* ]]; then | |
argsUnsupported="true" | |
break; | |
fi | |
done | |
if [[ $argsUnsupported == true ]]; then | |
echo "Unsupported arguments were passed, please use \`sudo\`." | |
exit 1 | |
else | |
sudo -u "$asUser" sh -c "xauth add $DISPLAY . $(xauth list | grep $(uname -n) | grep :$(echo -n $DISPLAY | awk -F ":" '{print $2}' | awk -F "." '{print $1}') | awk '{print $3}'); $args" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment