@@ -67,8 +67,61 @@ func installPackagesByType(pkgType string, pkgInfos []types.PackageInfo, options
6767 utils .PrintStatus (utils .Cyan , fmt .Sprintf ("Processing %s: %s" , pkgType , pkgInfo .Name ))
6868 }
6969
70+ alreadyInstalled := false
71+ switch pkgType {
72+ case "tap" :
73+ if output , err := utils .RunCommand ("brew" , "tap" ); err == nil {
74+ installedTaps := strings .Fields (output )
75+ for _ , installed := range installedTaps {
76+ if installed == pkgInfo .Name {
77+ alreadyInstalled = true
78+ break
79+ }
80+ }
81+ }
82+ case "brew" :
83+ if output , err := utils .RunCommand ("brew" , "list" , "--formula" ); err == nil {
84+ installedBrews := strings .Fields (output )
85+ for _ , installed := range installedBrews {
86+ if installed == pkgInfo .Name || strings .HasPrefix (pkgInfo .Name , installed + "/" ) {
87+ alreadyInstalled = true
88+ break
89+ }
90+ }
91+ }
92+ case "cask" :
93+ if output , err := utils .RunCommand ("brew" , "list" , "--cask" ); err == nil {
94+ installedCasks := strings .Fields (output )
95+ for _ , installed := range installedCasks {
96+ if installed == pkgInfo .Name {
97+ alreadyInstalled = true
98+ break
99+ }
100+ }
101+ }
102+ case "mas" :
103+ if output , err := utils .RunCommand ("mas" , "list" ); err == nil {
104+ lines := strings .Split (strings .TrimSpace (output ), "\n " )
105+ for _ , line := range lines {
106+ if strings .HasPrefix (line , strconv .FormatInt (pkgInfo .ID , 10 )) {
107+ alreadyInstalled = true
108+ break
109+ }
110+ }
111+ }
112+ }
113+
70114 if options .DryRun {
71- utils .PrintStatus (utils .Yellow , fmt .Sprintf ("[DRY RUN] Would install %s: %s" , pkgType , pkgInfo .Name ))
115+ if ! alreadyInstalled {
116+ utils .PrintStatus (utils .Yellow , fmt .Sprintf ("[DRY RUN] Would install %s: %s" , pkgType , pkgInfo .Name ))
117+ }
118+ continue
119+ }
120+
121+ if alreadyInstalled {
122+ if options .Verbose {
123+ utils .PrintStatus (utils .Yellow , fmt .Sprintf ("%s already installed: %s" , strings .Title (pkgType ), pkgInfo .Name ))
124+ }
72125 continue
73126 }
74127
0 commit comments