Class: Yoke::Base
- Inherits:
-
Object
- Object
- Yoke::Base
- Defined in:
- lib/yoke/base.rb
Constant Summary collapse
- FILENAME =
".yoke"
Class Method Summary collapse
- .add(name = nil) ⇒ Object
- .alias_file_path ⇒ Object
- .create_alias_file ⇒ Object
- .delete_text(alias_name) ⇒ Object
- .directory?(path) ⇒ Boolean
- .empty_file_contents ⇒ Object
- .end_text ⇒ Object
- .has_alias_file? ⇒ Boolean
- .list ⇒ Object
- .puts_text(text) ⇒ Object
- .remove(name = nil) ⇒ Object
- .setup ⇒ Object
- .sharp_count ⇒ Object
- .source_text ⇒ Object
- .yoke_text ⇒ Object
Class Method Details
.add(name = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yoke/base.rb', line 28 def add(name=nil) puts yoke_text path = Dir.pwd name = name || File.basename(path) if Yoke::Alias.add(path, name) puts_text("") puts_text("Added #{name} as alias for #{path}") else puts_text("") puts_text("The alias with #{name} already exists") end source_text puts end_text end |
.alias_file_path ⇒ Object
84 85 86 |
# File 'lib/yoke/base.rb', line 84 def alias_file_path File.join(Dir.home, FILENAME) end |
.create_alias_file ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/yoke/base.rb', line 92 def create_alias_file unless has_alias_file? puts_text("") puts_text("Generated #{FILENAME} file") File.open(alias_file_path, "w") { |f| f.write(empty_file_contents) } end end |
.delete_text(alias_name) ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/yoke/base.rb', line 123 def delete_text(alias_name) puts_text("") puts_text("To remove this alias immediately run the following command:") puts_text("") puts_text("unalias #{alias_name}") puts_text("") puts_text("Or just start another shell and the aliases are reloaded for you!") puts_text("") end |
.directory?(path) ⇒ Boolean
80 81 82 |
# File 'lib/yoke/base.rb', line 80 def directory?(path) File.directory?(path) end |
.empty_file_contents ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/yoke/base.rb', line 100 def empty_file_contents <<TEXT # File generated by Yoke (http://fousa.be/apps/yoke). # # Do not alter this file or yoke will stop working correctly. # TEXT end |
.end_text ⇒ Object
117 118 119 120 121 |
# File 'lib/yoke/base.rb', line 117 def end_text <<TEXT ############################################################################################################# TEXT end |
.has_alias_file? ⇒ Boolean
88 89 90 |
# File 'lib/yoke/base.rb', line 88 def has_alias_file? File.exists?(alias_file_path) end |
.list ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/yoke/base.rb', line 60 def list puts yoke_text list = Yoke::Alias.list if list.count > 0 puts_text("") puts_text("Listing all aliases") puts_text("") longest_word_count = list.keys.group_by(&:size).max.last.last.size list.each do |alias_link, path| printf "### %-#{longest_word_count}s %s %-#{sharp_count - 9 - longest_word_count - path.size}s###\n", alias_link, path, "" end else puts_text("") puts_text("No aliases to list") end puts_text("") puts end_text end |
.puts_text(text) ⇒ Object
148 149 150 |
# File 'lib/yoke/base.rb', line 148 def puts_text(text) printf "### %-#{sharp_count - 8}s ###\n", text end |
.remove(name = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/yoke/base.rb', line 44 def remove(name=nil) puts yoke_text path = Dir.pwd name = name || File.basename(path) if Yoke::Alias.remove(path, name) puts_text("") puts_text("Removed #{name} as an alias") else puts_text("") puts_text("The alias with #{name} is does not exist") end delete_text(name) puts end_text end |
.setup ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/yoke/base.rb', line 10 def setup puts yoke_text puts_text("") puts_text("Prepared the shell.") if %x[echo $SHELL].include?("zsh") Yoke::Zsh.setup else Yoke::Bash.setup end create_alias_file puts_text("") puts_text("Run yoke help to check out the available options.") puts_text("") puts end_text end |
.sharp_count ⇒ Object
144 145 146 |
# File 'lib/yoke/base.rb', line 144 def sharp_count "#############################################################################################################".size end |
.source_text ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/yoke/base.rb', line 133 def source_text puts_text("") puts_text("You should reload the 'yoke' aliases defined in your .yoke file.") puts_text("You can do this by executing the following command:") puts_text("") puts_text("source ~/.yoke") puts_text("") puts_text("Or just start another shell and the aliases are reloaded for you!") puts_text("") end |
.yoke_text ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/yoke/base.rb', line 109 def yoke_text <<TEXT ############################################################################################################# ### YOKE #################################################################################################### ############################################################################################################# TEXT end |