-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
42 lines (35 loc) · 900 Bytes
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package plugin
import (
"fmt"
"os"
"github.com/josledp/termcolor"
)
//User is the plugin struct
type User struct {
user string
hostname string
}
//Name returns the plugin name
func (User) Name() string {
return "user"
}
//Help returns help information about this plugin
func (User) Help() (description string, options map[string]string) {
description = "This plugins show the current user if its not root"
return
}
//Load is the load function of the plugin
func (u *User) Load(Prompter) error {
u.user = os.Getenv("USER")
if u.user == "" {
return fmt.Errorf("Unable to get USER")
}
return nil
}
//Get returns the string to use in the prompt
func (u User) Get(format func(string, ...termcolor.Mode) string) (string, []termcolor.Mode) {
if u.user == "root" {
return "", nil
}
return format(u.user, termcolor.Bold, termcolor.FgGreen), []termcolor.Mode{termcolor.FgGreen}
}