1. 6

    Going through my history of commands,

    grep -oP '(^| +\| +)\K[^ ]+' "$HISTFILE" | sort | uniq -c | sort -nr | head -n100
    

    I see rg and pngquant as the two main commands that aren’t present by default on my Ubuntu set up. I also use my own aliases/functions. For example, I use 2lc frequently to check if last two commands are giving the same result (when I’m working on my cli books, answering on reddit/stackoverflow, etc).

    2lc () 
    { 
        p1=$(fc -ln -2 | head -n1);
        p2=$(fc -ln -3 | head -n1);
        diff --suppress-common-lines -y -s <(eval command "$p1") <(eval command "$p2") | head -n5
    }
    

    Another is ch (inspired by https://explainshell.com/) to quickly extract information from manual for command line options (see https://github.com/learnbyexample/command_help). For example:

    $ ch rg -g
           rg - recursively search current directory for lines matching a pattern
    
           -g, --glob GLOB ...
               Include or exclude files and directories for searching that match the given glob.
               This always overrides any other ignore logic. Multiple glob flags may be used.
               Globbing rules match .gitignore globs. Precede a glob with a ! to exclude it. If
               multiple globs match a file or directory, the glob given later in the command line
               takes precedence.
    
    1.  

      Going through my history of commands, I think I’m very boring in this regard (only ripgrep and custom tools in the top 100)

      I use colordiff a lot, because I have to diff files not in git a lot and hexdump comes up more often than I’d like to.

      Maybe the most unusual thing (which I stole somewhere) is a colorize function/alias so I can tail and still highlight stuff without resorting to grep and missing out on the rest:

      grep --color=always "$1\|^"

      1.  

        ^ or $ can be skipped, i.e. "$1\|" should give the same result

        also, ripgrep has --passthru option for this purpose

    1. 3

      Worth noting that all of the objective criticisms of Brave were bugs that were reported by users and addressed by the developers. I’m not seeing any past bugs being brought up regarding other browsers?

      All things considered, I feel Brave is doing a good job having honest conversations with their users and writing code that aligns with the values of the users.

      (I have no affiliation with any browser, I am currently using Firefox/Chrome/Brave respectively on each of my 3 devices to get an accurate feel for the differences. I am considering switching the other two to Brave or Chrome.)

      1. 7

        re: Brave, I think there is probably a fundamental conflict between selling Attention Units and ensuring user privacy.

        Plus there was the scandal a while back where Brave was hijacking URLs to pocket referrals [1].

        There have just been too many Things That Make You Go Hmmmm with Brave for me to trust them. Fair or not, I dismiss the browser as a crypto scam parading as a privacy focused browser.

        1: https://decrypt.co/31522/crypto-brave-browser-redirect

          1.  

            Plus there was the scandal a while back where Brave was hijacking URLs to pocket referrals [1].

            Yea, that was one of the objective criticisms I reference: https://brave.com/referral-codes-in-suggested-sites/

            I don’t agree that BAT is fundamentally conflicting with user privacy. We can debate that, but at minimum I think we can agree it’s a more subjective criticism.

        1. 19

          Forgive me if this is gauche, but what is wrong with simply using bashisms? Outside of embedded contexts, where you want everything in Busybox, but writing shell scripts in just POSIX shell just seems like a tortured dialect.. The extensions are legitimately useful, so it’s also a question of why other shells haven’t implemented it.

          Also curious is not wanting to use Shellcheck, even if it’s just for (skippable) CI-side tests. Shellcheck was the first tool that made writing shell scripts tolerable for me.

          1. 4

            Some POSIX operating systems don’t come with Bash out of the box, notably the BSDs. As such Bash is rarely used in them even if it is available. Even MacOS switched its default shell to ZSH.

            Generally though I think dropping the dependency on Bash increases compatibility across the board and removes an unneeded dependency. Both of which are always welcome.

            1. 3

              I don’t mind taking dependencies if it helps you reduce complexity elsewhere, especially if the cost is amortized elsewhere.

              1. 4

                You’re not the one maintaining thousands of rc scripts or build scripts for a distro/flavor. Or at least I assume you’re not. The tradeoffs communities make usually have a reason and just because you don’t see it or understand it doesn’t mean it’s not there.

                1. 3

                  But this is not about thousands of rc scripts. This issue is about one script used during the go build process. On majority of systems it will need a dependency that is immediately satisfied. On some minority it will require a single package.

                  1. 4

                    The GitHub issue appears to be a troll issue, and I agree it doesn’t really matter much in the context of the Golang toolchain. However I was responding to the thread which was speaking more generically about dependencies and script maintenance.

                    1. 3

                      Well technically at least 3.

                      But I agree in general. I fail to see why requiring bash is such a huge deal (I have read the comments here as well as the comments on the GitHub issue).

                2. 2

                  Even MacOS switched its default shell to ZSH.

                  For a while, not any more.

                  1. 1

                    What is it now?

                    1. 1

                      I’m fairly sure it’s back to bash.

                3. 3

                  One of the comments from that issue:

                  Just had my first experience with Go, which was nice. The one thing that surprised me a little bit was that bash was required to build. On OpenBSD the standard shell is a hardened ksh. bash is avoided everywhere in base so I had to install that, no biggie, but the question I would phrase in the spirit of portability and reducing dependencies is “why require more if technically all you need is POSIX shell”? I’m wondering if such a change would be desirable, aside from the question who’s going to make it happen.

                  Also, doesn’t macOS uses zsh by default now? But probably, it’ll be compatible with the bash scripts used here?

                  1. 3

                    It seems like just another dependency to me though - and certainly one common enough most people will have, and run on most people’s systems.

                    1. 3

                      doesn’t macOS uses zsh by default now?

                      Yes, but they’re not removing bash from the standard system AFAIK

                      1. 2

                        Yes, that comment is from me. It is my first encounter with the Go community, so after discovering they don’t completely dismiss the idea itself, I thought let’s first get some broader opinions and have a discussion with a community I’m part of before I continue this discussion in the Go thread.

                        Also, doesn’t macOS uses zsh by default now?

                        idd

                        But probably, it’ll be compatible with the bash scripts used here?

                        Good question, from a superquick check I can say it doesn’t right out fail like it does on OpenBSD with ksh.

                      2. 2

                        Forgive me if this is gauche, but what is wrong with simply using bashisms?

                        Nothing, bash really makes our lives easier, the extensions are really useful. Some people wants to only use POSIX sh, just because it is a “standard”. Some people just hates bash because it is popular.

                      1. 2

                        Looks like a great idea but the examples aren’t commented much and when they are it’s in German.

                        1. 1

                          You might like the snake game example video that was mentioned in the reddit thread

                        1. 2

                          Bookmarked. I had to convert from GHF markdown to LaTeX to PDF on Windows using a complicated set-up of Pandoc, Strawberry Perl, etc. and it was a pain.

                          1. 2

                            Do check the links at the end too, for example https://github.com/Wandmalfarbe/pandoc-latex-template might suit better with less fiddling involved compared to my custom scripts.

                          1. 2

                            Today, I finished some minor pending tasks on my GitHub repos.

                            Tomorrow and day-after-tomorrow reserved for Wintersteel by Will Wight. It’s a progression fantasy series, think Naruto or Hunter x Hunter in book form, but fast paced most of the time without fillers. The first seven books are free during Oct 5/6/7.

                            After that, planning to start Perl one-liners book.

                            1. 10

                              I am building a search engine with my friend who just graduated from a conversion masters in computer science!

                              The goals of this are to:

                              • Teach him about proper branching strategy, pull requests and code review, GitHub issues, etc.
                              • Help him put together a cool portfolio project that he can speak about in interviews
                              • Understand more about search engines!

                              Any related resources are appreciated. We’ve been reading Write an Internet search engine with 200 lines of Ruby code and also the PageRank white paper.

                              1. 6

                                I collected quite a lot of links about search engines. I think it’s a cool learning project.

                                1. 3

                                  Ah, a fantastic resource, thank you!

                                  I see you’ve listed some search engines written in Rust. One of my favourite Rust projects at the moment is a WebAssembly search solution for static sites called Stork: https://github.com/jameslittle230/stork

                                2. 1

                                  Does the search engine has any distinct goals or new features? I just thought of Sonic, which is a light weight copy of Elastic Search and very great :D

                                  1. 2

                                    Nothing novel. Just the standard Crawling, Indexing, and Querying. We were thinking about making it ‘a search engine for technical blogs’. Thanks for the heads up about Sonic, I’m checking it out on GitHub now.

                                    1. 1

                                      a search engine for technical blogs

                                      I came across https://hyperlog.app/ which uses redis on HN (https://news.ycombinator.com/item?id=24383857).

                                  2. 1
                                    • Look into aho-corasick
                                    • Look into boolean query and FSM
                                    • Look into for-each-par-map
                                  1. 9

                                    The section “What can we do?” leaves out the option of leaving GitHub. The only way to disable or limit pull requests while keeping the repo active is the emergency measures which only work for 24 hours, and that’s a product decision aimed at keeping people on the platform and exploit network effects, not a service for their users.

                                    1. 5

                                      This is an excellent market-based solution to this problem. Any git host that has a ToS forbidding this kind of behavior should be reaching out to maintainers now to help them move their repos over.

                                      1. 9

                                        When moving, I would strongly suggest people to take this opportunity to consider self-hosting, instead. Hosting your own means being master of your own castle, where you get to decide the ToS.

                                        1. 3

                                          I’m completely sure that Microsoft wouldn’t do anything with such spammers and in fact - they might not want to. Actually, it’s sort of profitable to them to gain new users and additional traffic on GitHub, and the quality issues are absolutely not their problems because that’s someone else’s repositories :)

                                        2. 5

                                          Hi @pgeorgi, my team at GitHub has just shipped a change to Temporary interaction limits which lets you set them for up to six months.

                                          We had started this work prior to Hacktoberfest and it wasn’t on our minds as we were planning it, but the timing happened to line up very well to release this feature today.

                                          1. 3

                                            Is there a reason interaction limits are limited to six months and can’t be set indefinitely? Some projects would like to permanently disable interaction.

                                            1. 2

                                              Interaction limits were introduced in 2017 as a way to tackle the specific problem of heated discussions, brigading of issue trackers, and targeted harassment. It’s a very blunt tool as it prevents all of the interactions in a repository.

                                              When we’ve talked to maintainers about limiting interactions permanently, if they wanted to limit interactions at all, it was usually having control over certain kinds of interactions, e.g. some people can open issues, but anyone can still open a PR. Do you have any examples of projects that would like to permanently disable interaction?

                                              1. 5

                                                A lot of projects use GitHub just for hosting/mirroring their repo, such as the Linux kernel, OpenBSD, FreeBSD, NetBSD, SQLite, LLVM, GCC, Android Open Source Project, Emacs, LibreOffice, MediaWiki, Lua, JGit, Wayland, zsh, etc. Most don’t want pull requests because they use another method like email or Gerrit for contribution, or because they don’t accept contributions at all in the case of SQLite. I assume most of these projects would want to disable comments on commits and other interactions, because in my experience those comments on these projects are noise.

                                                In my case, I want to host repos on another host but have a mirror of the repo on GitHub as a fallback/convenience, with just the repository itself, no issues/PRs/comments/etc. I also want to be able to host repos that I don’t accept any contribution to (i.e. a personal dotfiles repo). I could re-enable interaction limits on every repo every six months, but that’s much less convenient than being able to set it permanently.

                                                1. 1

                                                  TZ info does this too, and the maintainer prefers the mailing list:

                                                  Thanks for bringing that to the mailing list (if I could shut off GitHub pull requests I would).

                                                  (my emphasis)

                                            2. 3

                                              Sorry to hijack this thread, but I have a related query.

                                              Is there any reason (technical or otherwise) to not give an option to disable Pull Requests? Even outside of spam considerations, I have repos that host code snippets for my ebooks, for which I do not wish to get any PR at all. I do not mind using this “interaction limit” feature every 6 months, but it doesn’t currently have an option to restrict only PRs.

                                              1. 5

                                                Not a hijack at all, this is a great question. Disabling Pull Requests is definitely something we’ve heard from maintainers before. I can’t make any promises, but it’s certainly an interesting idea.

                                                For your ebook repos, do you still want to get Issues opened, just not PRs?

                                                1. 3

                                                  Thank you for listening to feedback :)

                                                  For your ebook repos, do you still want to get Issues opened, just not PRs?

                                                  Yes, issues will provide a way for readers to report typos/bugs/suggestions/etc. I encourage that in my README as well as within the ebook content - which seems to work as I have gotten helpful issues in the past on these repos.

                                            3. 3

                                              Many of my personal projects are on Sourcehut for several reasons. This is another one to add to the list.

                                            1. 2

                                              It seems GitHub has added the option to limit pull requests https://twitter.com/github/status/1311772722234560517

                                              1. 2

                                                But this affects issues as well.

                                              1. 7

                                                Overly dramatic. And I do like getting a free t shirt.

                                                1. 15

                                                  Not at all. I have a few sub-500 stars projects, and they too get a significant amount of spammy PRs. It’s literally just “Adding a gif to the readme” or something similarly ridiculous.

                                                  And I can’t begin to imagine how much crap high-profile project maintainers have to deal with. This post is fully warranted.

                                                  1. 10

                                                    Interestingly, I’ve gotten zero thus far. I wonder if tech choice and/or the kind of project is a factor here?

                                                    1. 2

                                                      I should’ve been clear—I was describing my experience from last year. After all, it’s only Oct 1st. Give it time. :)

                                                      I’ve gotten two so far for Hacktoberfest 2020, by the way.

                                                      1. 2

                                                        I didn’t get any last year either; or any year. Actually, this is the first time I heard of the entire thing 🤔

                                                    2. 4

                                                      To add some context, Vaelatern is a Void Linux contributor and we encouraged hacktoberfest PRs: https://twitter.com/VoidLinux/status/1179006377219506177.

                                                      There is a spam problem but for some reason we were not the target, maybe because its not python, js or html.

                                                      Not sure about the stars, but we are now at 1.1k and I think we already had around 500 in 2018. I think we were easily one of the top non-spammy “add your name to a file” repositories.

                                                    3. 8

                                                      I’d love actual contributions. Even if they were just typo fixes, or I had to guide a novice how to improve the code.

                                                      But the only “contributions” I’ve got were pure useless garbage. Someone has added “Requires Windows 7 or higher” (with worse spelling) to my Mac app. They didn’t even bother read a single line of the README they were changing.

                                                      1. 3

                                                        I thought so too, but take a look at this: https://github.com/search?o=desc&q=is%3Apr+%22improve+docs%22&s=created&type=Issues

                                                        Try “amazing project” too. It’s an onslaught. I don’t remember it ever being this bad, but perhaps it was for the more popular repos.

                                                        1. 2

                                                          This small 0-star project got three “improve docs” PRs in the last 40 minutes from three different accounts (just noticed it was mentioned several times on the first page): https://github.com/tehpug/TehPUG/pulls?q=is%3Apr+is%3Aclosed

                                                          Then I clicked another random project from that list, and this 4-star project has four pages of PRs spammed: https://github.com/Moeplhausen/SunknightsWebsite/pulls – literally those entire four pages are full of this idiocy, there’s not one legitimate PR in there. This is just idiocy.

                                                          I don’t know why these projects gets so many, nothing about those repos or the accounts/organisations they belong to seems well-known in the slightest; just a typical small project people uploaded just for code hosting. As I mentioned in my other comment, I’ve gotten zero PRs thus far in spite of having several >100 star repos. If these repo are targetted (and I think that’s an appropriate term here) them why aren’t mine? 🤔

                                                          What a clusterfuck.

                                                          1. 3

                                                            I would guess they are now targeting small/inactive repositories in the hope of maintainers not flagging their PRs within the 7 day period in which “invalid” flags are checked.

                                                            They could instead of make PRs to their own repos or create organizations without bothering other projects.

                                                            1. 1

                                                              Right; that makes sense. I assumed you need to actually have the PR merged to count, but turns out you just need to make it.

                                                              As for making your own repo, the site mentions:

                                                              Bad repositories will be excluded. In the past, we’ve seen many repositories that encourage participants to make simple pull requests – such as adding their name to a file – to quickly gain a pull request toward completing Hacktoberfest. [..] We’ve implemented a system to block these repositories, and any pull requests submitted to such repositories will not be counted.

                                                        2. 3

                                                          I archived a repo two days back to avoid this spam (and I’m not actively working on it anyway)

                                                          https://github.com/learnbyexample/Python_Basics/pulls?q=is%3Apr+is%3Aclosed

                                                          1. 1

                                                            man I’d feel bad if I was abhinav-TB and created a PR for some project only to have it closed without comment a mere 5 days later

                                                            1. 1

                                                              may be if they read the readme first or if they explained why they are making a pointless PR, then perhaps I’d have made an effort to comment

                                                        1. 8

                                                          The feeling of knowing that you have helped a lot of people is gratifying. The personal growth that comes from taking on such a challenge is also considerable. And there is no better way to learn something in depth than by explaining it to others.

                                                          An apt conclusion that resonates well with me.

                                                          My contract with the publisher specifies that I get 25% of publisher revenue from ebooks, online access, and licensing, 10% of revenue from print sales, and 5% of revenue from translations.

                                                          Self-publishing is relatively new compared to the history of traditional publishing. If someone wishes to write a book and hasn’t been able to land a deal with a publishing company, I’d definitely suggest self-publishing. Returns are much higher and you retain the rights to do interactive course, translations, video course, etc. The downside is that you have to do marketing, get reviewed, etc all by yourself. One of the main reasons self-publishing is attractive to me is that I can easily update for newer versions and I can give them away for free whenever I want.

                                                          1. 3

                                                            A comparison of all viable options for technical writing would be cool. Many books are also available on a website for free, but can be bought as paperback for money. You can help much more people this way, but probably make less money.

                                                            1. 1

                                                              A comparison of all viable options for technical writing would be cool

                                                              Didn’t get you, can you give an example?

                                                              Many books are also available on a website for free, but can be bought as paperback for money

                                                              Yeah, for example: https://automatetheboringstuff.com/2e/ and https://greenteapress.com/wp/think-python-2e/. I’m highly inspired from these authors and recently created web versions for all my books as well.

                                                              1. 3

                                                                Didn’t get you, can you give an example? Here the authour published with O’Reilly. This results in him making so much money and reached so many people. He also gets a lot of offers for consulting work.

                                                                What would’ve happenend if he instead published the book for free on his website? Or if he self-published? It’s hard to make a good comparison, because I believe there is not one person, who did it all. I’d just be interested in the thought process, which to choose and what the unexpected differences are.

                                                                1. 3

                                                                  Oh ok, thanks for the clarification. It is difficult to say what would work and whether traditional or self-pub is better. It depends on various factors like how much time you have, can you spend time to market, get a cover designed, get the book reviewed, etc. I don’t think I’ll be able to give a good summary myself. I’ll link to some posts instead:

                                                                  1. 2

                                                                    Thank you!

                                                          1. 2

                                                            I prefer writing proper scripts rather than using it as a part of a command line but yeah, Ruby is really good at text processing. I just wish I didn’t have to look up the documentation of popen3 every time I had to use it.

                                                            1. 2

                                                              I just wish I didn’t have to look up the documentation of popen3 every time I had to use it.

                                                              Years ago I wrote myself a cheat sheet about Ruby process spawning methods such as popen3, something more useful to me than Ruby’s highly-detailed reference documentation. The cheat sheet doesn’t include Open3.popen3 specifically, though. I found it was overkill for all my use-cases, and I could use system, Open3.capture2, or Open3.capture3 instead.

                                                              Here’s a Markdown export of my cheat sheet in case it helps anyone in the future: Ruby – how to run a system command (shell command) and know whether it failed.

                                                              1. 2

                                                                Nice! Don’t forget the backticks, which return stdout but not the status code.

                                                              2. 1

                                                                I just wish I didn’t have to look up the documentation of popen3 every time I had to use it.

                                                                I usually search for stackoverflow (for ex: Ruby capture stderr output from bash script execution) first - I’ve become used to reading documentation, but SO feels better to get a direct solution.

                                                              1. 2

                                                                Published my Ruby one-liners cookbook today.

                                                                Other than some minor pending tasks, I look forward to spending rest of the week reading fantasy books and may be watch some anime. I have The Book in the Bottle by Raymond St. Elmo lined up, rest I’ll decide later.

                                                                1. 1

                                                                  ed(1) is the way to do it, I think. It won’t be the fastest, but it is doable.

                                                                  1. 1

                                                                    Would ed be able to work within remaining memory here?

                                                                  1. 2

                                                                    Reviewing my ebook for typos and improvements. This time I’m trying to note down some of the interesting changes, might do a blog post someday - here’s a tweet thread for now

                                                                    Started reading The Cybernetic Tea Shop by Meredith Katz. It a short novella, so I’ll likely start Queen in the Mud by Maari afterwards.

                                                                    1. 12

                                                                      One of the smaller pain points on the Mac is that there’s no built in paint tool. I want to use it just often enough that I miss it, but not enough that I want to learn what’s out there and/or pay money for a sophisticated tool.

                                                                      I realize there’s some subjectivity to this, but I think a simple paint tool ought to be part of what’s comes included with every “normal” machine.

                                                                      1. 5

                                                                        I’m using Acorn for MacOS, after seeing a recommendation or two. It’s light, fast and easy (for me) to understand. It was also cheap. I don’t do much - just cropping, copying, pasting, drawing an arrow, etc.

                                                                        1. 3

                                                                          I also endorse Acorn, it’s a great tool. One under appreciated aspect of it- you can open an image, modify it, command + s and it saves it over the original file. No “export as” or “save for web” nonsense.

                                                                          1. 1

                                                                            Boxy SVG is really nice and free.

                                                                            1. 1

                                                                              This one? https://boxy-svg.com/

                                                                              Looks great, but not free to use (15-day free trial is available though). Restricted version is available for free on Linux, but only snap (which I don’t want to use)

                                                                              1. 2

                                                                                That’s the one. I guess I’ve just been so used to using it that I completely forgot it wasn’t free.

                                                                                I’m using the Mac version. I guess since I got it from the MAS and didn’t have to go through the license activation rigamarole, it was easy to forget.

                                                                                Sorry about that.

                                                                                1. 1

                                                                                  sure no problem, the suggestion is still a good one :)

                                                                                  1. 2

                                                                                    No worries. I’ll definitely be more careful about double checking things from a while back or qualifying them.

                                                                            2. 1

                                                                              I second Acorn recommendation, although it’s not really a Paint clone. It’s more like a “subset of Photoshop that a Paint user would recognize”.

                                                                            3. 4

                                                                              there’s definitely money in it! after trying a bunch of paint alternatives I settled on (not even joking ) renting a $5/mo Windows compute server from Azure for the sole purpose of using MS Paint…

                                                                              1. 1

                                                                                You can run MS Paint using Wine. Super easy to install with WineBottler too.

                                                                              2. 3

                                                                                If your goal is to draw over a screenshot or an existing picture, you can use Preview for this. It’s not exactly a “dumb” image editor like MS Paint but it has a couple of additional features like recognizing the shapes you draw by hand. It’s very convenient for annotating screenshots if you use “File > New from Clipboard”. Otherwise you can use Pages or Keynote as a vector graphics editor.

                                                                                1. 2

                                                                                  I’ve used Preview for existing screenshots, but I’d also like to be able to start from scratch and scribble.

                                                                                  I didn’t realize that Pages and Keynote were free until just now, but they’re not built-in, so they still fail one test. I’d also suggest that using a document editor to do scribbling/painting is a little surprising and not the thing that comes to mind so easily.

                                                                                  1. 1

                                                                                    Mmm, I don’t think they have a mac flavor, but the best thing for screenshots is flameshot.

                                                                                2. 2

                                                                                  I’m with you on this. Both macOS and Linux need a good Paint clone. The other way I battled for hours with Inkscape to do a basic image manipulation with cutting and pasting, something that would take seconds on Paint. Not because Inkscape is a bad application, but rather because I haven’t learned it and don’t have the need to do it for my daily tasks.

                                                                                  1. 4
                                                                                    1. 2

                                                                                      kolourpaint.

                                                                                      1. 1

                                                                                        I wouldn’t use inkscape, it’s more of a vector thing, I use GIMP for images. It doesn’t matter though because I think your point still stands, the learning curve is steep.

                                                                                        The closest I have come to something simpler out of the box is Krita.

                                                                                      2. 1

                                                                                        I had the same complaint, and apparently I installed this: https://paintbrush.sourceforge.io/. Although I can’t remember when I last used it.

                                                                                        1. 2

                                                                                          This looks quite nice - but I was disappointed to see that fixed string mode doesn’t extend to the replacement string, so you still have to escape stuff.

                                                                                          Seems to defeat the purpose somewhat.

                                                                                          1. 1

                                                                                            Yeah, but it has a use if you need to use $0 as backreference. Also, search string starting with - requires special attention due to conflict with option parsing.

                                                                                            $ echo 'a.b*{2}c' | rg -F '.b*{2}' -r ' $0 '
                                                                                            a .b*{2} c
                                                                                            
                                                                                            $ echo 'a-b*c' | rg -r '+' -F -- '-b*'
                                                                                            a+c
                                                                                            

                                                                                            You could check out sd, which supports String-literal mode (although I haven’t tested if it applies to replacement section as well)

                                                                                            1. 2

                                                                                              Handling arguments starting with a hyphen/dash is a common thing (as you show, this is what -- is for), but the lack of “replace exactly this string with exactly this string” is surprising, in a tool that specifically has a “look for exactly this string” and “replace stuff in a string” functionalities.

                                                                                              ripgrep might have made it into tools I use from shell scripts, because it’s available from Debian buster onwards, but if its something I’m gonna need to compile and install on any target machines, I’m just as likely to just write a simple implementation myself in some higher level scripting language.

                                                                                              People by and large use grep and sed because they’re essentially ubiquitous - disregarding the various ‘flavours’, for the basic usage, they’re both part of the POSIX spec. Yes they probably have a speed advantage over a scripting languages for complex pattern based replacement, but unless you’re dealing with huge data or highly time sensitive processes, a lot of developers would be better served by writing a simple script in .

                                                                                              1. 2

                                                                                                The only thing you have to escape in the replacement string is the dollar sign: $$0 is $0. It’s simple enough IMO that a whole new flag for it seems like overkill to me.

                                                                                                And ripgrep isn’t designed to be a better sed. It has a very simple replacement feature and that’s it. It turns out you can get a lot of mileage out if it though.

                                                                                          1. 2

                                                                                            Great stuff. I didn’t know of search/replace. Does anyone here know if there is a flag or combination of tools so I can get truncated matches? i.e. so that the match is:

                                                                                            $ rg dep
                                                                                            README.md:
                                                                                            7: ... Kubernetes *dep* loyment ...
                                                                                            

                                                                                            rather than the full line? I do want some context but if I searched a minified file I don’t want the whole line.

                                                                                            1. 3

                                                                                              I think the solution you got in the replies is the best work-around for now, but there is an open feature request for this: https://github.com/BurntSushi/ripgrep/issues/1352

                                                                                              1. 1

                                                                                                Cool. Thank you.

                                                                                              2. 3

                                                                                                Printing only the matching part is -o, the same flag grep uses for this.

                                                                                                I always use -M 240 to cut off very long lines

                                                                                                You could rg -o '.{0,40}pattern.{0,40}' maybe?

                                                                                                Caveat: I only know what like 4% of rg’s flags do so maybe there’s a more direct way

                                                                                                1. 3

                                                                                                  Clever trick, matching some amount before and after and then chopping with M. I like it. Cool. Let me see if I can just edit this in myself. I, too, know very few of the flags (and there are so many!).

                                                                                                  1. 3

                                                                                                    Thank you! The -M thing was a separate thought, I just have that there with an alias because super long lines mess up my workflow

                                                                                                2. 2

                                                                                                  That’s a usecase I haven’t come across before, but I can see why it would be helpful with minified and other such lengthy inputs. The rg -o '.{0,40}pattern.{0,40}' suggestion in another comment seems the best way for this.

                                                                                                  If you are on github, you could also ask the community: https://github.com/BurntSushi/ripgrep/discussions

                                                                                                1. 11

                                                                                                  Pretty cool, thanks! I didn’t know ripgrep could do replacements.

                                                                                                  In-place editing can be done with the sponge utility from moreutils:

                                                                                                  rg --passthru 'blue' -r 'red' ip.txt | sponge ip.txt
                                                                                                  
                                                                                                  1. 1

                                                                                                    You’re welcome.

                                                                                                    sponge is a nice suggestion, I’ll add it to the post, thanks.