Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Private/Get-Slug.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function Get-Slug {
<#
.SYNOPSIS
Generates a simple, readable slug (alias) from input text.

.DESCRIPTION
Converts a string into a URL/alias-safe slug:
- Lowercases everything
- Replaces spaces/underscores with dashes
- Removes invalid characters
- Collapses multiple dashes
- Ensures max length (default: 16 chars) cutting at the nearest dash if possible

.PARAMETER InputString
The text you want to convert into a slug.

.PARAMETER MaxLen
Maximum allowed length of the slug (default: 16).

.EXAMPLE
New-Slug "Hello World! This is an Alias"
# hello-world

.EXAMPLE
New-Slug "Daily Check In" -MaxLen 12
# daily-check
#>
param(
[Parameter(Mandatory = $true)]
[string]$InputString,

[int]$MaxLen = 16
)

# Normalize
$slug = $InputString.ToLower().Trim()
$slug = $slug -replace '[\s_]+', '-' # spaces/underscores → dash
$slug = $slug -replace '[^a-z0-9-]', '' # keep only alphanumeric/dash
$slug = $slug -replace '-{2,}', '-' # collapse multiple dashes
$slug = $slug.Trim('-') # remove leading/trailing dashes

if ($slug.Length -gt $MaxLen) {
# Try to cut at the last dash before max length
$cut = $slug.Substring(0, $MaxLen)
$lastDash = $cut.LastIndexOf('-')
if ($lastDash -gt 0) {
$slug = $cut.Substring(0, $lastDash)
}
else {
$slug = $cut.TrimEnd('-')
}
}

return $slug
}
4 changes: 3 additions & 1 deletion Public/Functions/New-Task.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ function New-Task {
"attribute" = $Attribute
}

if ($Alias) { $body.alias = $Alias }
if ($Alias) { $body.alias = $Alias } else {
$body.alias = (Get-Slug $Text)
}
if ($Note) { $body.notes = $Note }
if ($Tags) {
$tagIds = @()
Expand Down
6 changes: 3 additions & 3 deletions Public/Functions/Set-Task.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function Set-Task {
function Set-Task {
<#
.SYNOPSIS
Updates an existing Habitica task.

.DESCRIPTION
Calls the Habitica API to update a task by ID.
Calls the Habitica API to update a task by ID.
Parameters are grouped into sets depending on the task type (`todo`, `daily`, or `habit`).

.PARAMETER TaskId
Expand Down Expand Up @@ -100,7 +100,7 @@ function Set-Task {
)

begin {

}

process {
Expand Down
Binary file modified pshabitica.psd1
Binary file not shown.
Loading