-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_1.0.ps1
55 lines (55 loc) · 1.56 KB
/
edit_1.0.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
param(
[string]$file
)
If( -not (Test-Path(".\$file"))) {
Write-Output("File not found.")
Write-Output("Exiting edit.")
exit
}
Write-Output("[edit]: Welcome to edit. type `"help`"")
while(1) {
$prompt = read-host -prompt [edit]
if($prompt -eq "exit") {
Write-Output("Exiting edit.")
exit
}
if($prompt.StartsWith("add")) {
if($file -ne "") {
$lineadd = $prompt
[regex]$pattern = "add"
[regex]$pattern2 = " "
$lineadd = $pattern.Replace($lineadd, "", 1)
$lineadd = $pattern2.Replace($lineadd,"",1)
Add-Content -Path ".\$file" -Value "$lineadd"
Get-Content ".\$file"
}
if($file -eq "") {
Write-Output("[edit]: No file selected")
}
}
if($prompt -eq "help") {
Write-Output("[edit]: Help
[edit]: help Shows this menu
[edit]: add <string> Adds text to the selected file
[edit]: exit Exits edit
[edit]: sel <string> Selects a file
[edit]: read Reads the contents of the selected file"
)
}
if($prompt.StartsWith("sel")) {
$file = $prompt
[regex]$pattern = "sel"
[regex]$pattern2 = " "
$file = $pattern.Replace($file,"",1)
$file = $pattern2.Replace($file,"",1)
Write-Output("Selected file $file")
}
if($prompt -eq "read") {
if($file -eq "") {
Write-Output("[edit]: No file selected")
}
if($file -ne "") {
Get-Content(".\$file")
}
}
}