Closed jparsert closed 6 years ago
sudo won't work. as you need to enter a password. I will add a binding that you can setup a custom command accomplishing this, f.e. bind a key to run 'gksudo {cmd}'.
For anyone interested here is i3wm binding example:
bindsym $mod+Shift+d exec --no-startup-id "rofi -show drun -run-command 'gksudo {cmd}'"
or more generally:
rofi -show drun -run-command 'gksudo {cmd}'
Thinking about it, and talking it over. I think @jstefanski is the best/cleanest solution.
Closing.
@jstefanski : Thanks.
Thought I'd necrobump this: there's a way to do this without gksudo
using rofi
for password input.
sudo
itself has a -A option that makes it pipe the prompt and take the pass from stdout of whatever is in the SUDO_ASKPASS
environment variable.
So, we make a rofi-powered askpass script, say ~/bin/askpass-rofi
:
#!/bin/sh
# Take password prompt from STDIN, print password to STDOUT
# the sed piece just removes the colon from the provided
# prompt: rofi -p already gives us a colon
rofi -dmenu \
-password \
-no-fixed-num-lines \
-p "$(printf "$1" | sed s/://)"
Then to run something as root, we do:
SUDO_ASKPASS=~/bin/askpass-rofi rofi -show drun -run-command "sudo -A {cmd}"
This is probably something to bind to a "run as root" hotkey in your DE.
Alternatively, you could just add the environment variable to your usual rofi
binding (mine is ALT+F2)
SUDO_ASKPASS=~/bin/askpass-rofi rofi -show run
and just type sudo -A YOUR_COMMAND
each time you want to sudo something -- this way the whole ritual is very similar to what you usually do on the commandline.
PS @DaveDavenport, this could be put into the FAQ section of the wiki, not sure how frequent this topic is :)
For anyone interested here is i3wm binding example:
bindsym $mod+Shift+d exec --no-startup-id "rofi -show drun -run-command 'gksudo {cmd}'"
or more generally:
rofi -show drun -run-command 'gksudo {cmd}'
For anyone in the future who is confused why this doesn't work via sxhkd, it's because sxhkd strips out the {}
. Escaping them seems to work:
rofi -show drun -run-command 'gksudo \{cmd\}'
Thought I'd necrobump this: there's a way to do this without
gksudo
usingrofi
for password input.sudo
itself has a -A option that makes it pipe the prompt and take the pass from stdout of whatever is in theSUDO_ASKPASS
environment variable.So, we make a rofi-powered askpass script, say
~/bin/askpass-rofi
:#!/bin/sh # Take password prompt from STDIN, print password to STDOUT # the sed piece just removes the colon from the provided # prompt: rofi -p already gives us a colon rofi -dmenu \ -password \ -no-fixed-num-lines \ -p "$(printf "$1" | sed s/://)"
Then to run something as root, we do:
SUDO_ASKPASS=~/bin/askpass-rofi rofi -show drun -run-command "sudo -A {cmd}"
This is probably something to bind to a "run as root" hotkey in your DE.
Alternatively, you could just add the environment variable to your usual
rofi
binding (mine is ALT+F2)SUDO_ASKPASS=~/bin/askpass-rofi rofi -show run
and just type
sudo -A YOUR_COMMAND
each time you want to sudo something -- this way the whole ritual is very similar to what you usually do on the commandline.PS @DaveDavenport, this could be put into the FAQ section of the wiki, not sure how frequent this topic is :)
This is not working ! The rofi menu doesn't even show,can you be more clear about this setup ?
Bascially what the title says. It would be grate to be able to run a program with sudo.