bin/u-menu in u-menu-0.2.0 vs bin/u-menu in u-menu-0.4.0
- old
+ new
@@ -1,21 +1,18 @@
#!/usr/bin/env ruby
-require 'bundler/inline'
+require 'pastel'
+require 'tty-prompt'
-gemfile do
- source 'https://rubygems.org'
-
- gem 'pastel'
- gem 'tty-prompt'
-end
-
require 'yaml'
-config_path = File.expand_path("#{ENV.fetch('HOME', nil)}/.umenurc.yml", __dir__)
-config_path ||= File.expand_path("#{ENV.fetch('HOME', nil)}/.umenu/umenurc.yml", __dir__)
+paths = [
+ File.expand_path("#{Dir.home}/.umenurc.yml", __dir__),
+ File.expand_path("#{Dir.home}/.umenu/umenurc.yml", __dir__),
+]
+config_path = paths.first { |path| File.exist? path }
config = YAML.load_file(config_path, symbolize_names: true)
pastel = Pastel.new
prompt = TTY::Prompt.new(prefix: pastel.magenta("\uea85 \u00b5menu "), interrupt: :signal)
@@ -28,13 +25,13 @@
'settings' => "\ue615",
'link' => "\ueb15"
}
thanks = [
- "#{pastel.green('Great job! o/')}",
- "#{pastel.green('See you later! =)')}",
- "#{pastel.green('Baby bye bye bye...')}",
+ pastel.green('Great job! o/'),
+ pastel.green('See you later! =)'),
+ pastel.green('Baby bye bye bye...'),
"Bring me #{pastel.green('a cookie')} when you come back!?",
"Have a nice #{pastel.cyan('day')}! =)",
"See you later #{pastel.green('olligator')}! =)"
]
@@ -48,11 +45,11 @@
options << {
name: '{{settings}} Edit Settings',
type: 'edit',
value: 'settings',
- execute: "#{config_path}"
+ execute: config_path
}
options = options.sort { |a, b| a[:name] <=> b[:name] }
options.each do |option|
if option[:name].match(/\{\{(?<icon_name>.*)\}\}/)
@@ -68,10 +65,10 @@
choice = prompt.select(title, options, filter: true)
action = config[:options].find { |item| item[:value] == choice }
case action[:type]
when 'command'
- system "#{action[:execute]} &"
+ system action[:execute]
when 'link'
puts "#{pastel.bold('Sure... opening link')} '#{pastel.cyan(action[:execute])}'"
system "open #{action[:execute]} &"
when 'edit'
puts "#{pastel.bold('Sure... opening file')} '#{pastel.cyan(action[:execute])}'"