News for hackers. Stuff that matters.
Re:Making Hard Things Easy by zvmaz on Friday October 06, 2023 @10:58AM (#37791652)
Excellent talk. She seems to be a very likable person. She is right about Bash being full of "gotchas" and trivia and memorizing them all is very hard, but I think it is nice to memorize some trivia. For instance, I tended to forget the order of the arguments of the find command, and I would lose time trying to remember its syntax when I'm in front of a machine with no readily available internet connection. So I committed to learning and memorizing the most common command line tools and some of their "gotchas". I used Anki for that, and some mnemonics, and the return on the investment has been worth it I think.
Re:Making Hard Things Easy by thwarted on Friday October 06, 2023 @11:13AM (#37791861)
I tended to forget the order of the arguments of the find command, and I would lose time trying to remember its syntax when I'm in front of a machine with no readily available internet connection.

The man pages are readily available.

The bash man page is huge and hairy, but comprehensive, I've found it pretty valuable to be familiar with the major sections and the visual shape of the text in the man page so I can page through it quickly to locate the exact info I need. This is often faster than using a Internet search engine.

Re:Making Hard Things Easy by zvmaz on Friday October 06, 2023 @11:16AM (#37791916)
> The man pages are readily available.

True, but I find the man pages not easy and quick to parse.

Re:Making Hard Things Easy by imp0cat on Friday October 06, 2023 @11:34AM (#37792168)
Right. I don't think you're supposed to read them top-to-bottom.

Use `/` and search for the things of interest (keywords, arguments, options, etc...). Use n/N to quickly jump forward/back.

Re:Making Hard Things Easy by lazide on Friday October 06, 2023 @03:49PM (#37795389)
Find has a particularly bad man page to find things that way.
Re:Making Hard Things Easy by tripleo1 on Friday October 06, 2023 @04:32PM (#37795994)
FWIW it's `-maxdepth 1` not `-depth 1`.

But yeah, you're right.

Re:Making Hard Things Easy by lazide on Friday October 06, 2023 @10:42PM (#37798576)
Dude, flashbacks. Aren’t you supposed to do a trigger warning or something first! ;)
Re:Making Hard Things Easy by imp0cat on Friday October 06, 2023 @06:18PM (#37797071)
AFAIK there is a find replacement with sane defaults: https://github.com/sharkdp/fd , a lot of people I know love it.

However, I already have this in my muscle memory: find <where> -name '<what>' -type f(file)/d(directory)

Works in 90% of situations when searching for some file in terminal, ie: find / -name 'stuff*'

The rest of the time is spent figuring out exec/xargs. :)

And once you master that, swap xargs for GNU parallel. I bet your machine has a ton of cores, don't let then sit idly. ;)

Re:Making Hard Things Easy by anjanb on Saturday October 07, 2023 @02:14PM (#37804127)
you can grep the man page contents by using the following command

man <command> | col -b | grep "search_string"

Re:Making Hard Things Easy by pixelbyindex on Friday October 06, 2023 @12:06PM (#37792579)
I'm not a fan of man pages. Or any documentation that focuses on textual explanations rather than examples in code (looking at you aws).

I recently found https://tldr.sh/ and found it more convenient. I ended up writing myself a vscode extension to have a quick lookup at my fingertips, since I am at least 60% of the time looking at a terminal in vscode

Re:Making Hard Things Easy by anjanb on Saturday October 07, 2023 @01:32PM (#37803686)
I've used a small bash function. example : to search grep's manual for "lines", I type gm grep "lines"

gm () { man $1 | col -b | grep --color=always "$2" }

I also have something similar for grepping a command's help

gh () { $1 --help | grep --color=always $2 }

I usually try gh(grep help) and if I don't get what I'm looking for, I run gm(grep man).

It appears that I can also use tldr

Re:Making Hard Things Easy by layer8 on Friday October 06, 2023 @12:10PM (#37792626)
For find, I think the Info pages are (even) more comprehensive (info find), and you get more structural navigation.
Re:Making Hard Things Easy by eviks on Friday October 06, 2023 @12:36PM (#37792978)
Comprehensiveness is not a benefit if it's poorly searchable
Re:Making Hard Things Easy by asicsp on Friday October 06, 2023 @11:03AM (#37791728)
I maintain a file with commands that I don't use often (ex: increase volume with ffmpeg, add a border to an image with convert, etc). I even have a shortcut that'll add the last executed command to this file and another shortcut to search from this file.
Re:Making Hard Things Easy by redlohr on Friday October 06, 2023 @11:12AM (#37791857)
Oh, that's a great idea. I have a doc that I maintain by hand, either via ">>" or editing directly. Time to go and make a shortcut. Do you do any annotation to help with the search?
Re:Making Hard Things Easy by asicsp on Friday October 06, 2023 @11:15AM (#37791889)
Usually no annotations, as I typically search by command name. But sometimes I edit the file to add comments if there are many examples for the same command.
Re:Making Hard Things Easy by mmcdermott on Friday October 06, 2023 @11:52AM (#37792400)
A large Justfile (https://just.systems/) of random recipes might be a way to make it both executable and searchable (at least on zsh, you can get an autocomplete list of completions from the command line).
Re:Making Hard Things Easy by cole-k on Friday October 06, 2023 @12:21PM (#37792784)
Can you think of a single CLI tool that would let me commit a past incantation to a file and retrieve it later? Especially one that syncs well across devices.

The best I can think of is Atuin (https://github.com/atuinsh/atuin) but I wasn't super interested in using it - I kind of want something more lightweight.

Re:Making Hard Things Easy by mmc on Friday October 06, 2023 @02:46PM (#37794595)
I've been using a little set of bash funcs I called `hs` for this for a few years:

https://github.com/mikemccracken/hs

your snippets are stored in a git repo that you can sync around how you like.

Re:Making Hard Things Easy by kenoh on Friday October 06, 2023 @11:22AM (#37792004)
Pretty much the same, though I usually just keep the file open in a side terminal. I want to use stuff like cheat.sh (ex. curl cheat.sh/grep) but I never remember.
Re:Making Hard Things Easy by fiddlerwoaroof on Friday October 06, 2023 @12:13PM (#37792662)
If you’re already putting them in a file, you might as well put them in a shell script on $PATH: at a certain point I started writing shell scripts and little utilities for relatively infrequently used commands and other tasks (e.g. clone this repo from GitHub to a well-known location and cd to it)
Re:Making Hard Things Easy by eschneider on Friday October 06, 2023 @12:48PM (#37793103)
Keeping a ~/bin directory with all your personal shell shortcut scripts has been my go-to for years. I tend to make a lot of project-specific shortcut scripts for anything that I want to remember/becomes a common task.
Re:Making Hard Things Easy by ustad on Friday October 06, 2023 @01:10PM (#37793355)
Wait, how do you “cd to it” from within the script? Doesn’t exiting the script take you back to where you were?
Re:Making Hard Things Easy by justin_oaks on Friday October 06, 2023 @01:47PM (#37793777)
You're right that you often can't modify your current environment by invoking a shell script. That's because it's executed in a sub-shell.

For cases where you need to modify your current environment (setting environment variables, changing directories, etc), you need to run the script using the "source" built-in. That will execute the script in the current shell rather than a sub-shell.

So instead of

    ./some-script.sh
you'd run

    source some-script.sh
or use the dot (".") shorthand

    . some-script.sh
In cases where I need to source a script, I generally create an alias or a shell function for it. Otherwise I may forget to source it.
Re:Making Hard Things Easy by fiddlerwoaroof on Friday October 06, 2023 @02:49PM (#37794645)
For this I use shell functions in my .zshrc and I wrote a loader to source a bunch of files in a .zsh.d directory.
Re:Making Hard Things Easy by tripleo1 on Friday October 06, 2023 @04:29PM (#37795962)
Rolled your own direnv?
Re:Making Hard Things Easy by fiddlerwoaroof on Friday October 06, 2023 @08:10PM (#37797905)
No, this is global: I use direnv too.

It’s more like “roll your own oh-my-zsh”

Re:Making Hard Things Easy by brezelgoring on Friday October 06, 2023 @02:14PM (#37794162)
Nobody asked but I'd like to chime in with my method.

I have a lot of aliases, for example to start my QEMU VM with my development stuff in it, I make an alias for 'qemu-system-x86_64 [...]' with all the switches and devices and files required, called 'startvm'. I have another that takes me to my current project's folder and pulls the repo. And a third that creates a new folder called 'newproject', creates a small set of folders and empty files with specific names, and finally makes a git repo in it. I am a serial abandoner of projects so I use this more often than I care to admit.

It's not pretty, but functional; and since I always copy my dotfiles when I change computers, I've kept these small helpers with me for a while now.

Re:Making Hard Things Easy by cole-k on Friday October 06, 2023 @12:15PM (#37792703)
If you don't mind, it would be awesome to see your cheatsheet. I think this would be a great thing for people to share - like their dotfiles. But maybe they already do and I don't pay much attention to it because I'm lazy - like their dotfiles.
Re:Making Hard Things Easy by hiAndrewQuinn on Friday October 06, 2023 @02:24PM (#37794296)
I like `fzf`'s default override of Ctrl+R backwards search for this purpose, along with the fish shell's really good built in autocompletion.

I've been thinking about updating the GIFs in my fzf tutorial to show off fish, but I think I'd rather leave them with ish just so I don't dilute the pedagogical message.

Re:Making Hard Things Easy by xenodium on Friday October 06, 2023 @07:49PM (#37797774)
Oh, specially ffmpeg and imagemagick! I have a handful of incantations saved over time.

Just today I saved a new one for trimming borders on video screenshots https://xenodium.com/trimming-video-screenshots to https://github.com/xenodium/dwim-shell-command/blob/main/dwi... (that’s my cheat sheet).

I wrote an Emacs package that works fairly well for saving commands but also making them reusable from its file manager without the need to tweak input or output file paths https://github.com/xenodium/dwim-shell-command

While Emacs isn’t everyone’s cup of tea, I think the same concept can be applied elsewhere. Right click on file(s) from macOS Finder or Windows Explorer and apply any of those saved commands.

Edit: More examples…

- Stitching multiple images: https://xenodium.com/joining-images-from-the-comfort-of-dire...

- Batch apply on file selections: https://xenodium.com/emacs-dwim-shell-command

Re:Making Hard Things Easy by eviks on Friday October 06, 2023 @12:35PM (#37792969)
It might be better to invest in something more general like better docs/cheatsheets (the bad old man pages which you could convert to a text editor friendly format, or something better like tldr, or something like Dash) so you don't depend on the internet, but also don't have to memorize bad designs (since find wouldn't be the only one)
Re:Making Hard Things Easy by hiAndrewQuinn on Friday October 06, 2023 @02:20PM (#37794241)
I came here to say Anki is my lifeline for grokking difficult things like DNS.

It was in fact on jvns.ca's book recommendation that I got Michael W. Lucas's _Networking for System Administrators_, and strip mined it for Anki cards containing both technical know-how and more than a little sysadmin wisdom.

It might be one of the highest ROI books I've ever read, considering I actually remember how to use things like nectat and tcpdump to debug transport layer issues at a moment's notice now.

Re:Making Hard Things Easy by grumblingdev on Friday October 06, 2023 @05:55PM (#37796929)
We should stop using Bash, and use TypeScript instead.

Bash is terrible.

Re:Making Hard Things Easy by corobo on Friday October 06, 2023 @07:32PM (#37797660)
well this shell is just broken

  > ls -al
  <repl>.ts:4:1 - error TS2304: Cannot find name 'ls'.
  
  4 ls -al
    ~~
  <repl>.ts:4:5 - error TS2304: Cannot find name 'al'.
  
  4 ls -al
        ~~
Re:Making Hard Things Easy by grumblingdev on Saturday October 07, 2023 @08:01AM (#37800986)
Easy...

    $`ls -al`
or

    ls('al')
And, transpile shortcut strings on-the-fly to TS code:

    ls({
      all: true,
      oneEntryPerLine: true,
    })