summaryrefslogtreecommitdiff
path: root/powershell
diff options
context:
space:
mode:
authoradmin <contact@optics-design.com>2025-04-26 22:57:28 +0200
committeradmin <contact@optics-design.com>2025-04-26 22:57:28 +0200
commit0ede748577b45f3d9ed91a0fdaf142953fe7a744 (patch)
tree14faf3fc51d66beebb477e045a165c2d3d77b9eb /powershell
Initial Commit
Diffstat (limited to 'powershell')
-rw-r--r--powershell/Microsoft.PowerShell_profile.ps1188
1 files changed, 188 insertions, 0 deletions
diff --git a/powershell/Microsoft.PowerShell_profile.ps1 b/powershell/Microsoft.PowerShell_profile.ps1
new file mode 100644
index 0000000..c05df79
--- /dev/null
+++ b/powershell/Microsoft.PowerShell_profile.ps1
@@ -0,0 +1,188 @@
+#Prompt
+
+function prompt {
+
+ $Date = Get-Date -Format 'dddd HH:mm:ss'
+
+ $LastCommand = Get-History -Count 1
+ if ($lastCommand) { $RunTime = ($lastCommand.EndExecutionTime - $lastCommand.StartExecutionTime).TotalSeconds }
+
+ $ElapsedTime = [math]::Round(($RunTime), 3)
+ $ElapsedTime = -join (($ElapsedTime.ToString()), "s")
+
+ Write-Host $PWD -ForegroundColor Blue -NoNewline
+ Write-Host " [$date]" -ForegroundColor Yellow
+
+ Write-Host "[$elapsedTime] " -NoNewline -ForegroundColor Green
+ 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-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
+ }
+}
Back to https://optics-design.com