list command

This commit is contained in:
2020-04-19 23:33:59 -04:00
parent 40e57a83a9
commit ce43c1dcd9
2 changed files with 70 additions and 2 deletions

View File

@ -63,12 +63,29 @@ func StartProject(name string) {
tmux.Attach(name)
}
func ListProjects() error {
configDir := getConfigDir()
files, err := ioutil.ReadDir(configDir)
if err != nil {
return err
}
for _, file := range files {
if file.IsDir() {
continue
}
name := file.Name()
ext := filepath.Ext(name)
fmt.Printf("%s\n", name[:len(name)-len(ext)])
}
return nil
}
// LoadProject loads and parses the config for the given project.
func LoadProject(name string) (*Project, error) {
project := &Project{}
home, _ := homedir.Dir()
fileName := path.Join(home, ".workon", name+".yml")
fileName := path.Join(getConfigDir(), name+".yml")
data, err := ioutil.ReadFile(fileName)
if err != nil {
@ -97,6 +114,11 @@ func (p *Project) GetRoot() string {
return rootPath
}
func getConfigDir() string {
home, _ := homedir.Dir()
return path.Join(home, ".workon")
}
func sessionExists(name string) bool {
t := Tmux{}
result, err := t.Exec("ls")