Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: create variable with calculated number of spaces.





On 2024-05-06 16:57, Lawrence Velázquez wrote:
And if the spacing is just being added to the beginning or end of
string1, then don't bother with the spacer variable:

	# Left-padded
	printf -v string1 '%*s' $#string2 $string1

	# Right-padded
	printf -v string1 '%-*s' $#string2 $string1
Gotta start using printf to cobble together complicated variables.  But in this case it's internal:

% mnt

Label:     Partition:    Mountpoint:  Size:    Free:    Used:  %Used:

b6-12-Deb12b     sda6    /            11.7G     5.6G     5.5G    47%
b3--0-aWorking   sda3    /aWorking   280.5M   157.2M   104.3M    37%
b2--0-boot       sda2    /boot       188.2M   131.2M    43.0M    23%
b8--6-root1      sda8    /root         5.8G     2.4G     3.1G    53%
b11---aRay       sda11   /aRay        15.6G     6.2G     8.5G    55%
b10-5-aMisc      sda10   /aMisc        4.8G     4.5G   121.1M     2%

% mnt sda

Label:     Partition:    Mountpoint:     Size:    Free:    Used:  %Used:

b6-12-Deb12b     sda6    /               11.7G     5.6G     5.5G    47%
b3--0-aWorking   sda3    /aWorking      280.5M   157.2M   104.3M    37%
b2--0-boot       sda2    /boot          188.2M   131.2M    43.0M    23%
b8--6-root1      sda8    /root            5.8G     2.4G     3.1G    53%
b11---aRay       sda11   /aRay           15.6G     6.2G     8.5G    55%
b10-5-aMisc      sda10   /aMisc           4.8G     4.5G   121.1M     2%
b5-12-Deb11a     sda5    /media/sda/5    11.7G     4.2G     6.8G    58%
b7-12-Deb12c     sda7    /media/sda/7    11.7G     5.6G     5.5G    47%
b9--6-root2      sda9    /media/sda/9     5.8G     2.4G     3.1G    53%

... 'findmnt' outputs nice columns so the thing is to space the 'title' line accordingly -- it's mostly the mountpoint who's width can vary so the spacer goes in there.  Purely cosmetic.





    



Messages sorted by: Reverse Date, Date, Thread, Author