Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
rgrau
searching Neon…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
5 ms
·
1.
▲
by
rgrau
2mo ago
So true. I think most of us who learned "advanced" bash is after being tired of feeling like an idiot looking at long bash scripts. Usually, those scripts are written by people who didn't learn the "weird tricks", a
2.
▲
by
rgrau
2mo ago
Nice one! I love those weird bash tricks. Some of the examples here are interesting, but they show parameter substitution more than colon itself: https://tldp.org/LDP/abs/html/parameter-substitution.html In s
3.
▲
by
rgrau
6mo ago
aha! I see what you mean, it's indeed a nice option, yep. Using brackets like this is something I never thought of, and it's probably why it's hard for me to process it, but I can see it provides nice annotation capabilities,
4.
▲
by
rgrau
6mo ago
That's very cool! To take advantage of the "leading space" one, I have this, to mark some commands that I never want to record: unhist () { alias $1=" $1" } unhist unhist unhis
5.
▲
by
rgrau
6mo ago
for multiline pipes, it's WAY better to format like foo | bar | baz You don't have to use backquotes, AND, it allows you to comment line by line, because there's no backslash messing with the parser. I
6.
▲
by
rgrau
6mo ago
A similar trick: #!/bin/sh $* that's my `~/bin/noglob` file, so when I call a zsh script from bash that uses `noglob`, it doesn't blow up.
7.
▲
by
rgrau
1y ago
I use a variant with ssh and some compression: docker save $image | bzip2 | ssh "$host" 'bunzip2 | docker load'
8.
▲
by
rgrau
3y ago
You can also nest those, so this way you can get a value from an argument, or an env var, and if none is set, error. echo "${1:-${env_var:?I need a value for that!}}"
9.
▲
by
rgrau
3y ago
Here's a solution in k, that uses a similar array oriented approach: &2=+/~x!/:\:x:!100 I wrote a little explanation of it, in case anyone is curious about how it works: https://github.com/kidd&
10.
▲
by
rgrau
3y ago
I couldn't find a way to have more than one callback per signal, and created a system to have an array of callbacks: https://github.com/kidd/scripting-field-guide/blob/master/bo... A nice bonus is t
11.
▲
by
rgrau
3y ago
Yep, good point. They are useful when you want to change the whole text inside the delimiters (and IME, it's most of the times), but they do different things than cf( because they also change/delete text behind the cursor. The % a
12.
▲
by
rgrau
3y ago
I have 2 use cases for cf), but I don't use it a lot in the end: One is when inside a parenthesis, and wanting to really delete till the closing parenthesis. But that would leave an unbalanced open paren. So in this case, I use ct) mos
13.
▲
by
rgrau
3y ago
Another advantage of pipes at the end is that you can comment lines and the full pipeline still works. Some time ago I wrote a bunch of tips to make more ergonomic bash scripts: https://raimonster.com/scripting-field-guide&#
14.
▲
by
rgrau
3y ago
Here's where he explains how he did it: https://www.youtube.com/watch?v=ORjyXcLDd9M
15.
▲
by
rgrau
4y ago
Oh, I hadn't noticed that links are not highlighted as such (unless already visited). Fixed, thanks!
16.
▲
by
rgrau
4y ago
Fixed, thanks!
17.
▲
by
rgrau
4y ago
> If appropriate, change to the script’s directory close to the start of the script. > And it’s usually always appropriate. I wouldn't think so. You don't know where your script will be called from, and many times the param
18.
▲
by
rgrau
5y ago
Oh! I didn't know that one could build an arbitrary string like that inside a map. Thanks a lot for that, I agree it looks better!
19.
▲
by
rgrau
5y ago
A very useful function in jq is "join", which I use a lot to cook the final shape of the data (many times used with fzf/dmenu) Here's a simple way to list and browse github issues of a given user/repo: #!/
20.
▲
by
rgrau
5y ago
Even funnier when you realize bash and zsh do different things (by default) there. foo="ls -las" $foo "$foo" for zsh to split words, `setopt SH_SPLIT_WORDS`.
21.
▲
by
rgrau
5y ago
Yep, sorry about that, I meant in general. This particular case is fine, and I am grateful for that.
22.
▲
by
rgrau
5y ago
yes! that looks super useful indeed. Thanks!
23.
▲
by
rgrau
5y ago
What I miss most about those collections is that they are browser based, and when I'm programming, if I need the music to stop, or I get a call, or something, I have to go find the tab and manually stop it. I'm trying to maintain
24.
▲
by
rgrau
5y ago
thanks so much! I'll fix all those right away :+1:
25.
▲
by
rgrau
5y ago
wow, that's a great one!
26.
▲
by
rgrau
5y ago
Part of the mystery of the infamous shell fork bomb is that it picks a weird name like ':' for the function name. :(){ :|:& };: Turns into a less mysterious: bomb() { bomb | bomb & } bomb I
27.
▲
by
rgrau
5y ago
Several ways (overkill answer, but leaving all options I know because why not): You can try evaluating this in the scratch buffer (if (member 'nativecomp features) (message "yay") (message "nay&quo
28.
▲
by
rgrau
5y ago
Or maybe, you'd have the same dollar a million times... you never know...
29.
▲
by
rgrau
5y ago
Most of my scripts start with that template on 4.20.1. That's the baseline. But soon enough they have 4.22 and 4.25. I never liked those "bare minimum templates" that are 100 lines, because usually the scripts I write start b
30.
▲
by
rgrau
5y ago
Thanks for giving it a read. Glad it was useful!
More ›