-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from rsteube/api-change
updated carapace to 0.1.0
- Loading branch information
Showing
28 changed files
with
230 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package fs | ||
|
||
import ( | ||
"os/exec" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/rsteube/carapace" | ||
) | ||
|
||
func ActionMounts() carapace.Action { | ||
return carapace.ActionCallback(func(args []string) carapace.Action { | ||
if output, err := exec.Command("mount").Output(); err != nil { | ||
return carapace.ActionMessage(err.Error()) | ||
} else { | ||
re := regexp.MustCompile(`^(?P<target>\S+) on (?P<mountt>\S+) type (?P<type>\S+) (?P<mode>.+)`) | ||
mounts := make([]string, 0) | ||
for _, line := range strings.Split(string(output), "\n") { | ||
if re.MatchString(line) { | ||
matches := re.FindStringSubmatch(line) | ||
mounts = append(mounts, matches[2], matches[1]) | ||
} | ||
} | ||
return carapace.ActionValuesDescribed(mounts...) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package net | ||
|
||
import ( | ||
"io/ioutil" | ||
"os/exec" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/mitchellh/go-homedir" | ||
|
||
"github.com/rsteube/carapace" | ||
) | ||
|
||
func ActionHosts() carapace.Action { | ||
return carapace.ActionCallback(func(args []string) carapace.Action { | ||
hosts := []string{} | ||
if file, err := homedir.Expand("~/.ssh/known_hosts"); err == nil { | ||
if content, err := ioutil.ReadFile(file); err == nil { | ||
r := regexp.MustCompile(`^(?P<host>[^ ,#]+)`) | ||
for _, entry := range strings.Split(string(content), "\n") { | ||
if r.MatchString(entry) { | ||
hosts = append(hosts, r.FindStringSubmatch(entry)[0]) | ||
} | ||
} | ||
} else { | ||
return carapace.ActionMessage(err.Error()) | ||
} | ||
} | ||
return carapace.ActionValues(hosts...) | ||
}) | ||
} | ||
|
||
func ActionNetInterfaces() carapace.Action { | ||
return carapace.ActionCallback(func(args []string) carapace.Action { | ||
if output, err := exec.Command("ifconfig").Output(); err != nil { | ||
return carapace.ActionMessage(err.Error()) | ||
} else { | ||
interfaces := []string{} | ||
for _, line := range strings.Split(string(output), "\n") { | ||
if matches, _ := regexp.MatchString("^[0-9a-zA-Z]", line); matches { | ||
interfaces = append(interfaces, strings.Split(line, ":")[0]) | ||
} | ||
} | ||
return carapace.ActionValues(interfaces...) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.