Skip to content

Commit ca573e2

Browse files
committed
grrrr
1 parent 1dfb754 commit ca573e2

File tree

7 files changed

+141
-1
lines changed

7 files changed

+141
-1
lines changed

docs/document/Bash/docs/Bash as A Language/String.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# String
22

3-
# Native String
3+
## Native String
44

55
Strings in bash can be native without any quote.
66

File renamed without changes.

docs/document/Powershell/docs/Alias.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ alias gl='git log' # fine
5858
New-Alias gl 'git log' # not allowed! # [!code error]
5959
```
6060

61+
> [!TIP]
62+
> Use functions to do alias with predetermined parameters in your profile.
63+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Overview
2+
3+
**FileSystem** is a builtin **PSProvider** in Powershell.
4+
5+
FileSystem can have one or more **PSDrive** depends on the system.
6+
7+
In windows, drives can be `C:`, `D:` and so on. In linux they can be some mount points.
8+
9+
This is introduces how to manipulate file system objects with item-related cmdlet.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Working Directory
2+
3+
## Change Directory
4+
5+
```ps1
6+
Set-Location <path>
7+
```
8+
9+
Powershell has three builtin aliases for `Set-Location`
10+
11+
```console
12+
$ Get-Alias -Definition 'Set-Location'
13+
14+
CommandType Name Version Source
15+
----------- ---- ------- ------
16+
Alias cd -> Set-Location
17+
Alias chdir -> Set-Location
18+
Alias sl -> Set-Location
19+
```
20+
21+
## Current Working Directory
22+
23+
There's two ways to get current working directory in Powershell.
24+
25+
- `$PWD` builtin string variable. Refreshes on each time location changed.
26+
- `Get-Location` cmdlet. Returns a `PathInfo` object.
27+
- `pwd` is an builtin alias for `Get-Location`.
28+
29+
```ps1
30+
(Get-Location).Path # equivelant to $pwd
31+
```
32+
33+
```console
34+
$ Get-Location | select -Property *
35+
36+
Drive Provider ProviderPath Path
37+
----- -------- ------------ ----
38+
D Microsoft.PowerShell.Core\FileSystem
39+
```
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Create Item
2+
3+
Powershell uses a single cmdlet named `New-Item` to represent all kinds of creation logic for file system items like folder, file, symlinks...
4+
5+
> [!TIP]
6+
> Use `ni` alias for `New-Item`.
7+
8+
## File
9+
10+
`New-Item` creates file without extra options by default.
11+
12+
```ps1
13+
New-Item -Path <file_path>
14+
# or
15+
New-Item <file_path>
16+
```
17+
18+
> [!NOTE]
19+
> `-Path` is the first positional parameter which can be ignored.
20+
21+
> [!NOTE]
22+
> `-Path` is `string[]`, so you can create multiple items at a same time with same options.
23+
24+
> [!TIP]
25+
> Use `-Force` flag to overwrite existing target.
26+
27+
## Directory
28+
29+
```ps1
30+
New-Item <dir_path> -ItemType Directory
31+
```
32+
Powershell has another builtin function called `mkdir`, it's a shorthand for `New-Item <dir_path> -ItemType Directory`
33+
34+
```ps1
35+
mkdir <dir_path>
36+
```
37+
38+
> [!NOTE]
39+
> When creating directory, `New-Item` ensures necessary parent directories by default, so there's no things like `mkdir -p`.
40+
41+
> [!TIP]
42+
> Use `-Force` flag to overwrite existing target.
43+
44+
## Symbolic Link
45+
46+
```ps1
47+
New-Item <symlink_path> -Target <source> -ItemType SymbolicLink
48+
```
49+
50+
> [!TIP]
51+
> Use `-Force` flag to overwrite existing target.
52+
53+
## Ignore Wildcards
54+
55+
`-Path` translates wildcards by default, if you do need to include special characters from wildcards syntax for your new item, use `-LiteralPath`.
56+
57+
```ps1
58+
New-Item -LiteralPath 'foo*.txt' # creates a file literally named `foo*.txt`
59+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# PSProvider
2+
3+
**PSProvider** is another confusing concept from powershell.
4+
A PSProvider basically provides a way to browse and access items from a source.
5+
There's some builtin PSProviders like `FileSystem`, `Registry` on windows and so on.
6+
7+
You can check all available providers by:
8+
9+
```console
10+
$ Get-PSProvider
11+
12+
Name Capabilities Drives
13+
---- ------------ ------
14+
Registry ShouldProcess {HKLM, HKCU}
15+
Alias ShouldProcess {Alias}
16+
Environment ShouldProcess {Env}
17+
FileSystem Filter, ShouldProcess, Credentials {C, D, Temp}
18+
Function ShouldProcess {Function}
19+
Variable ShouldProcess {Variable}
20+
Certificate ShouldProcess {Cert}
21+
WSMan Credentials {WSMan}
22+
```
23+
24+
## PSDrive
25+
26+
Each PSProvider can have one or more **PSDrive**.
27+
28+
PSDrive is kind of like one of the entries of a PSProvider.
29+
30+
Check all available PSDrive by `Get-PSDrive`.

0 commit comments

Comments
 (0)