Module: Lexdrill::ShellSnippet

Defined in:
lib/lexdrill/shell_snippet.rb

Overview

Generates the zsh/bash shell integration snippet for drill hook.

Constant Summary collapse

ZSH =
<<~SNIPPET
  drill_precmd() {
    [[ -f "$HOME/.drill.disabled" ]] && return
    command drill next 2>/dev/null
  }
  if [[ -z "${precmd_functions[(r)drill_precmd]}" ]]; then
    precmd_functions+=(drill_precmd)
  fi
SNIPPET
BASH =
<<~SNIPPET
  drill_precmd() {
    [ -f "$HOME/.drill.disabled" ] && return
    command drill next 2>/dev/null
  }
  case ";${PROMPT_COMMAND:-};" in
    *";drill_precmd;"*) ;;
    *) PROMPT_COMMAND="drill_precmd;${PROMPT_COMMAND}" ;;
  esac
SNIPPET

Class Method Summary collapse

Class Method Details

.for(shell_name) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/lexdrill/shell_snippet.rb', line 26

def self.for(shell_name)
  case shell_name.to_s
  when "zsh" then ZSH
  when "bash" then BASH
  else
    raise ArgumentError, "unsupported shell #{shell_name.inspect} (expected \"zsh\" or \"bash\")"
  end
end