blob: e9a1b38bf2c106c40f490b0c5d1b0fdafcb0031e (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#Prompt
function prompt {
$Date = Get-Date -Format 'dddd HH:mm:ss'
Write-Host $PWD -ForegroundColor Blue -NoNewline
Write-Host " [$date]" -ForegroundColor Yellow
return "> "
} #end prompt function
Set-PSReadLineOption -EditMode Emacs `
-BellStyle None `
-PredictionSource History `
-Colors @{
"Command" = "Green"
"Parameter" = "DarkGray"
"String" = "DarkYellow"
"Keyword" = "DarkYellow"
"Comment" = "Gray"
"Variable" = "DarkGray"
}
$PSStyle.FileInfo.Directory = "`e[38;2;255;191;0m"
Set-PSReadLineKeyHandler -Key Ctrl+Spacebar -Function AcceptSuggestion #ForwardWord
Set-PSReadLineKeyHandler -Chord 'Ctrl+i' -Function MenuComplete
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+g' -PSReadlineChordReverseHistory 'Ctrl+r'
####################### Private Functions ###################################
. "$env:SYNC\Repos\Powershell\BackupFunctions.ps1"
####################### Functions ###################################
#Reduce video quality for archiving large sets.
function Convert-Videos {
param (
[Parameter(Mandatory = $true)]
[string]$InputFolder,
[Parameter(Mandatory = $true)]
[string]$OutputFolder
)
# Resolve relative paths to absolute paths
$InputFolder = (Resolve-Path $InputFolder).Path
$InputFolder = Join-Path $InputFolder "\*" #necessary since gci -include needs this
$OutputFolder = (Resolve-Path $OutputFolder).Path
# Process each video file in the input folder
Get-ChildItem -Path $InputFolder -File -Include *.mp4,*.mkv,*.avi,*.webm | ForEach-Object {
$inputFile = $_.FullName
$outputFile = Join-Path $OutputFolder $_.Name
Write-Host "Processing $inputFile to $outputFile"
# Run FFmpeg command
ffmpeg -i $inputFile -vf "scale=-1:720,fps=30" -c:v h264_nvenc -preset fast -cq 30 -c:a aac -b:a 128k $outputFile
}
Write-Host "Conversion complete! Files saved to $OutputFolder"
}
function Convert-Videoswebm {
param (
[Parameter(Mandatory = $true)]
[string]$InputFolder,
[Parameter(Mandatory = $true)]
[string]$OutputFolder
)
# Resolve relative paths to absolute paths
$InputFolder = (Resolve-Path $InputFolder).Path
$InputFolder = Join-Path $InputFolder "\*" #necessary since gci -include needs this
$OutputFolder = (Resolve-Path $OutputFolder).Path
# Process each video file in the input folder
Get-ChildItem -Path $InputFolder -File -Include *.webm | ForEach-Object {
$inputFile = $_.FullName
$outputFile = Join-Path $OutputFolder $_.Name
Write-Host "Processing $inputFile to $outputFile"
# Run FFmpeg command
ffmpeg -hwaccel cuda -i $inputFile -vf "scale=-1:720,fps=30" -c:v av1_nvenc -cq 30 -preset p4 -c:a copy $outputFile
# ffmpeg -i $inputFile -vf "scale=-1:720,fps=30" -crf 30 -b:v 1M -c:a copy -threads 0 $outputFile
}
Write-Host "Conversion complete! Files saved to $OutputFolder"
}
#Generate a file list for ffmpeg operation (primary use for concat).
function genlistffmpeg{
foreach ($i in Get-ChildItem .\*.wav) {"file '$i'" | Out-File mylist.txt -Encoding utf8 -Append}
}
# Utilities
# Better way of starting nvim
function in {
param (
[string]$FilePath
)
nvim $FilePath
# }
}
#Start CODE V
function cv{
param (
[string]$SourcePath = "D:\Optics\CODEV\CVUSER\Defaults.seq"
)
# Check if the source file exists
if (Test-Path -Path $SourcePath) {
# Copy the file to the current active directory
Copy-Item -Path $SourcePath -Destination (Get-Location) -Force
}
else {
Write-Host "File '$FileName' not found in the specified directory."
}
codevm
}
# Backup Functions
function rcopy {
param (
[string]$source,
[string]$destination
)
# Construct the Robocopy command with 16 threads
$robocopyCommand = "robocopy `"$source`" `"$destination`" /MT:16 /COPY:DAT /DCOPY:DAT /E"
# Execute the Robocopy command
Invoke-Expression $robocopyCommand
}
function rmirror {
param (
[string]$source,
[string]$destination
)
# Construct the Robocopy command with 16 threads
$robocopyCommand = "robocopy `"$source`" `"$destination`" /MIR /MT:16 /COPY:DAT /DCOPY:DAT"
# Execute the Robocopy command
Invoke-Expression $robocopyCommand
}
function rt{
rterm --no-save
}
function lsr {
param (
[int]$Days = 7, # Default to 7 days if no parameter is provided
[string]$Path = "." # Default to the current directory
)
Get-ChildItem -Path $Path -File -Recurse |
Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-$Days) }
}
#Alias Programs
function i {ipython}
function pidof {Get-Process -Name $args}
function which {Get-Command $args}
function lsblk {Get-PSDrive}
function blkid {Get-Volume}
function gfh {Get-FileHash}
function dict {wsl zsh -c "dict $args | colorit"}
function Search-Markdown {
param (
[string]$query = $(Read-Host "Enter search term")
)
$selected = rg --color=always --line-number --smart-case $query *.md | fzf --ansi --delimiter : --preview "bat --color=always --style=plain {(echo {1})}"
if ($selected -match "^([^:]+):(\d+)") {
$file = $matches[1]
$line = $matches[2]
code "$file" --goto $line # Open in VS Code at the correct line
}
}
|