dotfiles

Mahdi's dotfiles
git clone git://mahdi.pw/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

doas-askpass (800B)


      1 #!/usr/bin/expect -- 
      2 
      3 # askpass implementation for doas 
      4 # /home/mahdi/.local/bin/doas-askpass
      5 # Example:
      6 # DOAS_ASKPASS="dmenu -P -p Password:" doas-askpass echo doas
      7  
      8 # don’t mind the man behind the curtain 
      9 log_user 0 
     10  
     11 # no command, then nothing to do 
     12 if { $argc == 0 } { exit 0 } 
     13  
     14 # treat all arguments as command input 
     15 set cmd [lrange $argv 0 end]; 
     16  
     17 # read askpass from env or fallback to dmanu_pass () 
     18 if {[info exists ::env(DOAS_ASKPASS)]} { 
     19     set askpass "$::env(DOAS_ASKPASS)" 
     20 } else { 
     21     set askpass "dmenu-askpass Password:" 
     22 } 
     23  
     24 # read password from user 
     25 set pwd [exec {*}$askpass] 
     26  
     27 # spawn doas operation 
     28 spawn doas {*}$cmd 
     29  
     30 # send password and execute command 
     31 expect "doas*password:" { 
     32     send -- "$pwd\r" 
     33     expect \r 
     34     log_user 1 
     35     expect eof 
     36 }