Improved user selection dialog
This commit is contained in:
parent
cc07972c78
commit
b9baec2b1f
|
@ -403,24 +403,29 @@ function show_about {
|
|||
|
||||
function select_user {
|
||||
SELECTED_USERNAME=
|
||||
data=$(tempfile 2>/dev/null)
|
||||
trap "rm -f $data" 0 1 2 5 15
|
||||
dialog --title "Select a user" \
|
||||
--backtitle $"Freedombone Control Panel" \
|
||||
--dselect "/home/" 14 40 2> $data
|
||||
sel=$?
|
||||
case $sel in
|
||||
0) SELECTED_USERNAME=$(cat $data | awk -F '/' '{print $3}');;
|
||||
1) return;;
|
||||
255) return;;
|
||||
esac
|
||||
if [ ${#SELECTED_USERNAME} -lt 2 ]; then
|
||||
SELECTED_USERNAME=
|
||||
fi
|
||||
if [ ! -d /home/$SELECTED_USERNAME ]; then
|
||||
dialog --title $"User directory check" \
|
||||
--msgbox $"This does not look like a user directory" 6 40
|
||||
SELECTED_USERNAME=
|
||||
|
||||
users_array=($(ls /home))
|
||||
|
||||
delete=(mirrors git)
|
||||
for del in ${delete[@]}
|
||||
do
|
||||
users_array=(${users_array[@]/$del})
|
||||
done
|
||||
|
||||
i=0
|
||||
W=()
|
||||
name=()
|
||||
for u in ${users_array[@]}
|
||||
do
|
||||
i=$((i+1))
|
||||
W+=($i "$u")
|
||||
name+=("$u")
|
||||
done
|
||||
|
||||
user_index=$(dialog --backtitle $"Freedombone Control Panel" --title $"Select User" --menu $"Select one of the following:" 24 40 17 "${W[@]}" 3>&2 2>&1 1>&3)
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
SELECTED_USERNAME="${name[$((user_index-1))]}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue