gen-passwd.sh: add GUI, small fixes
This commit is contained in:
@@ -96,8 +96,8 @@ declare pw_sep=":"
|
|||||||
declare pw_cap=""
|
declare pw_cap=""
|
||||||
declare pw_dict=""
|
declare pw_dict=""
|
||||||
declare pw_copy=""
|
declare pw_copy=""
|
||||||
declare pwd_gui=""
|
declare pw_gui=""
|
||||||
declare pwd_verbose=""
|
declare pw_verbose=""
|
||||||
declare -A pw_commands=()
|
declare -A pw_commands=()
|
||||||
declare -a pw_command=()
|
declare -a pw_command=()
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ man() {
|
|||||||
# log -s "foo"
|
# log -s "foo"
|
||||||
log() {
|
log() {
|
||||||
local timestr="" prefix="" newline=y todo OPTIND
|
local timestr="" prefix="" newline=y todo OPTIND
|
||||||
[[ -z $pwd_verbose ]] && return 0
|
[[ -z $pw_verbose ]] && return 0
|
||||||
while getopts lsnt todo; do
|
while getopts lsnt todo; do
|
||||||
case $todo in
|
case $todo in
|
||||||
l) prefix=$(printf "*%.s" {1..30})
|
l) prefix=$(printf "*%.s" {1..30})
|
||||||
@@ -279,8 +279,7 @@ pwd_mac() {
|
|||||||
local str="" _str=""
|
local str="" _str=""
|
||||||
|
|
||||||
for ((i = 0; i < n; ++i)); do
|
for ((i = 0; i < n; ++i)); do
|
||||||
printf -v _str "%s%s" "$sep" "$(rnd_hex)"
|
str+="$sep$(rnd_hex)"
|
||||||
str+="$_str"
|
|
||||||
sep="$_sep"
|
sep="$_sep"
|
||||||
done
|
done
|
||||||
[[ -n $_cap ]] && str=${str^^}
|
[[ -n $_cap ]] && str=${str^^}
|
||||||
@@ -338,10 +337,11 @@ print_command() {
|
|||||||
#
|
#
|
||||||
# @return: 0
|
# @return: 0
|
||||||
gui_passwd() {
|
gui_passwd() {
|
||||||
|
local -a _command=("$@")
|
||||||
local passwd="" res=0
|
local passwd="" res=0
|
||||||
|
|
||||||
while
|
while
|
||||||
passwd=$(rnd_mac "$@")
|
passwd=$("${_command[@]}")
|
||||||
yad --title="Password Generator" --text-align=center --text="$passwd" \
|
yad --title="Password Generator" --text-align=center --text="$passwd" \
|
||||||
--borders=20 --button=gtk-copy:0 --button=gtk-refresh:1 \
|
--borders=20 --button=gtk-copy:0 --button=gtk-refresh:1 \
|
||||||
--button=gtk-ok:252 --window-icon=dialog-password
|
--button=gtk-ok:252 --window-icon=dialog-password
|
||||||
@@ -382,8 +382,7 @@ parse_opts() {
|
|||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
'-g'|'--gui')
|
'-g'|'--gui')
|
||||||
pwd_gui="$2"
|
pw_gui="$2"
|
||||||
shift
|
|
||||||
;;
|
;;
|
||||||
'-h'|'--help')
|
'-h'|'--help')
|
||||||
usage
|
usage
|
||||||
@@ -398,7 +397,7 @@ parse_opts() {
|
|||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
'-v'|'--verbose')
|
'-v'|'--verbose')
|
||||||
pwd_verbose=y
|
pw_verbose=y
|
||||||
;;
|
;;
|
||||||
'--')
|
'--')
|
||||||
shift
|
shift
|
||||||
@@ -456,13 +455,13 @@ parse_opts() {
|
|||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
[[ -n $tmp_length ]] && pw_length=$tmp_length
|
[[ -n $tmp_length ]] && pw_length=$tmp_length
|
||||||
if ! (( tmp_length )); then
|
if ! (( pw_length )); then
|
||||||
printf "%s: Bad '%d' length.\n" "$CMDNAME" "$tmp_length"
|
printf "%s: Bad '%d' length.\n" "$CMDNAME" "$tmp_length"
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
[[ -n $tmp_sep ]] && pw_sep=$tmp_sep
|
[[ -n $tmp_sep ]] && pw_sep=$tmp_sep
|
||||||
[[ $pw_sep = 0 ]] && pw_sep=""
|
[[ $pw_sep = "0" ]] && pw_sep=""
|
||||||
[[ -n $tmp_cap ]] && pw_cap=$tmp_cap
|
[[ -n $tmp_cap ]] && pw_cap=$tmp_cap
|
||||||
[[ -n $tmp_dict ]] && pw_dict=$tmp_dict
|
[[ -n $tmp_dict ]] && pw_dict=$tmp_dict
|
||||||
}
|
}
|
||||||
@@ -480,6 +479,8 @@ if [[ -z $pw_gui ]]; then
|
|||||||
printf "%s" "$passwd" | xsel -bi
|
printf "%s" "$passwd" | xsel -bi
|
||||||
fi
|
fi
|
||||||
printf "%s\n" "$passwd"
|
printf "%s\n" "$passwd"
|
||||||
|
else
|
||||||
|
gui_passwd "${pw_command[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Reference in New Issue
Block a user