dotfiles

Obligatory dotfiles repo
git clone git://git.danielmoch.com/dotfiles.git
Log | Files | Refs

Sudo (692B)


      1 #!/bin/sh
      2 # Assumes the user can run cat and tee as root without a password
      3 
      4 if type doas >/dev/null 2>&1
      5 then
      6 	sudo=doas
      7 else
      8 	sudo=sudo
      9 fi
     10 
     11 if [ $# -eq 0 ]
     12 then
     13 	fname=$(9p read acme/$winid/tag | awk '{ print $1 }')
     14 	9p read acme/$winid/body | $sudo /usr/bin/tee $fname >/dev/null 2>&1
     15 	echo clean | 9p write acme/$winid/ctl
     16 else
     17 	if echo $1 | grep -E '^/' > /dev/null 2>&1
     18 	then
     19 		fname=$1
     20 	else
     21 		fname=$(pwd)/$1
     22 	fi
     23 	echo name $fname | 9p write acme/new/ctl
     24 	winid=$(9p read acme/index | awk '{ print $1 " " $6 }' | grep $fname | awk '{ print $1 }')
     25 	echo -n 'Sudo ' | 9p write acme/$winid/tag
     26 	$sudo /bin/cat $fname | 9p write acme/$winid/body
     27 	echo clean | 9p write acme/$winid/ctl
     28 fi