-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrg.ps1
41 lines (35 loc) Β· 934 Bytes
/
rg.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
function rgf {
$input | rg --files | rg $args
}
function rgf! {
$input | rg --files --no-ignore | rg $args
}
function rgfo {
$files = $input | rg --files | rg $args
Invoke-Code($files)
}
function rgfoa {
$input | rg --files | rg -l $args | ForEach-Object { Invoke-Code($_) }
}
function rgo {
$files = rg -l $args
Invoke-Code($files)
}
function rgoa {
rg -l $args | ForEach-Object { Invoke-Code($_) }
}
function Invoke-Code($files) {
if ($null -eq $files) {
# Nothing was found
Write-Output "No matches for this pattern"
} elseif ($files.GetType().Name -eq "String") {
# If there's only one result we can just open it.
code ($files)
} elseif ($files.Length -gt 1) {
# Otherwise we open a picker, if there are multiple choices.
$pickedFile = $files | fzf
if ($null -ne $pickedFile) {
code $pickedFile
}
}
}