1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-18 06:28:02 +00:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Mohammad Alyetama
947a8995e3 Merge bc767a0ad3 into 02086e7115 2024-10-08 13:22:08 +08:00
jbranchaud
02086e7115 Add Link A Scalar To An Array as a Zsh TIL 2024-10-07 18:51:57 -05:00
jbranchaud
0ecc41bd29 Add Add To The Path Via Path Array as a Zsh TIL 2024-10-07 18:37:23 -05:00
jbranchaud
569220e734 Add Find Any Dotfiles That Modify Path Env Var as a Unix TIL 2024-10-07 13:44:21 -05:00
Mohammad Alyetama
bc767a0ad3 Update bew cask command 2022-11-24 17:49:13 -05:00
5 changed files with 109 additions and 2 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1452 TILs and counting..._
_1455 TILs and counting..._
---
@@ -80,6 +80,7 @@ _1452 TILs and counting..._
* [XState](#xstate)
* [YAML](#yaml)
* [Zod](#zod)
* [Zsh](#zsh)
---
@@ -1396,6 +1397,7 @@ _1452 TILs and counting..._
- [File Type Info With File](unix/file-type-info-with-file.md)
- [Find All Files Matching A Name With fd](unix/find-all-files-matching-a-name-with-fd.md)
- [Find All Files With A Specific Extension With fd](unix/find-all-files-with-a-specific-extension-with-fd.md)
- [Find Any Dotfiles That Modify Path Env Var](unix/find-any-dotfiles-that-modify-path-env-var.md)
- [Find A File Installed By Brew](unix/find-a-file-installed-by-brew.md)
- [Find Duplicate Lines In A File](unix/find-duplicate-lines-in-a-file.md)
- [Find Files With fd](unix/find-files-with-fd.md)
@@ -1725,6 +1727,11 @@ _1452 TILs and counting..._
- [Incorporate Existing Type Into Zod Schema](zod/incorporate-existing-type-into-zod-schema.md)
- [Set Custom Error Message For Nonempty Array](zod/set-custom-error-message-for-nonempty-array.md)
### Zsh
- [Add To The Path Via Path Array](zsh/add-to-the-path-via-path-array.md)
- [Link A Scalar To An Array](zsh/link-a-scalar-to-an-array.md)
## Usage
The `.vimrc` file for this project contains a function `CountTILs` that can

View File

@@ -0,0 +1,37 @@
# Find Any Dotfiles That Modify Path Env Var
Whether you are using `zsh`, `bash`, or some other shell, there are a variety
of dotfiles where you can place statements to update the `PATH` env var. These
files don't all run in the same contexts and it can be tricky to debug if one
is clobbering the path set by another.
One way to audit how your `PATH` gets set and track down any issues is to find
any place where the path may be getting modified in your dotfiles.
I like to use [`rg` (ripgrep)](https://github.com/BurntSushi/ripgrep) for tasks
like this.
First, I want to check where the `PATH` is explicitly modified.
```bash
$ rg 'export PATH' ~/\.* --max-depth 0
```
This looks at all instances of dotfiles in my home directory where `export
PATH` appears. That should catch the majority of ways that it gets updated.
Next, because I am using `zsh` as my shell, I want to look for another way my
path might be set. `zsh` defaults to setting up `path` as proxy for `PATH` that
acts as an array.
I check for any instances of `path=` or `path+=` in my dotfiles:
```bash
$ rg 'path\+?=' ~/\.* --max-depth 0
```
Note that the `--max-depth 0` is really important for both because otherwise a
ton of irrelevant stuff buried in deeply-nested dot-directories will be
surfaced.
If you want just a file name summary of the results, tack on a `-l` flag.

View File

@@ -6,7 +6,7 @@ convert it using the `ebook-convert` binary from `Calibre`.
First, install `Calibre`:
```bash
$ brew cask install calibre
$ brew install --cask calibre
```
Then convert your ePub using `ebook-convert`:

View File

@@ -0,0 +1,25 @@
# Add To Path Via Path Array
Typically when managing what is on your path in a Unix shell environment, you
override the `PATH` environment variable with `export`. This is usually an
append or prepend to bring along the existing path entries.
```bash
$ export PATH="$PATH:/Users/me/.local/bin"
```
The `zsh` shell environment exposes another way of adding to your path. They
have a `path` array which can be a little easier to work with since you can use
an array operation instead of string interpolation.
Here is how we'd do the same as above:
```bash
$ path+=/Users/me/.local/bin
```
This works because there is an automatic linking in zsh between arrays and
colon-separated strings (_scalars_).
[source](https://www.zsh.org/mla/users//2005/msg01132.html)
[source](https://superuser.com/a/1447959)

View File

@@ -0,0 +1,38 @@
# Link A Scalar To An Array
`Zsh` has a builtin command `typeset` that does a variety of things. When given
the `-T` flag and the names of a scalar and an array, it will link them
together so that a change to one is reflected in the other.
The scalar is a string of values delimited by a colon (`:`). The array is an
array that can be interacted with using array operations like append (`+=`).
```bash
$ typeset -T FOO foo
$ echo $FOO
$ export FOO="one:two"
$ echo $foo
one two
$ foo+=three
$ echo $FOO
one:two:three
```
Notice `FOO` is initially empty. I then `export` it to overwrite it with two
values delimited by a colon. Since `foo` is automatically kept in sync, I can
`echo $foo` and see those values displayed as an array. I can then append a
third value using an array operation on `foo`. The update will be automatically
reflected in `FOO`.
`Zsh` does this under the hood for `PATH` and `path` which is why you can [add
to the path via the path array](add-to-the-path-via-path-array.md).
See `man zshbuiltins` for more details.
[source](http://devlib.symbian.slions.net/s3/GUID-D87C96CE-3F23-552D-927C-B6A1D61691BF.html)