dotfiles

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

dpass (1904B)


      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\nEDIT\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 EDIT
     54 	encfile = /tmp/$pid.plain
     55 	touch $encfile
     56 	chmod 0700 $encfile
     57 	printf '%s' $dec > $encfile
     58 	if (~ $EDITOR ()) { EDITOR=vim }
     59 	$EDITOR $encfile
     60 	gpg --armor -e --default-recipient-self < $encfile > $PASS
     61 	shred -u $encfile
     62 	printf '%s' $newpass | xclip
     63 	@{ sleep 25; xclip </dev/null } &
     64 case *
     65 	out = `$nl{printf '%s' $dec | awk -F: -v 'opt=' ^ $opt '$1 == opt { print $2 }' | sed 's/^.//'}
     66 	if (~ $fromarg 1) {
     67 		echo $out
     68 	} else {
     69 		printf '%s' $out | xclip
     70 		@{ sleep 25; xclip </dev/null } &
     71 	}
     72 }