This PowerShell script (profile.ps1
) serves as an advanced user profile, building upon the base profile (Microsoft.PowerShell_profile.ps1
) and shared HelperFunctions.ps1
. It provides a wide range of custom functions and configurations designed for media management, development workflows, and enhanced command-line use.
Key Sections and Features:
-
Configuration (
#region Configuration
)- Sets PowerShell preferences like
$ErrorActionPreference = 'Stop'
. - Configures PSReadLine options for history.
- Checks for required PowerShell modules (like PSReadLine).
- Defines and checks for external command-line dependencies like
ffprobe
,starship
,git
, andmagick
using theTest-ExternalDependency
helper function. - Sets up global variables for default image and video file extensions (
$global:DefaultImageCheckExtensions
,$global:DefaultVideoCheckExtensions
,$global:DefaultVideoFilterExtensions
).
- Sets PowerShell preferences like
-
Helper Functions (
#region Helper Functions
)- Loads shared functions (like
Write-LogMessage
,Test-AdminRole
,Reload-Profile
) by dot-sourcingHelperFunctions.ps1
.
- Loads shared functions (like
-
Generic Functions (
#region Generic Functions
)New-NumberedFolders
: A reusable function to create sequences of numbered folders (e.g., "Chapter 001", "season 02") based on a format string.
-
File Management Functions (
#region File Management Functions
)Compress-ToCBZ
: Creates Comic Book Zip (.cbz) files from image folders. It automatically attempts to derive Series, Volume, and Chapter information from the folder structure (Series\Volume ##\Chapter ##
orSeries\Chapter ##
), generates aComicInfo.xml
metadata file (allowing overrides for writer, genre, rating, date, etc.), compresses the contents, places the CBZ in the grandparent directory (as per the latest modification), and cleans up the temporary XML. (Dependency: ImplicitlyCompress-Archive
)Move-PDFsToFolders
: Organizes PDF files by creating a subfolder named after each PDF and moving the file into it.Rename-ImageFilesSequentially
: Renames images (.webp, .jpeg, .jpg, .png) in a folder to a sequential format (e.g.,001.jpg
,002.png
) using intelligent sorting and a temporary directory.Rename-NumberedFiles
: Renames files with purely numeric names (e.g.,1.txt
,10.jpg
) to have consistent zero-padding based on the highest number found (e.g.,01.txt
,10.jpg
).Set-StandardSeasonFolderNames
: Renames folders matching "season #" (case-insensitive, allows space or underscore) to the standard "season XX" format (two digits).Rename-SeriesEpisodes
: Renames video files within "season XX" folders (or the current folder) to the standard Plex/Jellyfin format (series_name_sXXeYY.ext
). It attempts to derive the series name and uses season/episode numbering based on folder structure and file sorting. Allows overriding the series name and default season.Rename-NewSeriesEpisode
: Renames a single new video file based on the naming convention and highest episode number of existing files (series_name_sXXeYY.ext
) in the same directory.Set-RecursivePermissions
: (Use with caution, requires Admin) Grants 'Everyone:Modify' permissions recursively to a folder and its contents.
-
Folder Creation Functions (
#region Folder Creation Functions
)New-ChapterFolders
: A wrapper aroundNew-NumberedFolders
specifically for creating folders named "Chapter XXX" (3 digits).New-SeasonFolders
: A wrapper aroundNew-NumberedFolders
specifically for creating folders named "season XX" (2 digits).
-
Image Processing Functions (
#region Image Processing Functions
)Convert-ImageFormat
: Batch converts images between formats using ImageMagick, with options for quality, optimization, and keeping/deleting originals. (Dependency: ImageMagick -magick
command)
-
Media Information Functions (
#region Media Information Functions
)Get-VideoInfo
: Retrieves video metadata (codec, resolution, duration, optional audio/subtitle info) using ffprobe. (Dependency: FFmpeg -ffprobe
command)
-
Symbolic Link Functions (
#region Symbolic Link Functions
)New-FavoriteLinks
: Searches a source path for folders ending in a star emoji (⭐) and creates directory junctions (symbolic links) to them in a destination folder. Attempts to name links as "Artist - Work Name" based on folder structure. (Dependency:mklink
viacmd.exe
, often requires Admin/Developer Mode)
-
External Tools (
#region External Tools
)Invoke-WinUtil
/Invoke-WinUtilDev
: Functions to run Chris Titus Tech's WinUtil scripts.Upload-Hastebin
: Uploads file content tobin.christitus.com
.
-
Git Integration (
#region Git Integration
)- Provides wrapper functions (
Git-Status
,Git-Add
,Git-Commit
,Git-Push
, etc.) for common Git commands. This section is only active if thegit
command is detected in the system PATH. (Dependency: Git)
- Provides wrapper functions (
-
Profile Initialization (
#region Profile Initialization
)- Sets a custom window title.
- Ensures a custom temp directory exists.
- Logs profile loading completion.
-
Aliases (
#region Aliases
)- Sets up numerous aliases for both built-in cmdlets and the custom functions defined in this profile (e.g.,
reload
,rimg
,mpdf
,cbz
,cimg
,gs
,ga
,gp
, etc.).
- Sets up numerous aliases for both built-in cmdlets and the custom functions defined in this profile (e.g.,