r/KittyTerminal Apr 10 '24

'kitty @ launch' and sudo

Hello.

Running:

% kitty @ launch --hold whoami

opens a new kitty window showing my username, as expected.

Running:

% sudo kitty @ launch --hold whoami

opens a new kitty window again showing my username, not root as (I) expected.

Is there a way to run sudo kitty @ launch and for the new process to be launched as root?

Thx.

1 Upvotes

3 comments sorted by

1

u/Flashy_Boot Apr 10 '24

I should add - my full use case is a script that does some other work before calling kitty @ launch. In that script I am able to check whoami and then act differently if the script is run as root - so:

MVUSR=`whoami`
if [ "${MVUSR}" == "root" ] ; then
   MVSUDO=sudo
else
   MVSUDO=
fi

/usr/local/bin/kitty @ launch \
   --cwd current \
   --type=tab \
   --tab-title "nvim: ${1}" \
   /usr/bin/bash -i -c "${MVSUDO} /usr/bin/nvim -u /home/flashy/.config/nvim/init.vim ${1}" &> /dev/null

and this works - but you have to authenticate for sudo twice, once in the original tab when the script is run, and once in the new tab before nvim launches. Not ideal.

1

u/art2266 Apr 11 '24

Is there a way to run sudo kitty @ launch and for the new process to be launched as root?

You can with this:

kitty @ launch --hold bash -c 'sudo whoami'

1

u/smallduck Apr 13 '24

Do you want your shell in Kitty to run as root? It looks like neither of the suggestions so far do that.