Skip to content

Commit b223657

Browse files
rasar15ch13
authored andcommitted
Add subdirectories/arguments for shortcuts (#1945)
* Add support for subdirectories in shortcuts * Add argument option to shortcuts
1 parent 4b6dcdf commit b223657

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/shortcuts.ps1

+17-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ function create_startmenu_shortcuts($manifest, $dir, $global, $arch) {
44
$shortcuts | ?{ $_ -ne $null } | % {
55
$target = $_.item(0)
66
$name = $_.item(1)
7-
startmenu_shortcut "$dir\$target" $name $global
7+
try {
8+
$arguments = $_.item(2)
9+
} catch {
10+
$arguments = ""
11+
}
12+
startmenu_shortcut "$dir\$target" $name $global $arguments
813
}
914
}
1015

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

19-
function startmenu_shortcut($target, $shortcutName, $global) {
24+
function startmenu_shortcut($target, $shortcutName, $global, $arguments) {
2025
if(!(Test-Path $target)) {
2126
Write-Host -f DarkRed "Creating shortcut for $shortcutName ($(fname $target)) failed: Couldn't find $target"
2227
return
@@ -25,9 +30,19 @@ function startmenu_shortcut($target, $shortcutName, $global) {
2530
if(!(Test-Path $scoop_startmenu_folder)) {
2631
New-Item $scoop_startmenu_folder -type Directory
2732
}
33+
$dirname = [System.IO.Path]::GetDirectoryName($shortcutName)
34+
if ($dirname) {
35+
$dirname = [io.path]::combine($scoop_startmenu_folder, $dirname)
36+
if(!(Test-Path $dirname)) {
37+
New-Item $dirname -type Directory
38+
}
39+
}
2840
$wsShell = New-Object -ComObject WScript.Shell
2941
$wsShell = $wsShell.CreateShortcut("$scoop_startmenu_folder\$shortcutName.lnk")
3042
$wsShell.TargetPath = "$target"
43+
if ($arguments) {
44+
$wsShell.Arguments = $arguments
45+
}
3146
$wsShell.Save()
3247
write-host "Creating shortcut for $shortcutName ($(fname $target))"
3348
}

0 commit comments

Comments
 (0)