dotfiles

<-- duh.
git clone https://hhvn.uk/dotfiles
git clone git://hhvn.uk/dotfiles
Log | Files | Refs | Submodules | LICENSE

dpass (1599B)


      1 #!/bin/rc
      2 # Copyright (c) 2022 hhvn <dev@hhvn.uk>
      3 
      4 if (~ $#PASS 0) {
      5 	PASS = $home/.local/pass
      6 }
      7 if (!test -f $PASS) {
      8 	touch $PASS
      9 }
     10 
     11 dec = `''{dmenu -P -p 'Master password:' </dev/null | gpg -qd --passphrase-fd 0 $PASS}
     12 
     13 if (!~ $#* 0) {
     14 	opt = $1
     15 	fromarg = 1
     16 } else {
     17 	opt = `$nl{printf '%s' $dec | awk -F: 'BEGIN {printf("GENERATE\nAPPEND\n")}; {print $1}' | dmenu -l 20 -i}
     18 }
     19 
     20 switch ($opt) {
     21 case GENERATE
     22 	newpass = `''{tr -dc 'a-zA-Z0-9~!@#$%^&*_+=-' < /dev/urandom | head -c 35}
     23 	newname = `$nl{dmenu -p 'Name:' </dev/null}
     24 	if (~ $newname '') {
     25 		herbe 'dpass exiting... no pass given'
     26 		exit 1
     27 	}
     28 	dec     = `''{printf '%s%s: %s\n' $dec $newname $newpass}
     29 	encfile = /tmp/$pid.plain
     30 	touch $encfile
     31 	chmod 0700 $encfile
     32 	printf '%s' $dec > $encfile
     33 	gpg --armor -e --default-recipient-self < $encfile > $PASS
     34 	shred -u $encfile
     35 	printf '%s' $newpass | xclip
     36 	@{ sleep 25; xclip </dev/null } &
     37 case APPEND
     38 	newname = `$nl{dmenu -p 'Name:' </dev/null}
     39 	newpass = `$nl{dmenu -P -p 'Password:' </dev/null}
     40 	if (~ $newname '') {
     41 		herbe 'dpass exiting... no pass given'
     42 		exit 1
     43 	}
     44 	dec     = `''{printf '%s%s: %s\n' $dec $newname $newpass}
     45 	encfile = /tmp/$pid.plain
     46 	touch $encfile
     47 	chmod 0700 $encfile
     48 	printf '%s' $dec > $encfile
     49 	gpg --armor -e --default-recipient-self < $encfile > $PASS
     50 	shred -u $encfile
     51 	printf '%s' $newpass | xclip
     52 	@{ sleep 25; xclip </dev/null } &
     53 case *
     54 	out = `$nl{printf '%s' $dec | awk -F: -v 'opt=' ^ $opt '$1 == opt { print $2 }' | sed 's/^.//'}
     55 	if (~ $fromarg 1) {
     56 		echo $out
     57 	} else {
     58 		printf '%s' $out | xclip
     59 		@{ sleep 25; xclip </dev/null } &
     60 	}
     61 }