Module: Keybase::Local::Config

Included in:
Keybase::Local
Defined in:
lib/keybase/local/config.rb

Overview

Methods and constants related to a local Keybase installation.

Constant Summary collapse

CONFIG_DIR =

The Keybase configuration directory.

if Gem.win_platform?
  File.expand_path("#{ENV["LOCALAPPDATA"]}/Keybase").freeze
elsif RUBY_PLATFORM =~ /darwin/
  File.expand_path("~/Library/Application Support/Keybase").freeze
else
  File.expand_path("~/.config/keybase").freeze
end
CONFIG_FILE =
Note:

This is not guaranteed to exist on disk.

The Keybase configuration file.

File.join(CONFIG_DIR, "config.json").freeze
STATUS_HASH =

The Keybase status hash, obtained from keybase status -j.

JSON.parse(`keybase status -j`)
KBFS_MOUNT =

The mountpoint for KBFS.

STATUS_HASH["KBFS"]["Mount"]

Instance Method Summary collapse

Instance Method Details

#current_userString

Returns the currently logged-in user.

Returns:

  • (String)

    the currently logged-in user



29
30
31
# File 'lib/keybase/local/config.rb', line 29

def current_user
  STATUS_HASH["Username"]
end

#logged_in?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/keybase/local/config.rb', line 57

def logged_in?
  STATUS_HASH["LoggedIn"]
end

#private_dirString

Returns the user's private KBFS directory.

Returns:

  • (String)

    the user's private KBFS directory



34
35
36
# File 'lib/keybase/local/config.rb', line 34

def private_dir
  File.join(KBFS_MOUNT, "private", current_user)
end

#public_dirString

Returns the user's public KBFS directory.

Returns:

  • (String)

    the user's public KBFS directory



39
40
41
# File 'lib/keybase/local/config.rb', line 39

def public_dir
  File.join(KBFS_MOUNT, "public", current_user)
end

#running?Boolean

Returns whether or not Keybase is currently running.

Returns:

  • (Boolean)

    whether or not Keybase is currently running



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/keybase/local/config.rb', line 44

def running?
  if Gem.win_platform?
    !`tasklist | find "keybase.exe"`.empty?
  elsif RUBY_PLATFORM =~ /darwin/
    !`pgrep keybase`.empty?
  else
    # is there a more efficient way to do this that doesn't involve an exec?
    Dir["/proc/[0-9]*/comm"].any? do |comm|
      File.read(comm).chomp == "keybase" rescue false # hooray for TOCTOU
    end
  end
end

#running_versionString

Returns the running Keybase's version string.

Returns:

  • (String)

    the running Keybase's version string

Raises:



63
64
65
66
# File 'lib/keybase/local/config.rb', line 63

def running_version
  raise Exceptions::KeybaseNotRunningError unless running?
  `keybase --version`.split[2]
end