Skip to content

Commit 8cc4e3f

Browse files
committed
main
1 parent d7a3d3f commit 8cc4e3f

File tree

7 files changed

+150
-2
lines changed

7 files changed

+150
-2
lines changed

docs/document/Articles/docs/Setup nix-on-droid.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,21 @@
2626
## Init
2727
2828
- nix-on-droid may ask for url for certain file, if the url is not accessible on your phone, download it and transfer to your phone. And replace the default url as `file:///sdcard/...`
29+
> remember to allow file permision for nix-on-droid.
2930
- type `yes` when nix prompt for downloads for first init.
3031
- add and update channels:
3132
```sh
32-
nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager && nix-channel --update
33+
nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs && nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager && nix-channel --update
3334
```
3435
> [!TIP]
3536
> If you use the wrapper function mentioned above, would be like this:
3637
>```ps1
3738
>adbin -Enter 'nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager'
3839
>```
40+
- Update nix: default nix is out-dated, might not work with your current config like home-manager or any other.
41+
```sh
42+
nix profile install nixpkgs#nix --priority 4
43+
```
3944
4045
## Connect to nix-on-droid
4146
@@ -63,10 +68,16 @@ ssh-keygen -t rsa -b 4096 -f ssh_host_rsa_key -N "" # key is generated in pwd
6368
mkdir -p ~/.ssh/ && touch ~/.ssh/authorized_keys && echo <pub> >> ~/.ssh/authorized_keys
6469
```
6570

71+
> [!TIP]
72+
> Use this instead if you prefer pwsh, replace the pubkey name if needed.
73+
>```ps1
74+
>adbin -Enter ('mkdir -p ~/.ssh/ && touch ~/.ssh/authorized_keys && echo ''{0}'' >> ~/.ssh/authorized_keys' -f (gc ~/.ssh/id_ed25519.pub))
75+
>```
76+
6677
- start ssh daemon by `sshd`
6778
6879
```sh
69-
$(which sshd) -p <port> -h <host_key> -d
80+
$(which sshd) -p 8080 -h ./ssh_host_rsa_key -d
7081
```
7182
7283
`-d` is essential to know whether your port is been taken or not. See details in `man sshd`.

docs/document/PowerShell/docs/Language/String.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,34 @@ Use `*` to repeat a string.
167167
'abc' * 2 # abcabc
168168
```
169169

170+
## Grep
171+
172+
`Select-String` is a builtin cmdlet that does the similar thing like `grep` in gnu coreutils.
173+
It can select one or more lines that matches the specified regex.
174+
175+
- Grep single line from pipeline
176+
177+
```ps1
178+
# -Pattern is positional
179+
help sls | sls -Pattern 'Position\??\s*\d'
180+
```
181+
182+
- Grep multiple lines from above and below
183+
184+
```ps1
185+
# include 3 lines above and 5 lines below the macthed line
186+
help sls | sls 'Position\??\s*\d+' -Context 3,5
187+
```
188+
189+
- Grep from pipeline passed by property(`-Path`)
190+
191+
```console
192+
PS ~> gci /nix/store/ -dir | sls 'roslyn'
193+
194+
/nix/store/m4npcw66155bbi8i7ipp0bbp54wdwwlg-roslyn-ls-4.13.0-3.24577.4
195+
/nix/store/np6bigb7d3lvpinw0mrdvj38xi67q6sa-roslyn-ls-4.12.0-2.24422.6
196+
```
197+
170198
## String Evaluation in Interpolation
171199

172200
### Collection
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Understanding Remoting
2+
3+
## The Protocol
4+
5+
PowerShell uses a protocol that you might have never heard of, the *Web Services for Management(WSMan)*, which is one of the builtin *PSProvider* on Windows.
6+
WSMan is Windows specific feature, so as PowerShell came into the cross-platform world, Microsoft decided to support SSH which is more commonly used over industries.
7+
Microsoft made effort to bring SSH to Windows world, they're maintaining [a fork of SSH in github](https://github.com/PowerShell/openssh-portable)
8+
9+
> [!NOTE]
10+
> `openssh` is builtin since certain version of Windows 10.
11+
12+
## Connect to Remote
13+
14+
No matter which protocol you use with PowerShell, it has a unified cmdlet to connect to one.
15+
Of course this requires PowerShell available on both sides.
16+
17+
- Using SSH
18+
19+
```ps1
20+
# login as <user> on <ip>
21+
Enter-PSSession -HostName <host> -UserName <user> -Port <port>
22+
# or use a short syntax
23+
Enter-PSSession -HostName <usr>@<host>
24+
```
25+
26+
- Using WSMan
27+
28+
```ps1
29+
# -ComputerName used instead for connection by WSMan
30+
Enter-PSSession -ComputerName <host> -UserName <user>
31+
```
32+
33+
Optionally, you can store the session as variable instead of entering it by `New-PSSession`.
34+
35+
```ps1
36+
$session = New-PSSession -HostName <host> -UserName <usr>
37+
```
38+
39+
## Disconnect from Remote
40+
41+
```ps1
42+
Exit-PSSession
43+
```
44+
45+
## Execute Command on Remote
46+
47+
- Execute a same command on one or more remotes.
48+
49+
```ps1
50+
Invoke-Command -HostName <host1>[,<host2>, ...] -UserName <usr> -ScriptBlock { <cmd> }
51+
```
52+
53+
- Execute on a persistent session
54+
55+
```ps1
56+
$session = New-PSSession -HostName <host> -UserName <usr>
57+
icm -Session $s -ScriptBlock { <cmd> }
58+
```
59+
60+
> [!NOTE]
61+
> `Invoke-Command` returns deserialized object converted from transferred xml from remotes, it reflects data on remote only.
62+
> You should only aggregate format it without mutating the values.
63+
> `Enter-Session` does enter a PowerShell session, so it operates on a real PowerShell instance just like what you can do with SSH.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# What to Learn from New cmdlet
2+
3+
## Find Positional Parameter
4+
5+
Positional parameter matters for understanding the examples listed on documentations since the example might elide parameter name.
6+
We can take advantages of `Get-Help` and `Select-String` to capture those parameters that have a explicit order.
7+
The `-Context` includes 3 lines above and 5 lines below the display the whole info of the parameter.
8+
9+
```ps1
10+
help <cmd> | sls 'Position\??\s*\d' -Context 3,5
11+
```
12+
13+
The example usage is exactly what we have used here, the `Select-String`.
14+
It has two positional parameters, `-Pattern` and `-Path`.
15+
So in the previous example, the `-Pattern` was omitted.
16+
17+
```console
18+
$ help sls | sls 'Position\??\s*\d+' -Context 3,5
19+
20+
-Path <string[]>
21+
22+
Required? true
23+
> Position? 1
24+
Accept pipeline input? true (ByPropertyName)
25+
Parameter set name File, FileRaw
26+
Aliases None
27+
Dynamic? false
28+
Accept wildcard characters? false
29+
-Pattern <string[]>
30+
31+
Required? true
32+
> Position? 0
33+
Accept pipeline input? false
34+
Parameter set name (All)
35+
Aliases None
36+
Dynamic? false
37+
Accept wildcard characters? false
38+
```
39+
40+
## Find Parameters Accepts Pipeline
41+
42+
Similar to finding position parameter.
43+
44+
```ps1
45+
help <cmd> | sls 'Accept pipeline input\??\s*true.*$' -Context 5,4
46+
```

docs/document/Regular Expression/docs/Recap/Character Class.md

Whitespace-only changes.

docs/document/Regular Expression/docs/Recap/Modes.md

Whitespace-only changes.

docs/document/Regular Expression/docs/Recap/One Of.md

Whitespace-only changes.

0 commit comments

Comments
 (0)