Live data from Hacker News

New(ish) command line tools

jvns.ca

121–130 of 252 posts

Re: New(ish) command line tools

#121

A simple trick I only figured recently is following logs with fuzzy search: tail -f /var/log/foo.log | fzf +s Or something similar for output from a dev server: make serve | fzf --ansi +s

Could you (or anyone who understands) explain what these do?

tail -f will hang around and output new lines that appear in the file.

fzf will receive that input and in this case accumulate the new lines that have come in from tail -f. It will then stay around, present an interactive full screen text ui, and let you interactively filter the set of received lines based on substrings you enter at the fzf prompt. This while continuously incorporating new log lines coming from the pipe, from tail -f. The +s just says not to sort the lines, keeping the matches in the same order they appeared in the logs.

Re: New(ish) command line tools

#122
post #52

broot completely changed the way I navigate directories on the CLI over the past year. I was an 'ls' purist before, I've tried various CLI file managers in the past and they all felt like they added too much friction, with the one exception of nnn which I briefly used before finding broot, which just feels really fluid and natural.

Broot has many features that feel natural... when you know they exist (for example, try looking for what's taking space with `br -w` then stage the files and remove them at the end).

I suggest everyone to have at least a short glance at the introduction at https://dystroy.org/broot/

Re: New(ish) command line tools

#124

I could really use a better workflow to refine grep matches. Has anyone made a tool that combines grep (regex search) with fzf (multiple positive/negative patterns)? What I really want is something like: grep pattern1 **/* | grep pattern2 | grep -v exclude_these | grep -v also_exclude The problem is this loses filenames and context lines in the output. I want to apply several positive and negative regexes, and only a…

You can combine patterns on file names and/or file content with broot. Here's my usual workflow: https://dystroy.org/blog/broot-c-search/

Re: New(ish) command line tools

#125
post #3

direnv is such a godsend that I shill for it on every team and in every company now, it's such a great tool.

I read through the direnv docs, but I'm trying to think of how I'd use it. Can you or anyone else give me some examples? Even just listing which directories you have .env or .envrc files in, and what environment variables you use in them.

I place a .envrc at the root of our monorepo with a handful of env vars that configure stuff like PATH (to point to the various scripts, tools, and executables that are used in the dev environment), override the sane default config files with an environment variable (extremely useful when chasing down specific bugs) and to redirect or control logging and debug info when running tools and systems.

It makes it a breeze to pull in a commit and set up a development harness that pokes at whatever thing I need to poke at in my local environment. And it does it without changing a line of code or command line invocation, which is a big deal in polyglot environments with various build constraints (not passing -DFLAG=thing is enormous in a big C/C++ code base, for example).

Even just being able to point whether a service is looking at a dev/production/local service/database is a big deal if you've invested in IaC and don't want to mess with any config files to do your work (as .envrc is probably in your .gitignore).

Re: New(ish) command line tools

#126

A simple trick I only figured recently is following logs with fuzzy search: tail -f /var/log/foo.log | fzf +s Or something similar for output from a dev server: make serve | fzf --ansi +s

This is amazing! Is it possible to do the following somehow? - automatically have this for any command that outputs more than 10 lines? - automatically exit when the main command (for example a dev server) exits? - print the output of the main command to stdout after this is done?

> automatically have this for any command that outputs more than 10 lines?

Probably not. The output of a command typically goes directly to the terminal and does not pass through the shell, so the shell has no idea how many lines there are.

You could write a shell where that's not the case, but that would have issues with interactive things - what happens if you run e.g. vim or htop in that context?

You can pipe to `less -F` (`--quit-if-one-screen`), but note that the version of `less` shipped with macOS has a bug and might just swallow the output instead.

Re: New(ish) command line tools

#127

A simple trick I only figured recently is following logs with fuzzy search: tail -f /var/log/foo.log | fzf +s Or something similar for output from a dev server: make serve | fzf --ansi +s

fzf is a wonderful little tool. I use this script so much:

git branch | fzf | xargs git checkout

Re: New(ish) command line tools

#128

Earlier quoted context omitted.

Ah, htmlq [1] is a missing one that's not on the list! Straight from the repo: "Like jq, but for HTML." I find it useful for quickly hacking scripts together and exploring data. Very useful for the iterative process of finding good CSS selectors with the data that I can get without javascript running. --- [1] https://github.com/mgdm/htmlq

I use pup for this. People who tried both, any difference? https://github.com/EricChiang/pup

Not sure if pup supports this but something I do use fairly often (and copied into my own internal tooling) is the ability to filter out results as a flag in the CLI.

For example, something I usually do is:

  curl --include --location https://example.com | tee /tmp/example-com.html | htmlq --base https://example.com a --attribute href --remove-nodes 'a[href*="#"],a[href^="javascript"],a[href*="?"]'
This grabs the page, shunts a copy to /tmp for subsequent, iterative testing, then tries to grab all the links while filtering out any links that have a '#', '?', or start with the word 'javascript'. This is super helpful when I'm just exploring some HTML scrape and trying to build a graph of links without having to pop out a proper programming language just yet.

Re: New(ish) command line tools

#129

Has anyone made an installer/GNU type thing for the "common" ones like delta and rg? Could be a fun weekend project: Select what tooling you want, it will be installed using your package manager [ ] delta [ ] bat ...

I use a makefile to set up a new computer.

https://github.com/peteryates/dotfiles/blob/master/Makefile#...

Re: New(ish) command line tools

#130
post #97

A simple trick I only figured recently is following logs with fuzzy search: tail -f /var/log/foo.log | fzf +s Or something similar for output from a dev server: make serve | fzf --ansi +s

Alternatively, you can use less(1) in tail mode to search growing logs. less +F -p pattern /path/to/log (Ctrl-C to break out of tail mode. /pattern to interactively set search pattern.)

Also while inside less: & shows you only lines which match a pattern. You can hit & multiple times and less will show you only those lines which match every input pattern. A ^N right after & negates the pattern. & respects the -I switch (case insensitive pattern matching).

I use this all the time, especially when I'm on a machine that I don't want to bother installing something like fzf on.

Post reply on HN