@@ -3,6 +3,7 @@ package cmd
33import (
44 "fmt"
55 "net/url"
6+ "strings"
67
78 uicli "github.com/alperdrsnn/clime"
89 "github.com/git-hulk/clime/internal/installer"
@@ -43,17 +44,37 @@ Otherwise, the built-in default plugin list is used.`,
4344 return nil
4445 }
4546
46- terminal .Infof ("Installing %d default plugin(s)..." , len (plugins ))
47- fmt .Println ()
48-
4947 manifest , err := plugin .LoadManifest ()
5048 if err != nil {
5149 manifest = & plugin.Manifest {}
5250 }
5351
52+ // Filter out already-installed plugins.
53+ var missing []plugin.Plugin
54+ var skipped []string
55+ for _ , p := range plugins {
56+ if _ , exists := manifest .Get (p .Name ); exists {
57+ skipped = append (skipped , p .Name )
58+ } else {
59+ missing = append (missing , p )
60+ }
61+ }
62+
63+ if len (skipped ) > 0 {
64+ terminal .Infof ("Skipping %d already installed plugin(s): %s" , len (skipped ), formatNames (skipped ))
65+ }
66+
67+ if len (missing ) == 0 {
68+ terminal .Success ("All plugins are already installed." )
69+ return nil
70+ }
71+
72+ terminal .Infof ("Installing %d missing plugin(s)..." , len (missing ))
73+ fmt .Println ()
74+
5475 var failed []string
5576
56- for _ , p := range plugins {
77+ for _ , p := range missing {
5778 spinner := uicli .NewSpinner ().
5879 WithStyle (uicli .SpinnerDots ).
5980 WithColor (uicli .CyanColor ).
@@ -96,11 +117,16 @@ Otherwise, the built-in default plugin list is used.`,
96117 }
97118
98119 fmt .Println ()
99- terminal .Successf ("All %d plugins installed!" , len (plugins ))
120+ terminal .Successf ("All %d plugins installed!" , len (missing ))
100121 return nil
101122 },
102123}
103124
125+ // formatNames joins a slice of names into a comma-separated string.
126+ func formatNames (names []string ) string {
127+ return strings .Join (names , ", " )
128+ }
129+
104130// isURL returns true if the given string looks like an HTTP(S) URL.
105131func isURL (s string ) bool {
106132 u , err := url .Parse (s )
0 commit comments