Skip to content

Instantly share code, notes, and snippets.

@Jerrylum
Last active August 14, 2020 20:19
Show Gist options
  • Save Jerrylum/6d983bcf0c65d46a42e1fef19ad723ea to your computer and use it in GitHub Desktop.
Save Jerrylum/6d983bcf0c65d46a42e1fef19ad723ea to your computer and use it in GitHub Desktop.
A shell script that can help you execute a command [as the superuser | on a new GNOME terminal]
#!/usr/bin/bash
# Usage:
# curious [--sudo | -s | --terminal | -t] <command>
#
# For example:
# curious notify-send "hello world"
# curious -t notify-send "hello world"
# curious -s -t notify-send "hello world"
for ((i=1; i<=$#; i++));
do
token=${!i}
if [ "$token" = '--sudo' ] || [ "$token" = '-s' ]; then
arg_sudo=1
elif [ "$token" = '--terminal' ] || [ "$token" = '-t' ]; then
arg_terminal=1
else
break
fi
done
cmd="${@:$i:$#}"
if [ -n "$arg_terminal" ]; then
if [ -n "$arg_sudo" ]; then
gnome-terminal -- sudo bash -c "$cmd"
else
gnome-terminal -- bash -c "$cmd"
fi
else
if [ -n "$arg_sudo" ]; then
echo $cmd
pkexec bash -c "$cmd"
else
bash -c "$cmd"
fi
fi
@Jerrylum
Copy link
Author

Setup:

git clone https://gist.github.com/6d983bcf0c65d46a42e1fef19ad723ea.git
cd 6d983bcf0c65d46a42e1fef19ad723ea
chmod +x curious
sudo cp curious /usr/bin

Examples

I will give you some examples of how to use Curious

1. Open a new terminal

This shortcut can open a new terminal to display Linux processes

First, create the shell script

cd ~/Desktop
echo "curious -t top" > open_top.sh
chmod +x open_top.sh

Flag -t means open a terminal to execute the command

After that, you can find the script we just created on your desktop. Try to open it using your cursor or execute the script in the terminal.

image


2. Execute command(s) in the background as the superuser

For example, I want to change the lighting effects of my computer, the follow command requires root privilege:

OpenRGB -d 3 -m Rainbow

Here are the steps:

  1. Press Alt + F2 to open the "Run a command" prompt
    image
  2. Enter curious -s OpenRGB -d 3 -m Rainbow
  3. Enter your password
    image
  4. Done!

Flag -s means execute the command as the superuser

B4 you leave

You can also use Curious in .desktop files and other places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment