-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: use types for session, client, buffer
- Loading branch information
Showing
16 changed files
with
180 additions
and
94 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
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
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,63 @@ | ||
package kak | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
type Session struct { | ||
Name string | ||
// clients []string | ||
// dir string | ||
} | ||
|
||
type Client struct{ Name string } | ||
type Buffer struct{ Name string } | ||
|
||
func (s *Session) Exists() (bool, error) { | ||
sessions, err := Sessions() | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
for _, session := range sessions { | ||
if session.Name == s.Name { | ||
return true, nil | ||
} | ||
} | ||
return false, nil | ||
} | ||
|
||
func (s *Session) Clients() (clients []Client) { | ||
cl, err := Get(*s, Client{}, Buffer{}, "%val{client_list}") | ||
if err != nil { | ||
return []Client{} | ||
} | ||
|
||
for _, c := range cl { | ||
clients = append(clients, Client{c}) | ||
} | ||
|
||
return clients | ||
} | ||
|
||
func (s *Session) Dir() string { | ||
dir, err := Get(*s, Client{}, Buffer{}, "%sh{pwd}") | ||
if err != nil { | ||
return "" | ||
} | ||
return dir[0] | ||
} | ||
|
||
func Sessions() (sessions []Session, err error) { | ||
output, err := exec.Command("kak", "-l").Output() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, s := range strings.Split(strings.TrimSpace(string(output)), "\n") { | ||
sessions = append(sessions, Session{Name: s}) | ||
} | ||
|
||
return sessions, nil | ||
} |
Oops, something went wrong.