setup-your-mac / Setup-Your-Mac

Setup Your Mac aims to simplify initial device configuration by leveraging swiftDialog and Jamf Pro Policy Custom Events to allow end-users to self-complete Mac setup post-enrollment.
https://snelson.us/sym
MIT License
246 stars 54 forks source link

Limit the 'loggedInUserFirstname' variable to 25 characters and capitalize its first letter #20

Closed mani2care closed 1 year ago

mani2care commented 1 year ago

Hi Dan,

Greetings for the better visibility and standardising the login user first letter to making it capitalising

from : https://github.com/dan-snelson/Setup-Your-Mac/blob/5c0c95887aa7cb82c7c20010b312710341395a9d/Setup-Your-Mac-via-Dialog.bash#L216

to : loggedInUserFullname=$( id -F "${loggedInUser}" | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)), $i)}1')

Find the attached out put before :

image

Find the out put after :

image
dan-snelson commented 1 year ago

Thanks for the ongoing testing and FRs, @mani2care.

While this strikes me as a "garbage in, garbage out" situation — if users are too lazy to capitalize their own names, why should we reward their bad behavior — please test the following:

loggedInUserFirstname=$( echo "$loggedInUserFullname" | sed -E 's/^.*, // ; s/([^ ]*).*/\1/' | awk '{print toupper(substr($0,1,1))substr($0,2)}' )

Screenshot 2023-04-03 at 2 15 02 AM Screenshot 2023-04-03 at 2 16 03 AM
mani2care commented 1 year ago

hi Dan,

Tested with this loggedInUserFirstname its works well. loggedInUserFirstname=$( echo "$loggedInUserFullname" | sed -E 's/^.*, // ; s/([^ ]*).*/\1/' | awk '{print toupper(substr($0,1,1))substr($0,2)}' )

However, if the account name is very long then 15, its another scenario. for example Raju Manikandanrajusubbaramanigoundar Alexandros Constantinou Anastasia Papadopoulos Christophoros Georgiou Demetrios Anastasiades Eleni Ioannou-Kyprianou Georgios Michalopoulos Katerina Tzortzis-Papadakis Konstantinos Papageorgiou Margarita Kyprianou-Christodoulou Panayiotis Papageorgopoulos

can be possible like this if the name is very longer just to limiting the letters 10

loggedInUserFullname=$( id -F "${loggedInUser}" )
loggedInUserFirstname=$( echo "$loggedInUserFullname" | sed -E 's/^.*, // ; s/([^ ]*).*/\1/' | cut -c 1-10 | awk '{print toupper(substr($0,1,1))substr($0,2)}' )
if [ ${#loggedInUserFullname} -gt 11 ]; then
  loggedInUserFirstname="${loggedInUserFirstname}..."
fi

Manikandan...... so this will be limited printing the letters after if any words will be printed like ...... so this will help us to reducing the over size the table.

Before :

Screenshot 2023-04-04 at 1 32 49 PM

After :

Screenshot 2023-04-04 at 1 33 10 PM
dan-snelson commented 1 year ago

@mani2care:

Thanks for the additional details and example strings.

Please test the following:

loggedInUserFirstname=$( echo "$loggedInUserFullname" | sed -E 's/^.*, // ; s/([^ ]*).*/\1/' | sed 's/\(.\{15\}\).*/\1.../' | awk '{print toupper(substr($0,1,1))substr($0,2)}' )

❯ loggedInUserFullname="raju, manikandanrajusubbaramanigoundar"
❯ loggedInUserFirstname=$( echo "$loggedInUserFullname" | sed -E 's/^.*, // ; s/([^ ]*).*/\1/' | sed 's/\(.\{15\}\).*/\1.../' | awk '{print toupper(substr($0,1,1))substr($0,2)}' )
❯ echo $loggedInUserFirstname
Manikandanrajus...
dan-snelson commented 1 year ago

@mani2care: The example above is for the first 15 characters; please advise if you'd prefer the first 10 characters (as in your example).

mani2care commented 1 year ago

I think this is looks good shot and sweet ,& prefer the first 10 characters

#!/bin/bash
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )
loggedInUserFullname=$( id -F "${loggedInUser}" )
loggedInUserFirstname=$( echo "$loggedInUserFullname" | sed -E 's/^.*, // ; s/([^ ]*).*/\1/' | sed 's/\(.\{15\}\).*/\1.../' | awk '{print toupper(substr($0,1,1))substr($0,2)}' )
echo loggedInUserFullname : $loggedInUserFullname
echo loggedInUserFirstname: $loggedInUserFirstname

Find the test results:

image
dan-snelson commented 1 year ago

@mani2care: This should be addressed in 1.10.0-rc1.

dan-snelson commented 1 year ago

@mani2care: Please test-drive 1.10.0-rc2.

As mentioned in the #setup-your-mac Channel on the Mac Admins Slack:

Long-term, I feel that if upgrading to the latest version of SYM is well-documented, Mac Admins can roll-their-own customizations now and easily maintain them across versions, without adversely impacting the entire user-base.

dan-snelson commented 1 year ago

(You can uncomment Line No. 216 during testing.)

mani2care commented 1 year ago

Hi @dan-snelson find the attached the test results.

https://user-images.githubusercontent.com/52978899/230109441-d3270a54-8d37-456a-82aa-2d434a119029.mov

https://user-images.githubusercontent.com/52978899/230109690-f642b9a1-1cd8-417c-8e60-cc447f094c5a.mov

mani2care commented 1 year ago

One more request change the headline to Center align so it’s looks good

dan-snelson commented 1 year ago

@mani2care: This one comes down to personal preference; I think the left-aligned header looks good.

dan-snelson commented 1 year ago

Thanks, @mani2care!