Module: Appear

Defined in:
lib/appear.rb,
lib/appear/lsof.rb,
lib/appear/tmux.rb,
lib/appear/util.rb,
lib/appear/config.rb,
lib/appear/editor.rb,
lib/appear/mac_os.rb,
lib/appear/output.rb,
lib/appear/runner.rb,
lib/appear/command.rb,
lib/appear/service.rb,
lib/appear/instance.rb,
lib/appear/terminal.rb,
lib/appear/constants.rb,
lib/appear/processes.rb,
lib/appear/revealers.rb,
lib/appear/util/join.rb,
lib/appear/editor/nvim.rb,
lib/appear/util/memoizer.rb,
lib/appear/util/value_class.rb,
lib/appear/util/command_builder.rb

Overview

Appear your terminal programs in your gui!

Appear is a tool for revealing a given process in your terminal. Given a process ID, ‘appear` finds the terminal emulator view (be it a window, tab, or pane) containing that process and shows it to you. Appear understands terminal multiplexers like `tmux`, so if your target process is in a multiplexer session, `appear` will reveal a client connected to that session, or start one if needed.

Most users of this library will find the Appear.appear method sufficient, although you may construct and control library internals using the Instance class, which is our “main” class.

Other useful ideas include the BaseService class, which is a super-simple dependency-injection base class.

Author:

Defined Under Namespace

Modules: Editor, Revealers, Terminal, Util Classes: BaseService, Command, Config, DeadProcess, Error, ExecutionFailure, Instance, Lsof, LsofParseError, MacOs, MacToolError, Output, Processes, Runner, RunnerRecorder, Service, Terminals, Tmux

Constant Summary collapse

VERSION =

the version of Appear

'1.2.1'
MODULE_DIR =

the root of the Appear project directory

Pathname.new(__FILE__).realpath.join('../../..')
TOOLS_DIR =

where we look for os-specific helper files

MODULE_DIR.join('tools')
REVEALERS =

stores all the ways we can appear something

[]

Class Method Summary collapse

Class Method Details

.appear(pid, config = nil) ⇒ Object

Appear the given PID in your user interfaces. This method is an easy public interface to Appear for ruby consumers.

Parameters:

  • pid (Number)

    pid to Appear.

  • config (Appear::Config, nil) (defaults to: nil)

    a config for adjusting verbosity and logging.



23
24
25
26
27
# File 'lib/appear.rb', line 23

def self.appear(pid, config = nil)
  config ||= Appear::Config.new
  instance = Appear::Instance.new(config)
  instance.call(pid)
end

.build_command(pid, config = nil) ⇒ String

Build a command string that will execute ‘appear` with the given config and arguments. If `appear` is in your PATH, we will use that binary. Otherwise, we will call the script in ./bin/ folder near this library, which has a #!/usr/bin/env ruby shbang.

You may optionally need to prepend “PATH=#'PATH' ” to the command if ‘tmux` is not in your command execution environment’s PATH.

Intended for use with the terminal-notifier gem.

Examples:

Show a notification that will raise your program

require 'appear'
require 'terminal-notifier'
TerminalNotifier.notify('Click to appear!', :execute => Appear.build_command(Process.pid))

Parameters:

  • pid (Number)

    pid to Appear.

  • config (Appear::Config, nil) (defaults to: nil)

    a config for adjusting verbosity and logging.

Returns:

  • (String)

    a shell command that will execute ‘appear`

See Also:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/appear.rb', line 48

def self.build_command(pid, config = nil)
  binary = `which appear`.strip
  if binary.empty?
    binary = Appear::MODULE_DIR.join('bin/appear').to_s
  end

  command = Appear::Util::CommandBuilder.new(binary).args(pid)

  if config
    command.flag('verbose', true) unless config.silent
    command.flag('log-file', config.log_file) if config.log_file
    command.flag('record-runs', true) if config.record_runs
  end

  command.to_s
end