Method: Ec2ssh::CLI#shellcomp

Defined in:
lib/ec2ssh/cli.rb

#shellcomp(_ = false) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ec2ssh/cli.rb', line 55

def shellcomp(_ = false)
  if args.include?("-")
    print_rc = true
  else
    print_rc = false
  end

  # print instructions for automatically enabling shell completion
  unless print_rc
    puts <<EOS
# Enable ec2ssh completion by adding
# the following to .bash_profile/.zshrc

type ec2ssh >/dev/null 2>&1 && eval "$(ec2ssh shellcomp -)"

EOS
    exit(false)
  end

  # print shell script for enabling shell completion
  zsh_comp_file = File.expand_path("../../../zsh/_ec2ssh", __FILE__)
  bash_comp_file = File.expand_path("../../../bash/ec2ssh.bash", __FILE__)
  puts <<EOS
if [ -n "${BASH_VERSION:-}" ]; then
source #{bash_comp_file}
elif [ -n "${ZSH_VERSION:-}" ]; then
source #{zsh_comp_file}
fi
EOS
end