2021/09/15
That you can, technically, write inline comments in bash. Specifically, you have to put the comments in a subshell:
echo abc `#put your comment here` \
def `#another chance for a comment` \
xyz etc
That you can, technically, write inline comments in bash. Specifically, you have to put the comments in a subshell:
echo abc `#put your comment here` \
def `#another chance for a comment` \
xyz etc
that different versions of sort(1) have different sorting presets.
For example, on ubuntu 20.04 vs debian buster, sort will swap the order of how it sorts _s.
These differences can be resolved by passing --unique --dictionary-order --stable.
Bonus: -h/--human-numeric-sort can sort SI suffixes.
about the shell until keyword, which is equivalent to while !.
That you can detect the terminal you’re running in (including vscode) by checking the value of "${TERM_PROGRAM:-}".
The VS Code integrated termial always has a $TERM_PROGRAM of vscode.
You can use journalctl -u ${service_name}.service --since ${time:-today} to view the logs of a systemd service: https://www.digitalocean.com/community/tutorials/how-to-use-journalctl-to-view-and-manipulate-systemd-logs
That you can call time(1) to time how long a shell command takes, like so:
; time terraform fmt -write=true -recursive .
# terraform fmt -write=true -recursive . 0.10s user 0.23s system 24% cpu 1.377 total
That you can unescape newlines with printf "%b" 'escaped\nstring':
escaped='a\nb'
printf "%b" "$escaped"
# a
# b
that in bash and zsh, you can put a newline in a variable like so:
newline=$'\n'
echo ">>>${newline}<<<"
learned from: https://stackoverflow.com/a/4456399/6571327
that you can lsblk to list the block devices that the OS knows about without sudo.
that you can sudo growpart to increase a partition size without restarting the machine.
That you can list the listening ports on a UNIX machine using sudo lsof -i -P -n | grep LISTEN
That you can write >& 1 and it still redirects to stdout!
example:
f() { echo "ok" >&2; }
f 2>& 1 | grep ok
That terraform plan -detailed-exitcode exists: 0 means no diff, 1 means error, 2 means a diff exists.
Also, that you can print the source code of a bash function like so:
print_fn_src() { declare -f "$1"; }
That BSD arch command found on Macs also supports a -${arch} flag for running universal binaries.
That ARIA stands for Accessible Rich Internet Applications! See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA
That in linux ls(1) uses the environment variable LS_COLORS to determine the colors in which the filenames are to be displayed.
Also, that linux specifies a dir_colors(5) configuration file format for dircolors(1), which exports LS_COLORS
See https://man7.org/linux/man-pages/man5/dir_colors.5.html
That nix is complicated, which is exactly what my prior research told me.
On one hand, it is AWESOME to cd into a project and watch direnv automatically spawn a development shell with all the fixings.
On the other, the nix ecosystem is bewildering.
I read through a few articles:
https://learnxinyminutes.com/docs/nix/ : covered the expression language
https://xeiaso.net/blog/nix-flakes-1-2022-02-21, part of the https://xeiaso.net/blog/series/nix-flakes series : made a great pitch for using flakes:
One of the big annoying parts about getting into Nix is that setting up projects isn’t totally a defined science…Nix flakes helps fix this by doing a few things:
- Defining a
flake.nixas the central “hub” for your project’s dependencies, exposed packages, NixOS configuration modules and more.- Shipping a set of templates so that you can get projects started easily. Think something like Yeoman but built directly into Nix. You can also define your own templates in your
flake.nix.
https://nixos.org/guides/declarative-and-reproducible-developer-environments.html : relied on shell.nix
https://nixos.org/guides/towards-reproducibility-pinning-nixpkgs.html introduced niv, a nix package-management cli that differs from nix flake
https://github.com/nix-community/awesome-nix#rust : there are many nix+rust tools, and it’s not at all clear to me which (if any) to use
https://xeiaso.net/talks/nixos-pain-2021-11-10 : talks about some pain I’ve encountered (e.g. the ambiguity of the term “nix”, flakes splitting the ecosystem) and some I haven’t (NixOs, NixOps troubles – I don’t use those yet.)
https://o.librepush.net/solutions/nix/developing-python-rust-projects-on-nixos/ eschewed flakes since the author wanted to install editable python packages (reasonable)
Then there are the reasonable-yet-still-more confusing tools like
both of which expose tools to use nix (package manager) to provide development environments without requiring devs to write any nix (the language). Since I’m still struggling with the configuration language, I’m sympathetic to anyone wanting to avoid writing nix.
By dint of procrastinating, I now know that
pants build currently uses absolute paths for linking some tools into its hermetic build environment? https://github.com/pantsbuild/pants/issues/14492I’m still putting off reading up on nix overlays at the time of writing.
I could see someone writing SDKs for nix-the-package-manager in non-nix languages that serialize and deserialize to JSON, just like is happening to infrastructure-as-code languages (pulumi, helm, terraform cloud development kit), etc.
that you can search for nix package names on https://search.nixos.org/packages
That you can list all addresses in terraform state by running
terraform state list
Docs at https://developer.hashicorp.com/terraform/cli/commands/state/list
Also, that compgen -v is a function, at least on Mac zsh.
Apparently in zsh compgen -v calls something like
for var_name in "${(k)parameters[@]}"; do
printf '%s\n' "$var_name"
done
which is the first time I’ve seen that kind of shell syntax.
It generates a bad substitution message in bash 3.2, so I can only assume it’s zsh-specific.
That there’s a Linux command to do sql-like JOINs of lines in files, possibly based on a field in each line: join(1)