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.("#{ENV["LOCALAPPDATA"]}/Keybase").freeze elsif RUBY_PLATFORM =~ /darwin/ File.("~/Library/Application Support/Keybase").freeze else File.("~/.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
-
#current_user ⇒ String
The currently logged-in user.
- #logged_in? ⇒ Boolean
-
#private_dir ⇒ String
The user's private KBFS directory.
-
#public_dir ⇒ String
The user's public KBFS directory.
-
#running? ⇒ Boolean
Whether or not Keybase is currently running.
-
#running_version ⇒ String
The running Keybase's version string.
Instance Method Details
#current_user ⇒ String
Returns 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
57 58 59 |
# File 'lib/keybase/local/config.rb', line 57 def logged_in? STATUS_HASH["LoggedIn"] end |
#private_dir ⇒ String
Returns 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_dir ⇒ String
Returns 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.
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_version ⇒ String
Returns the running Keybase's version string.
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 |