Splash 2020 conf is happening this week
2020.splashcon.org1 ポイント投稿者 rgrau0 コメント
unhist () {
alias $1=" $1"
}
unhist unhist
unhist fzf
unhist rghist #custom command that greps .zhistory,... 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. #!/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. docker save $image | bzip2 | ssh "$host" 'bunzip2 | docker load' echo "${1:-${env_var:?I need a value for that!}}" &2=+/~x!/:\:x:!100
I wrote a little explanation of it, in case anyone is
curious about how it works: https://github.com/kidd/arraylangs-index/blob/master/noteboo... if (is_foo()) {
return 1;
}
can be cleared with `d%.` from the beginning of the first line. #!/usr/bin/env sh
browse_url() {
firefox http://github.com/$1/issues/$2
}
issue=$(curl https://api.github.com/repos/$1/issues |
jq -r 'map([(.number|tostring), .title] | join(" | ")) | join("\n")' |
dmenu -i -l 10 |
awk "{print \$1}")
browse_url $1 $issue
Although the `| join("\n")` part could be done in a more idomatic way with just `[]`, sometimes the manual way are still clearer to me: map([(.number|tostring), .title] | join(" | "))[] foo="ls -las"
$foo
"$foo"
for zsh to split words, `setopt SH_SPLIT_WORDS`.
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 small scopes, I tend to inline the `:?` validation inside the arg of the command. `echo "${1:? first param required}"`
Another usecase is to use colon in the body of a while loop, while doing work in the condition of the loop.
Gives you the "do X while it succeeds. stop when it returns non-0" semantics.
I've also written about this and other bash tricks over the years in https://github.com/kidd/scripting-field-guide/blob/master/bo.... You might like them :)