-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: add (new)line #13
Comments
You can insert a literal newline into a string in most shell simply by
pressing enter. That should do the trick, right?
…On Thu, Jun 6, 2019 at 9:17 AM Sam Jaques ***@***.***> wrote:
A missing functionality (if I'm not mistaken) is the ability to add a line.
Good use case would be that I want to add a 'feature'. For most of the
code, a new line needs to be added similar to an existing feature.
One way to solve this would be to allow adding (\r)\n characters like
fastmod -m '(^[\s]*)(feature4\n)' '${1}${2}${1}feature5\n'
But \n is just printed raw as ''+'n'
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#13?email_source=notifications&email_token=AAAIK6ADYDEWPCQ6SPELDLLPZE2CZA5CNFSM4HVEN3I2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GYCDFMA>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAIK6F5OEPVQVEJQY7MXGLPZE2CZANCNFSM4HVEN3IQ>
.
|
Wow, you're right. It works like a charm! Example:
Thanks! |
@swolchok would you accept a PR implementing this? Sure, there are shells allowing this. But not all do. And the reliance on a shell means But even if you happen to use a shell that supports this, it makes it incredibly unwieldy ... either you need to stubble together So I thought to myself, heck, if I need to go through hoops, why not capture the line ending in
... it matches. It even performs a replacement, but the line breaks are not to be seen anywhere. I think that part may even qualify as a defect. Besides, when working with regexes I fully expect to be able to use such escaped characters in the replacement string. |
Your escaping in the replacement string is inconsistent -- you've escaped the first
Can we talk specifics? In what environment are you having trouble? Perhaps I can help. Just in case it helps without needing a round-trip cycle, BSD sed has a similar behavior of not interpreting escape characters in output; here's a Stack Overflow page with some ways to put newlines in: https://stackoverflow.com/questions/46082397/insert-newline-n-using-sed |
@swolchok thanks for the correction! You are right about the missing escapes for
I am using it in different environments and one of them is Windows. Broadly speaking we're talking Linux and Windows. And the "problem" is that not in all cases a shell is even involved. PowerShell could probably even do that with relative ease, given that its escape character is a backtick and not the backslash, but with NT scripts ("batch") I'm out of luck. Yes, I know, I could probably write a wrapper of sorts in each case, but the issue is that this would effectively mean one wrapper per regex/replacement pair or something generic that understands the Thanks for your time and patience (and also thanks for a very useful tool). PS: if you are open to a PR implementing this, I'm not yet sure if I'd contribute in my professional capacity (this account) or as individual, but I'd be willing to put in the time and effort to make this happen. |
My big reluctance on this is: 1) it's a breaking change to the tool 2) people already don't quite understand the difference between their shell and their tools' expected inputs, so making the reality extremely simple helps troubleshooting since we can say with confidence that fastmod isn't doing any escaping. I've asked for a second opinion internally though; will reply back after I get some more thoughts. |
Thanks for getting a second opinion. Hope it will be seen as acceptable, even if it meant that a command line switch needs to be used to explicitly enable this behavior going forward, say. Can understand your point on the inability of users to understand what is done by the shell and what is done by the tool. This frequently comes up whenever tools either refer to using shell magic for stuff they don't do (see above) and when cross-platform tools try to partially mimic that shell behavior in order to provide the illusion of shell globbing on Windows, say (I worked on another Rust-based tool where that was an issue). |
I'm running a bit behind on work due to a power outage yesterday. After consulting with some other folks, the idea I heard that I liked was to detect \n in the replacement string and print some help on inserting newlines. The todos are
|
For PowerShell one can use I'm not sure where exactly you'd want that however, @swolchok. Did you mean to place this into the For NT script ("batch") you should technically be able to embed a line break using the following (paraphrasing the example by @jaques-sam):
However, things get more difficult when you want to deal with With my PR #42 you'd be able to use the same characters you are used to, independently of a shell, provided you enable that handling with |
@swolchok Regarding your 1), I think that's a moot point, given codemod is no longer developed (since June 2021) and this tool is supposed to be a partial replacement. No? Regarding 2) it's true that shells differ, but that's exactly my point. It's hard enough as it is to juggle between all sorts of more-or-less-POSIX-y shells (backslash), NT script (circumflex) and Powershell (backtick) regarding escape characters. But the tool does already use its own globbing totally independent of the shell used to run it. So why is it alright to use the Python-internal globbing (codemod) or Rust-internal globbing (fastmod) rather than deferring it to the shell, but then it's not okay to gloss over other portability issues such as those non-printable characters within substitutions? Together with the fact that codemod seems to be no longer developed, this leaves me flabbergasted. I guess when you're in the comfortable position of using some POSIX-y shell (which I am not 100% of my time), then you don't care if the shell or fastmod itself expands the Please advise: does it make more sense to run a friendly fork of fastmod, or are you at all willing to accept outside contributions at all (and what are the constraints in that case, other than signing the CLA). Obviously there are some which are pretty much "between the lines". |
yes, we accept outside contributions.
I believe I've discussed above what the contribution I would be happy to accept would look like. Philosophically, I don't think it should be the responsibility of every command-line program to re-implement features that should be provided by the user's shell.
the tool does recursive directory traversal, which is beyond simple globbing. |
also, #42 looks OK except for the review comments I left, but hasn't been updated since. |
Wait, I think you misunderstood that part. Yep, I get the point about the traversal, but the
@swolchok Sorry, must have totally missed that. My apologies. But I am also still unable to see any review comments 😬. Did you actually post them or is the review still in-progress and therefore only visible to you? Here's what I see on #42: Feel free to skip and ignore the points below. I just wanted to convey that I totally get your point. There are a lot of things that are odd on either platform, in my opinion. But since the tool is otherwise cross-platform, its users would benefit from the ability to tap into that functionality despite their shell.
Got that point, and generally I even agree with your opinion. But it's kind of a moot point for a shell ( This is one of the bigger differences between how Unix shells do things and MSVC offers a so-called link option (not to be confused with linker command line options) which does the command-line argument wildcard expansion (again according to the ancient rules inherited from DOS with only minor adjustments; i.e. also different from shell globbing) before your
What's worse, though, on Linux you can pass usually 2 MiB ( So my point -- and mind you, my main systems at home are all Linux-based (only at work Windows is the main system), but I still care somewhat about my Windows tooling -- was that by saying "the shell should" you're about 44 years late if we look at I guess the misunderstanding on my end was that it looked as if you weren't interested in merging the changes and I can't see those review comments you mention -- even at the time of writing. |
A missing functionality (if I'm not mistaken) is the ability to add a line.
Good use case would be that I want to add a 'feature'. For most of the code, a new line needs to be added similar to an existing feature.
One way to solve this would be to allow adding (\r)\n characters like
fastmod -m '(^[\s]*)(feature4\n)' '${1}${2}${1}feature5\n'
But
\n
is just printed raw as\
+n
The text was updated successfully, but these errors were encountered: