diff --git a/docs/document/Articles/docs/Setup nix-on-droid.md b/docs/document/Articles/docs/Setup nix-on-droid.md index 470046f8..c56434d6 100644 --- a/docs/document/Articles/docs/Setup nix-on-droid.md +++ b/docs/document/Articles/docs/Setup nix-on-droid.md @@ -26,16 +26,21 @@ ## Init - 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/...` +> remember to allow file permision for nix-on-droid. - type `yes` when nix prompt for downloads for first init. - add and update channels: ```sh - nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager && nix-channel --update + 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 ``` > [!TIP] > If you use the wrapper function mentioned above, would be like this: >```ps1 >adbin -Enter 'nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager' >``` +- Update nix: default nix is out-dated, might not work with your current config like home-manager or any other. + ```sh + nix profile install nixpkgs#nix --priority 4 + ``` ## Connect to nix-on-droid @@ -63,10 +68,16 @@ ssh-keygen -t rsa -b 4096 -f ssh_host_rsa_key -N "" # key is generated in pwd mkdir -p ~/.ssh/ && touch ~/.ssh/authorized_keys && echo >> ~/.ssh/authorized_keys ``` +> [!TIP] +> Use this instead if you prefer pwsh, replace the pubkey name if needed. +>```ps1 +>adbin -Enter ('mkdir -p ~/.ssh/ && touch ~/.ssh/authorized_keys && echo ''{0}'' >> ~/.ssh/authorized_keys' -f (gc ~/.ssh/id_ed25519.pub)) +>``` + - start ssh daemon by `sshd` ```sh -$(which sshd) -p -h -d +$(which sshd) -p 8080 -h ./ssh_host_rsa_key -d ``` `-d` is essential to know whether your port is been taken or not. See details in `man sshd`. diff --git a/docs/document/PowerShell/docs/Language/String.md b/docs/document/PowerShell/docs/Language/String.md index 64fefabe..4b97087c 100644 --- a/docs/document/PowerShell/docs/Language/String.md +++ b/docs/document/PowerShell/docs/Language/String.md @@ -167,6 +167,34 @@ Use `*` to repeat a string. 'abc' * 2 # abcabc ``` +## Grep + +`Select-String` is a builtin cmdlet that does the similar thing like `grep` in gnu coreutils. +It can select one or more lines that matches the specified regex. + +- Grep single line from pipeline + +```ps1 +# -Pattern is positional +help sls | sls -Pattern 'Position\??\s*\d' +``` + +- Grep multiple lines from above and below + +```ps1 +# include 3 lines above and 5 lines below the macthed line +help sls | sls 'Position\??\s*\d+' -Context 3,5 +``` + +- Grep from pipeline passed by property(`-Path`) + +```console +PS ~> gci /nix/store/ -dir | sls 'roslyn' + +/nix/store/m4npcw66155bbi8i7ipp0bbp54wdwwlg-roslyn-ls-4.13.0-3.24577.4 +/nix/store/np6bigb7d3lvpinw0mrdvj38xi67q6sa-roslyn-ls-4.12.0-2.24422.6 +``` + ## String Evaluation in Interpolation ### Collection diff --git a/docs/document/PowerShell/docs/Understanding Remoting.md b/docs/document/PowerShell/docs/Understanding Remoting.md new file mode 100644 index 00000000..b70b6b6f --- /dev/null +++ b/docs/document/PowerShell/docs/Understanding Remoting.md @@ -0,0 +1,63 @@ +# Understanding Remoting + +## The Protocol + +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. +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. +Microsoft made effort to bring SSH to Windows world, they're maintaining [a fork of SSH in github](https://github.com/PowerShell/openssh-portable) + +> [!NOTE] +> `openssh` is builtin since certain version of Windows 10. + +## Connect to Remote + +No matter which protocol you use with PowerShell, it has a unified cmdlet to connect to one. +Of course this requires PowerShell available on both sides. + +- Using SSH + +```ps1 +# login as on +Enter-PSSession -HostName -UserName -Port +# or use a short syntax +Enter-PSSession -HostName @ +``` + +- Using WSMan + +```ps1 +# -ComputerName used instead for connection by WSMan +Enter-PSSession -ComputerName -UserName +``` + +Optionally, you can store the session as variable instead of entering it by `New-PSSession`. + +```ps1 +$session = New-PSSession -HostName -UserName +``` + +## Disconnect from Remote + +```ps1 +Exit-PSSession +``` + +## Execute Command on Remote + +- Execute a same command on one or more remotes. + +```ps1 +Invoke-Command -HostName [,, ...] -UserName -ScriptBlock { } +``` + +- Execute on a persistent session + +```ps1 +$session = New-PSSession -HostName -UserName +icm -Session $s -ScriptBlock { } +``` + +> [!NOTE] +> `Invoke-Command` returns deserialized object converted from transferred xml from remotes, it reflects data on remote only. +> You should only aggregate format it without mutating the values. +> `Enter-Session` does enter a PowerShell session, so it operates on a real PowerShell instance just like what you can do with SSH. diff --git a/docs/document/PowerShell/docs/What to Learn for New cmdlet.md b/docs/document/PowerShell/docs/What to Learn for New cmdlet.md new file mode 100644 index 00000000..23f96f77 --- /dev/null +++ b/docs/document/PowerShell/docs/What to Learn for New cmdlet.md @@ -0,0 +1,46 @@ +# What to Learn from New cmdlet + +## Find Positional Parameter + +Positional parameter matters for understanding the examples listed on documentations since the example might elide parameter name. +We can take advantages of `Get-Help` and `Select-String` to capture those parameters that have a explicit order. +The `-Context` includes 3 lines above and 5 lines below the display the whole info of the parameter. + +```ps1 +help | sls 'Position\??\s*\d' -Context 3,5 +``` + +The example usage is exactly what we have used here, the `Select-String`. +It has two positional parameters, `-Pattern` and `-Path`. +So in the previous example, the `-Pattern` was omitted. + +```console +$ help sls | sls 'Position\??\s*\d+' -Context 3,5 + + -Path + + Required? true +> Position? 1 + Accept pipeline input? true (ByPropertyName) + Parameter set name File, FileRaw + Aliases None + Dynamic? false + Accept wildcard characters? false + -Pattern + + Required? true +> Position? 0 + Accept pipeline input? false + Parameter set name (All) + Aliases None + Dynamic? false + Accept wildcard characters? false +``` + +## Find Parameters Accepts Pipeline + +Similar to finding position parameter. + +```ps1 +help | sls 'Accept pipeline input\??\s*true.*$' -Context 5,4 +``` diff --git a/docs/document/Regular Expression/docs/Recap/Character Class.md b/docs/document/Regular Expression/docs/Recap/Character Class.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/document/Regular Expression/docs/Recap/Modes.md b/docs/document/Regular Expression/docs/Recap/Modes.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/document/Regular Expression/docs/Recap/One Of.md b/docs/document/Regular Expression/docs/Recap/One Of.md new file mode 100644 index 00000000..e69de29b