Skip to content

Add repeat subcommand to builtin string #3864

@Greynad

Description

@Greynad

why?

I often find myself in need of a way to replicate a string n times and there is currently no way to do this natively in any shell. So people came up with a few ways to achieve this, i.e:

python -c 'print "A"*10'
ruby -e 'puts "A"*10'
perl -E 'say "A"x10'
printf "A%.0s" {1..10}

Creating a function to wrap any of these method is fine, but why bother when we could have a native function?

Proposal

Since (to my knowledge) no other shell has this feature, let's add this to fish!

The proposed syntax is:

string repeat -t 10 'string'

Repeat subcommand could take these arguments:

-t, --times: number of times to repeat the string
-n, --no-newline: whether to append a newline or not

alternatives:

-c, --count: number of times to repeat the string (as proposed by @krader1961 )
The newline could be appended automatically if we're not piping the output to another program

Misc

edge cases:

  • Should 'string repeat -t 0 test' yield an error or be allowed and not output anything?

A preliminary version of this has been proposed #3858

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions