zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: create variable with calculated number of spaces.
Date: Mon, 6 May 2024 22:14:36 -0700	[thread overview]
Message-ID: <2c187631-8284-4f35-a1a2-f982e42dd704@eastlink.ca> (raw)
In-Reply-To: <cd0cc21b-093f-4818-9503-29fe86cb3124@app.fastmail.com>

[-- Attachment #1: Type: text/plain, Size: 2125 bytes --]



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.





[-- Attachment #2: Type: text/html, Size: 3275 bytes --]

  reply	other threads:[~2024-05-07  5:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-06 22:03 Ray Andrews
2024-05-06 22:33 ` Mark J. Reed
2024-05-06 22:35   ` Mark J. Reed
2024-05-06 22:38     ` Mark J. Reed
2024-05-06 23:02       ` Ray Andrews
2024-05-06 23:28         ` Mark J. Reed
2024-05-06 23:41           ` Ray Andrews
2024-05-06 23:57       ` Lawrence Velázquez
2024-05-07  5:14         ` Ray Andrews [this message]
2024-05-07  5:52           ` Roman Perepelitsa
2024-05-07 14:56             ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2c187631-8284-4f35-a1a2-f982e42dd704@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).