Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subdirectories/arguments for shortcuts #1945

Merged
merged 2 commits into from
Jan 8, 2018
Merged
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
19 changes: 17 additions & 2 deletions lib/shortcuts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ function create_startmenu_shortcuts($manifest, $dir, $global, $arch) {
$shortcuts | ?{ $_ -ne $null } | % {
$target = $_.item(0)
$name = $_.item(1)
startmenu_shortcut "$dir\$target" $name $global
try {
$arguments = $_.item(2)
} catch {
$arguments = ""
}
startmenu_shortcut "$dir\$target" $name $global $arguments
}
}

Expand All @@ -16,7 +21,7 @@ function shortcut_folder($global) {
"$([environment]::getfolderpath('startmenu'))\Programs\Scoop Apps"
}

function startmenu_shortcut($target, $shortcutName, $global) {
function startmenu_shortcut($target, $shortcutName, $global, $arguments) {
if(!(Test-Path $target)) {
Write-Host -f DarkRed "Creating shortcut for $shortcutName ($(fname $target)) failed: Couldn't find $target"
return
Expand All @@ -25,9 +30,19 @@ function startmenu_shortcut($target, $shortcutName, $global) {
if(!(Test-Path $scoop_startmenu_folder)) {
New-Item $scoop_startmenu_folder -type Directory
}
$dirname = [System.IO.Path]::GetDirectoryName($shortcutName)
if ($dirname) {
$dirname = [io.path]::combine($scoop_startmenu_folder, $dirname)
if(!(Test-Path $dirname)) {
New-Item $dirname -type Directory
}
}
$wsShell = New-Object -ComObject WScript.Shell
$wsShell = $wsShell.CreateShortcut("$scoop_startmenu_folder\$shortcutName.lnk")
$wsShell.TargetPath = "$target"
if ($arguments) {
$wsShell.Arguments = $arguments
}
$wsShell.Save()
write-host "Creating shortcut for $shortcutName ($(fname $target))"
}
Expand Down