Skip to content

Commit

Permalink
grrrr
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpchen committed Nov 15, 2024
1 parent 1dfb754 commit ca573e2
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/document/Bash/docs/Bash as A Language/String.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# String

# Native String
## Native String

Strings in bash can be native without any quote.

Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions docs/document/Powershell/docs/Alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ alias gl='git log' # fine
New-Alias gl 'git log' # not allowed! # [!code error]
```

> [!TIP]
> Use functions to do alias with predetermined parameters in your profile.
9 changes: 9 additions & 0 deletions docs/document/Powershell/docs/File System/1.Overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Overview

**FileSystem** is a builtin **PSProvider** in Powershell.

FileSystem can have one or more **PSDrive** depends on the system.

In windows, drives can be `C:`, `D:` and so on. In linux they can be some mount points.

This is introduces how to manipulate file system objects with item-related cmdlet.
39 changes: 39 additions & 0 deletions docs/document/Powershell/docs/File System/2.Working Directory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Working Directory

## Change Directory

```ps1
Set-Location <path>
```

Powershell has three builtin aliases for `Set-Location`

```console
$ Get-Alias -Definition 'Set-Location'

CommandType Name Version Source
----------- ---- ------- ------
Alias cd -> Set-Location
Alias chdir -> Set-Location
Alias sl -> Set-Location
```

## Current Working Directory

There's two ways to get current working directory in Powershell.

- `$PWD` builtin string variable. Refreshes on each time location changed.
- `Get-Location` cmdlet. Returns a `PathInfo` object.
- `pwd` is an builtin alias for `Get-Location`.

```ps1
(Get-Location).Path # equivelant to $pwd
```

```console
$ Get-Location | select -Property *

Drive Provider ProviderPath Path
----- -------- ------------ ----
D Microsoft.PowerShell.Core\FileSystem
```
59 changes: 59 additions & 0 deletions docs/document/Powershell/docs/File System/3.Create Item.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Create Item

Powershell uses a single cmdlet named `New-Item` to represent all kinds of creation logic for file system items like folder, file, symlinks...

> [!TIP]
> Use `ni` alias for `New-Item`.
## File

`New-Item` creates file without extra options by default.

```ps1
New-Item -Path <file_path>
# or
New-Item <file_path>
```

> [!NOTE]
> `-Path` is the first positional parameter which can be ignored.
> [!NOTE]
> `-Path` is `string[]`, so you can create multiple items at a same time with same options.
> [!TIP]
> Use `-Force` flag to overwrite existing target.
## Directory

```ps1
New-Item <dir_path> -ItemType Directory
```
Powershell has another builtin function called `mkdir`, it's a shorthand for `New-Item <dir_path> -ItemType Directory`

```ps1
mkdir <dir_path>
```

> [!NOTE]
> When creating directory, `New-Item` ensures necessary parent directories by default, so there's no things like `mkdir -p`.
> [!TIP]
> Use `-Force` flag to overwrite existing target.
## Symbolic Link

```ps1
New-Item <symlink_path> -Target <source> -ItemType SymbolicLink
```

> [!TIP]
> Use `-Force` flag to overwrite existing target.
## Ignore Wildcards

`-Path` translates wildcards by default, if you do need to include special characters from wildcards syntax for your new item, use `-LiteralPath`.

```ps1
New-Item -LiteralPath 'foo*.txt' # creates a file literally named `foo*.txt`
```
30 changes: 30 additions & 0 deletions docs/document/Powershell/docs/PSDrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# PSProvider

**PSProvider** is another confusing concept from powershell.
A PSProvider basically provides a way to browse and access items from a source.
There's some builtin PSProviders like `FileSystem`, `Registry` on windows and so on.

You can check all available providers by:

```console
$ Get-PSProvider

Name Capabilities Drives
---- ------------ ------
Registry ShouldProcess {HKLM, HKCU}
Alias ShouldProcess {Alias}
Environment ShouldProcess {Env}
FileSystem Filter, ShouldProcess, Credentials {C, D, Temp}
Function ShouldProcess {Function}
Variable ShouldProcess {Variable}
Certificate ShouldProcess {Cert}
WSMan Credentials {WSMan}
```

## PSDrive

Each PSProvider can have one or more **PSDrive**.

PSDrive is kind of like one of the entries of a PSProvider.

Check all available PSDrive by `Get-PSDrive`.

0 comments on commit ca573e2

Please sign in to comment.