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
20 changes: 14 additions & 6 deletions private/Alias-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,29 @@ function Resolve-FullPath([string]$path) {
return [System.IO.Path]::GetFullPath((Join-Path $base $path))
}

function Add-Alias([string]$argument1, [string]$argument2) {
function Add-Alias {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$argument1,
[string]$argument2
)

Write-Verbose "Adding alias with argument1: $argument1, argument2: $argument2"

if (-not [string]::IsNullOrEmpty($argument2) ) {
Write-Verbose "Adding alias: $argument1 from path: $argument2"
Add-AliasFromPath -alias $argument1 -path $argument2
}
else {
Write-Verbose "Adding alias from JSON"
Add-AliasFromJson($argument1)
}

$json = [AliasPathMapping]::ToJson($script:ALIASES)
$json | Out-File $script:JSON_FILE_PATH
Write-Verbose "Alias added successfully."
}

function Add-AliasFromPath([string]$alias, [string]$path) {
Expand All @@ -84,8 +97,6 @@ function Add-AliasFromPath([string]$alias, [string]$path) {
return $script:ALIASES
}

$script:ALIASES = @($script:ALIASES)

$newAliasPath = [AliasPathMapping]::new()
$newAliasPath.Aliases = @($alias)
$newAliasPath.WindowsPath = $resolvedPath
Expand All @@ -107,7 +118,6 @@ function Add-AliasFromPath([string]$alias, [string]$path) {
}

function Add-AliasFromJson([string]$jsonString) {
$script:ALIASES = @($script:ALIASES)
$newAliasPath = [AliasPathMapping]::FromJson($jsonString)

if (!($newAliasPath)) {
Expand Down Expand Up @@ -137,8 +147,6 @@ function Add-AliasFromJson([string]$jsonString) {
}

function Remove-Alias([string] $alias) {
$script:ALIASES = @($script:ALIASES)

# If alias isn't present anywhere, do nothing
if (-not ($script:ALIASES | Where-Object { $_.Aliases -contains $alias })) {
return $script:ALIASES
Expand Down
61 changes: 33 additions & 28 deletions private/Get-Commands.ps1
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
. $PSScriptRoot\..\classes\Command.ps1

$script:CachedCommands = $null

function Get-Commands {
return @(
[Command]::new("cd", "Set-Alias-Location")
[Command]::new("rider", "Open-Command rider" )
[Command]::new("vs", "Open-Command visualstudio" )
[Command]::new("visualstudio", "Open-Command visualstudio" )
[Command]::new("intellij", "Open-Command intellij")
[Command]::new("code", "Open-Command code")
[Command]::new("ws", "Open-Command webstorm")
[Command]::new("webstorm", "Open-Command webstorm")
[Command]::new("explorer", "Open-Command explorer")
[Command]::new("sourcefolder", "Set-Source-Folder")
[Command]::new("help", 'Write-Host $(Get-DynamicHelp $commandNames)' )
[Command]::new("alias", @(
[Command]::new("add", "Add-Alias" ),
[Command]::new("remove", "Remove-Alias" )
[Command]::new("list", { Write-Host ($script:ALIASES | Format-Table | Out-String) })
)
if ($null -eq $script:CachedCommands) {
$script:CachedCommands = @(
[Command]::new("cd", "Set-Alias-Location")
[Command]::new("rider", "Open-Command rider" )
[Command]::new("vs", "Open-Command visualstudio" )
[Command]::new("visualstudio", "Open-Command visualstudio" )
[Command]::new("intellij", "Open-Command intellij")
[Command]::new("code", "Open-Command code")
[Command]::new("ws", "Open-Command webstorm")
[Command]::new("webstorm", "Open-Command webstorm")
[Command]::new("explorer", "Open-Command explorer")
[Command]::new("sourcefolder", "Set-Source-Folder")
[Command]::new("help", 'Write-Host $(Get-DynamicHelp $commandNames)' )
[Command]::new("alias", @(
[Command]::new("add", "Add-Alias" ),
[Command]::new("remove", "Remove-Alias" )
[Command]::new("list", { Write-Host ($script:ALIASES | Format-Table | Out-String) })
)
[Command]::new("todo", @(
[Command]::new("add", "Add-Todo")
[Command]::new("remove", { Write-Host "TODO: remove item from todolist: qp todo remove x" })
[Command]::new("list", { Write-Host "TODO: Output todo list" })
)
)
[Command]::new("todo", @(
[Command]::new("add", "Add-Todo")
[Command]::new("remove", { Write-Host "TODO: remove item from todolist: qp todo remove x" })
[Command]::new("list", { Write-Host "TODO: Output todo list" })
)
[Command]::new("version", { Write-Host (Get-MyModuleVersion) })
[Command]::new("update", {
Write-Host "updating quickpath..."
Update-Module quickpath
Write-Host "quickpath has been updated"
})
)
[Command]::new("version", { Write-Host (Get-MyModuleVersion) })
[Command]::new("update", {
Write-Host "updating quickpath..."
Update-Module quickpath
Write-Host "quickpath has been updated"
})
)
}
return $script:CachedCommands
}
6 changes: 3 additions & 3 deletions quickpath.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'quickpath.psm1'

# Version number of this module.
ModuleVersion = '0.14.3'
ModuleVersion = '0.14.3'
# ID used to uniquely identify this module
GUID = '376719b2-2cdd-47e8-b82b-b01870c08ac8'

Expand All @@ -31,7 +31,7 @@
and even makes it easy to open the folders/projects in your favorite tools."

# Minimum version of the PowerShell engine required by this module
# PowerShellVersion = ''
PowerShellVersion = '7.0'

# Name of the PowerShell host required by this module
# PowerShellHostName = ''
Expand Down Expand Up @@ -93,7 +93,7 @@
PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
# Tags = @()
Tags = @('Navigation', 'CLI', 'Productivity', 'FileSystem')

# A URL to the license for this module.
# LicenseUri = ''
Expand Down
2 changes: 1 addition & 1 deletion quickpath.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $commandText
function qp {
try {
$firstArgument = $args[0]
$remainingArguments = $remainingArguments = $args[1..($args.length - 1)]
$remainingArguments = $args[1..($args.length - 1)]

$script:JSON_FILE_PATH = Get-Script-Path
$commands = Get-Commands
Expand Down