@@ -4,24 +4,32 @@ import (
44 "io/ioutil"
55 "os"
66 "os/exec"
7+ "strconv"
78 "strings"
89
910 ps "github.com/mitchellh/go-ps"
1011 "github.com/rsteube/carapace"
1112)
1213
14+ // ActionEnvironmentVariables completes environment values
1315func ActionEnvironmentVariables () carapace.Action {
1416 return carapace .ActionCallback (func (args []string ) carapace.Action {
1517 env := os .Environ ()
16- vars := make ([]string , len (env ))
18+ vars := make ([]string , len (env )* 2 )
1719 for index , e := range os .Environ () {
1820 pair := strings .SplitN (e , "=" , 2 )
19- vars [index ] = pair [0 ]
21+ vars [index * 2 ] = pair [0 ]
22+ if len (pair [1 ]) > 40 {
23+ vars [(index * 2 )+ 1 ] = pair [1 ][:37 ] + "..."
24+ } else {
25+ vars [(index * 2 )+ 1 ] = pair [1 ]
26+ }
2027 }
21- return carapace .ActionValues (vars ... )
28+ return carapace .ActionValuesDescribed (vars ... )
2229 })
2330}
2431
32+ // ActionGroups completes system group names
2533func ActionGroups () carapace.Action {
2634 return carapace .ActionCallback (func (args []string ) carapace.Action {
2735 groups := []string {}
@@ -41,6 +49,7 @@ func ActionGroups() carapace.Action {
4149 })
4250}
4351
52+ // ActionKillSignals completes linux kill signals
4453func ActionKillSignals () carapace.Action {
4554 return carapace .ActionValuesDescribed (
4655 "ABRT" , "Abnormal termination" ,
@@ -77,20 +86,22 @@ func ActionKillSignals() carapace.Action {
7786 )
7887}
7988
89+ // ActionProcessExecutables completes executable names of current processes
8090func ActionProcessExecutables () carapace.Action {
8191 return carapace .ActionCallback (func (args []string ) carapace.Action {
8292 if processes , err := ps .Processes (); err != nil {
8393 return carapace .ActionMessage (err .Error ())
8494 } else {
8595 executables := make ([]string , 0 )
8696 for _ , process := range processes {
87- executables = append (executables , process .Executable ())
97+ executables = append (executables , process .Executable (), strconv . Itoa ( process . Pid ()) )
8898 }
89- return carapace .ActionValues (executables ... )
99+ return carapace .ActionValuesDescribed (executables ... )
90100 }
91101 })
92102}
93103
104+ // ActionProcessStates completes linux process states
94105func ActionProcessStates () carapace.Action {
95106 return carapace .ActionValuesDescribed (
96107 "D" , "uninterruptible sleep (usually IO)" ,
@@ -105,6 +116,7 @@ func ActionProcessStates() carapace.Action {
105116 )
106117}
107118
119+ // ActionUsers completes system user names
108120func ActionUsers () carapace.Action {
109121 return carapace .ActionCallback (func (args []string ) carapace.Action {
110122 users := []string {}
@@ -124,6 +136,7 @@ func ActionUsers() carapace.Action {
124136 })
125137}
126138
139+ // ActionUserGroup completes system user:group separately
127140func ActionUserGroup () carapace.Action {
128141 return carapace .ActionMultiParts (":" , func (args []string , parts []string ) carapace.Action {
129142 switch len (parts ) {
@@ -137,6 +150,7 @@ func ActionUserGroup() carapace.Action {
137150 })
138151}
139152
153+ // ActionShells completes available terminal shells
140154func ActionShells () carapace.Action {
141155 return carapace .ActionCallback (func (args []string ) carapace.Action {
142156 if output , err := exec .Command ("chsh" , "--list-shells" ).Output (); err != nil {
0 commit comments