diff --git a/keybase.go b/keybase.go index 31dc50d..6706f1c 100644 --- a/keybase.go +++ b/keybase.go @@ -29,6 +29,7 @@ func NewKeybase(path ...string) *Keybase { k.LoggedIn = k.loggedIn() if k.LoggedIn { k.Username = k.username() + k.Device = k.device() } return k } @@ -78,6 +79,19 @@ func (k *Keybase) username() string { return s.Username } +// device returns the device name of the currently provisioned device. +func (k *Keybase) device() string { + cmdOut, err := k.Exec("status", "-j") + if err != nil { + return "" + } + + var s status + json.Unmarshal(cmdOut, &s) + + return s.Device.Name +} + // loggedIn returns true if Keybase is currently logged in, otherwise returns false. func (k *Keybase) loggedIn() bool { cmdOut, err := k.Exec("status", "-j") diff --git a/types.go b/types.go index 0ee3d07..67f0844 100644 --- a/types.go +++ b/types.go @@ -518,6 +518,7 @@ type Keybase struct { Username string LoggedIn bool Version string + Device string } // Chat holds basic information about a specific conversation @@ -584,9 +585,15 @@ type keybase interface { loggedIn() bool username() string version() string + device() string } type status struct { Username string `json:"Username"` LoggedIn bool `json:"LoggedIn"` + Device device `json:"Device"` +} + +type device struct { + Name string `json:"name"` }