Module: NA::Prompt
- Defined in:
- lib/na/prompt.rb
Overview
Prompt Hooks
Class Method Summary collapse
- .install_prompt_hook(shell) ⇒ Object
- .prompt_file(shell) ⇒ Object
- .prompt_hook(shell) ⇒ Object
- .show_prompt_hook(shell) ⇒ Object
Class Method Details
.install_prompt_hook(shell) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/na/prompt.rb', line 53 def install_prompt_hook(shell) file = prompt_file(shell) File.open(File.(file), 'a') { |f| f.puts prompt_hook(shell) } $stderr.puts NA::Color.template("{y}Added {bw}#{shell}{xy} prompt hook to {bw}#{file}{xy}.{x}") $stderr.puts NA::Color.template("{y}You may need to close the current terminal and open a new one to enable the script.{x}") end |
.prompt_file(shell) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/na/prompt.rb', line 36 def prompt_file(shell) files = { zsh: '~/.zshrc', fish: '~/.config/fish/conf.d/na.fish', bash: '~/.bash_profile' } files[shell] end |
.prompt_hook(shell) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/na/prompt.rb', line 7 def prompt_hook(shell) case shell when :zsh " # zsh prompt hook for na\n chpwd() { na next }\n EOHOOK\n when :fish\n <<~EOHOOK\n # Fish Prompt Command\n function __should_na --on-variable PWD\n test -s (basename $PWD)\".\#{NA.extension}\" && na next\n end\n EOHOOK\n when :bash\n <<~EOHOOK\n # Bash PROMPT_COMMAND for na\n last_command_was_cd() {\n [[ $(history 1|sed -e \"s/^[ ]*[0-9]*[ ]*//\") =~ ^((cd|z|j|jump|g|f|pushd|popd|exit)([ ]|$)) ]] && na next\n }\n if [[ -z \"$PROMPT_COMMAND\" ]]; then\n PROMPT_COMMAND=\"eval 'last_command_was_cd'\"\n else\n echo $PROMPT_COMMAND | grep -v -q \"last_command_was_cd\" && PROMPT_COMMAND=\"$PROMPT_COMMAND;\"'eval \"last_command_was_cd\"'\n fi\n EOHOOK\n end\nend\n" |
.show_prompt_hook(shell) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/na/prompt.rb', line 46 def show_prompt_hook(shell) file = prompt_file(shell) $stderr.puts NA::Color.template("{bw}# Add this to {y}#{file}{x}") puts prompt_hook(shell) end |