mirror of
https://github.com/jbranchaud/til
synced 2026-01-20 07:28:02 +00:00
Compare commits
4 Commits
af2bf37528
...
b23ace0933
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b23ace0933 | ||
|
|
02086e7115 | ||
|
|
0ecc41bd29 | ||
|
|
295fe153ad |
@@ -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).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1453 TILs and counting..._
|
_1455 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -80,6 +80,7 @@ _1453 TILs and counting..._
|
|||||||
* [XState](#xstate)
|
* [XState](#xstate)
|
||||||
* [YAML](#yaml)
|
* [YAML](#yaml)
|
||||||
* [Zod](#zod)
|
* [Zod](#zod)
|
||||||
|
* [Zsh](#zsh)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -1726,6 +1727,11 @@ _1453 TILs and counting..._
|
|||||||
- [Incorporate Existing Type Into Zod Schema](zod/incorporate-existing-type-into-zod-schema.md)
|
- [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)
|
- [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
|
## Usage
|
||||||
|
|
||||||
The `.vimrc` file for this project contains a function `CountTILs` that can
|
The `.vimrc` file for this project contains a function `CountTILs` that can
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ an array-like object with all of the arguments to the function. Even if not
|
|||||||
all of the arguments are referenced in the function signature, they can
|
all of the arguments are referenced in the function signature, they can
|
||||||
still be accessed via the `arguments` object.
|
still be accessed via the `arguments` object.
|
||||||
|
|
||||||
|
> For ES6+ compatibility, the `spread` operator used via [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) is preferred over the `arugments` object when accessing an abritrary number of function arguments.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
function argTest(one) {
|
function argTest(one) {
|
||||||
console.log(one);
|
console.log(one);
|
||||||
|
|||||||
25
zsh/add-to-the-path-via-path-array.md
Normal file
25
zsh/add-to-the-path-via-path-array.md
Normal 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)
|
||||||
38
zsh/link-a-scalar-to-an-array.md
Normal file
38
zsh/link-a-scalar-to-an-array.md
Normal 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)
|
||||||
Reference in New Issue
Block a user