commit 395af62
Emilia Smólska
·
2026-06-19 11:43:03 +0000 UTC
parent fa8b24e
Add haslo del
M
README
+3,
-3
1@@ -12,13 +12,13 @@ Usage:
2 See haslo(1).
3
4 Ksh(1) completion example:
5-set -A complete_haslo_1 -- gen get put list
6+set -A complete_haslo_1 -- del gen get put list
7 set -A complete_haslo_2 -- $(haslo list)
8
9 Fish(1) completion example:
10 complete -c haslo -f
11-complete -c haslo -n 'not __fish_seen_subcommand_from gen get put list' -a 'gen get put list'
12-complete -c haslo -n '__fish_seen_subcommand_from get' -a "$(haslo list)"
13+complete -c haslo -n 'not __fish_seen_subcommand_from del gen get put list' -a 'gen get put list'
14+complete -c haslo -n '__fish_seen_subcommand_from get del' -a "$(haslo list)"
15
16 License:
17 Haslo is public domain software.
M
haslo
+25,
-7
1@@ -21,23 +21,34 @@ sub writegpgpassword
2 {
3 unless(-d $haslodir){
4 print STDERR "creating directory $haslodir\n";
5- mkdir $haslodir or die "couldn't create directory $haslodir: $!\n";
6+ mkdir $haslodir
7+ or die "couldn't create directory $haslodir: $!\n";
8 }
9 my $target = shift;
10 my $password = shift;
11- open GPG, '|-', 'gpg', '-qer', $hasloemail, '-o', "$haslodir/$target.gpg"
12+ open GPG, '|-', 'gpg', '-qer', $hasloemail, '-o',
13+ "$haslodir/$target.gpg"
14 or die "couldn't open pipe to gpg: $!\n";
15 print GPG $password;
16 close GPG or die "gpg failed with exit code $?\n";
17 }
18
19+sub dodel
20+{
21+ my $target = $ARGV[1] or usage;
22+ $target = encode_base32 $target;
23+ system 'rm', '-i', "$haslodir/$target.gpg"
24+ and die "rm failed with exit code $?\n";
25+}
26+
27 sub dogen
28 {
29 my $target = $ARGV[1] or usage;
30 $target = encode_base32 $target;
31- my $buf = '';
32- open URANDOM, '<', '/dev/urandom' or die "couldn't open /dev/urandom: $!\n";
33- read URANDOM, $buf, 128 or die "couldn't read from /dev/urandom: $!\n";
34+ open URANDOM, '<', '/dev/urandom'
35+ or die "couldn't open /dev/urandom: $!\n";
36+ read URANDOM, my $buf, 128
37+ or die "couldn't read from /dev/urandom: $!\n";
38 close URANDOM;
39 $buf = encode_base64 $buf;
40 writegpgpassword $target, $buf;
41@@ -47,7 +58,8 @@ sub doget
42 {
43 my $target = $ARGV[1] or usage;
44 $target = encode_base32 $target;
45- open GPG, '-|', 'gpg', '-qd', "$haslodir/$target.gpg" or die "couldn't open pipe to gpg: $!\n";
46+ open GPG, '-|', 'gpg', '-qd', "$haslodir/$target.gpg"
47+ or die "couldn't open pipe to gpg: $!\n";
48 my $password = <GPG>;
49 close GPG or die "gpg failed with exit code $?\n";
50 print $password;
51@@ -82,7 +94,13 @@ sub doput
52 writegpgpassword $target, $password;
53 }
54
55-my %commands = (gen => \&dogen, get => \&doget, list => \&dolist, put => \&doput);
56+my %commands = (
57+ del => \&dodel,
58+ gen => \&dogen,
59+ get => \&doget,
60+ list => \&dolist,
61+ put => \&doput
62+);
63 my $argv0 = $ARGV[0] or usage;
64 my $command = $commands{$argv0} or usage;
65 $command->();
M
haslo.1
+3,
-0
1@@ -17,6 +17,9 @@ The
2 .Nm
3 utility creates and retrieves PGP-encrypted passwords. The commands are as follows:
4 .Bl -tag -width Ds
5+.It Cm del Ar name
6+Delete the generated or created password for
7+.Ar name .
8 .It Cm gen Ar name
9 Generate a random password for
10 .Ar name ,