Skip to content

Commit

Permalink
refactor: change u-menu to use new abstractions
Browse files Browse the repository at this point in the history
  • Loading branch information
dvinciguerra committed May 13, 2023
1 parent 2157a23 commit cb333aa
Showing 1 changed file with 16 additions and 31 deletions.
47 changes: 16 additions & 31 deletions bin/u-menu
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
#!/usr/bin/env ruby

require 'pastel'
require 'tty-prompt'

require 'yaml'
require_relative '../lib/u-menu'

paths = [
File.expand_path("#{Dir.home}/.umenurc.yml", __dir__),
File.expand_path("#{Dir.home}/.umenu/umenurc.yml", __dir__),
]
require 'tty-prompt'

config_path = paths.first { |path| File.exist? path }
config = YAML.load_file(config_path, symbolize_names: true)
config = Micro::Menu.configurations.load

pastel = Pastel.new
prompt = TTY::Prompt.new(prefix: pastel.magenta("\uea85 \u00b5menu "), interrupt: :signal)
colors = Micro::Menu.colors
prompt = TTY::Prompt.new(prefix: colors.magenta("\uea85 \u00b5menu "), interrupt: :signal)

icons = {
'run' => "\ueb9e",
'terminal' => "\uea85",
'github' => "\uea84",
'chart' => "\ue760",
'jira' => "\ue75c",
'settings' => "\ue615",
'link' => "\ueb15"
}
icons = Micro::Menu.icons.all

thanks = [
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')}! =)"
colors.green('Great job! o/'),
colors.green('See you later! =)'),
colors.green('Baby bye bye bye...'),
"Bring me #{colors.green('a cookie')} when you come back!?",
"Have a nice #{colors.cyan('day')}! =)",
"See you later #{colors.green('olligator')}! =)"
]

trap('INT') do
Expand All @@ -47,7 +32,7 @@ options << {
name: '{{settings}} Edit Settings',
type: 'edit',
value: 'settings',
execute: config_path
execute: config[:_path]
}
options = options.sort { |a, b| a[:name] <=> b[:name] }

Expand All @@ -69,15 +54,15 @@ loop do
when 'command'
system action[:execute]
when 'link'
puts "#{pastel.bold('Sure... opening link')} '#{pastel.cyan(action[:execute])}'"
puts "#{colors.bold('Sure... opening link')} '#{colors.cyan(action[:execute])}'"
system "open #{action[:execute]} &"
when 'edit'
puts "#{pastel.bold('Sure... opening file')} '#{pastel.cyan(action[:execute])}'"
puts "#{colors.bold('Sure... opening file')} '#{colors.cyan(action[:execute])}'"
system "#{config[:settings][:editor]} #{action[:execute]}"
end

exit(0)
rescue StandardError => e
puts "#{pastel.red('[error]')} #{e}"
puts "#{colors.red('[error]')} #{e}"
exit(1)
end

0 comments on commit cb333aa

Please sign in to comment.