penguin/utils

my env utils

commit b0e98bad0a7f5b80f3f79b1ce4757c3cae4f00f2

author斟酌 鵬兄 <tgckpg@gmail.com>
date2025-05-19T20:24:17Z
subjectAdded type for pwgen
commit b0e98bad0a7f5b80f3f79b1ce4757c3cae4f00f2
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2025-05-19T20:24:17Z

    Added type for pwgen
---
 bash/sources/12_shortcuts | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/bash/sources/12_shortcuts b/bash/sources/12_shortcuts
index 16c69b7..f081cc4 100755
--- a/bash/sources/12_shortcuts
+++ b/bash/sources/12_shortcuts
@@ -19,14 +19,21 @@ function kres {
 }
 
 function pwgen {
-	local _LEN=$1
+	local _LEN=$1 _TYPE=$2
 	case $_LEN in
-		''|*[!0-9]*)
+		*[!0-9]*)
 			echo "Enter a valid number" > /dev/stderr
 			return 1
 			;;
+		'')
+			echo "Usage: pwgen [LEN] [TYPE]"
+			return 1
+			;;
 	esac
-	LC_ALL=C tr -dc '[:graph:]' </dev/urandom | head -c $_LEN
+	if [ -z "$_TYPE" ]; then
+		_TYPE="graph"
+	fi
+	LC_ALL=C tr -dc "[:$_TYPE:]" </dev/urandom | head -c $_LEN
 	if [ -t 1 ]; then
 		echo
 	fi