Skip to content

Commit 1dfb754

Browse files
committed
grrrr
1 parent 19ff204 commit 1dfb754

File tree

10 files changed

+128
-5
lines changed

10 files changed

+128
-5
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Mediator
2+
3+
Facilitates communications between components.
4+
5+
## Motivation
6+
7+
- Communications between clients on any presence or absence. Like a chatroom or online games.
8+
9+
So mediator usually as a central facility to handle communications from different clients, clients are not required to know each other.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Alias
2+
3+
## Set an Alias
4+
5+
```ps1
6+
New-Alias <alias> <cmd_name>
7+
```
8+
9+
> [!note]
10+
> `New-Alias` throws when the alias already exist while `Set-Alias` will overrides it.
11+
12+
## Override an Alias
13+
14+
```ps1
15+
Set-Alias <alias> <cmd_name>
16+
```
17+
18+
## Checkout Alias
19+
20+
- Check out by alias
21+
22+
```ps1
23+
Get-Alias <alias>
24+
```
25+
26+
Or use `Get-Command`
27+
28+
```ps1
29+
Get-Command <alias>
30+
```
31+
32+
- Check out by command name
33+
34+
```ps1
35+
Get-Alias -Definition <cmd_name>
36+
```
37+
38+
## Builtin Aliases
39+
40+
Powershell ships with some builtin aliases, checkout by this command:
41+
42+
```ps1
43+
Get-Alias | Where-Object { $_.Options -match 'ReadOnly|Constant' }
44+
```
45+
46+
> [!note]
47+
> Do not use custom aliases for public repository.
48+
49+
## Differ from Bash
50+
51+
Alias in powershell is only a name alias for a command, it can never take any predetermined parameters or flags like in bash.
52+
53+
```sh
54+
alias gl='git log' # fine
55+
```
56+
57+
```ps1
58+
New-Alias gl 'git log' # not allowed! # [!code error]
59+
```
60+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Overview
2+
3+
- Dynamic typing
4+
- Case insensitive

docs/document/Powershell/docs/Powershell as a Language/Array.md

Whitespace-only changes.

docs/document/Powershell/docs/Powershell as a Language/Comment.md

Whitespace-only changes.

docs/document/Powershell/docs/Powershell as a Language/Evaluation.md

Whitespace-only changes.

docs/document/Powershell/docs/Powershell as a Language/Function.md

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,38 @@
22

33
## Parameter
44

5-
There's no positional parameters, it's a table-like definition, can be specified with any order.
65
Parameters are wrapped inside a function block with `param(...)`
76

87
```ps1
98
function Foo {
109
param (
11-
[string]$foo
10+
$Foo
1211
)
1312
}
1413
```
1514

15+
> [!NOTE]
16+
>
17+
> Default type of a parameter is `System.Object`.
18+
19+
### Positional Parameter
20+
21+
Positional parameters allows passing values with explicit names.
22+
23+
```ps1
24+
function Foo {
25+
param (
26+
[string] $Foo,
27+
[string] $Bar
28+
)
29+
30+
Write-Output "$Foo $Bar"
31+
}
32+
33+
Foo -Foo foo -Bar bar
34+
Foo foo bar # it's the same # [!code highlight]
35+
```
36+
1637
### Default Parameter
1738

1839
```ps1
@@ -32,13 +53,13 @@ While `switch` will remain `$false` when unspecified.
3253
```ps1
3354
function Foo {
3455
param (
35-
[switch]$foo
36-
[bool]$bar
56+
[switch]$Foo
57+
[bool]$Bar
3758
)
3859
}
3960
4061
# this is why we should use `switch` instead.
41-
Foo -foo -bar $true # [!code highlight]
62+
Foo -Foo -Bar $true # [!code highlight]
4263
```
4364

4465
### Required Parameter
@@ -52,6 +73,25 @@ param (
5273
)
5374
```
5475

76+
### Parameter Alias
77+
78+
Parameters can have aliases. It's not needed for most of time though since pwsh can distinguish option by leading string.
79+
80+
```ps1
81+
function Person {
82+
param (
83+
[Alias("n")] # [!code highlight]
84+
[string]$Name,
85+
86+
[Alias("a")] # [!code highlight]
87+
[int]$Age
88+
)
89+
Write-Host "Name: $Name, Age: $Age"
90+
}
91+
92+
Person -n "Alice" -a 30 # [!code highlight]
93+
```
94+
5595
## Lifetime
5696

5797
- Function should be define before it was called.

docs/document/Powershell/docs/Powershell as a Language/Operators.md

Whitespace-only changes.

docs/document/Powershell/docs/Powershell as a Language/String.md

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
3+
## Terminology
4+
5+
Powershell has its own terminologies besides other shells like bash.
6+
It's a shell integrated with .NET, it's not a independent platform.
7+
8+
- `cmdlet`: builtin utils inside powershell, implemented using other languages like `C#`.
9+
- `function`: a command implemented using powershell language itself.
10+
- `application`: external executables.

0 commit comments

Comments
 (0)