Skip to content

Commit

Permalink
WIP: Generate fish completion file
Browse files Browse the repository at this point in the history
  • Loading branch information
avdv committed Jan 24, 2018
1 parent 5dc9840 commit 2fc1f32
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,24 @@ file 'zsh/_colorls' => ['lib/colorls/flags.rb'] do
ruby "exe/colorls '--*-completion-zsh=colorls' > zsh/_colorls"
end

desc 'Build Fish completion file'
file 'colorls.fish' => ['lib/colorls/flags.rb'] do
require 'colorls'
require 'shellwords'

flags = ColorLS::Flags.new
flags.options.each do |o|
short_and_long = o.flags.collect do |option|
case option
when /^--/ then "-l #{option[2..-1]}"
else "-s #{option[1..-1]}"
end
end.join(' ')

fixed_args = " -x -a #{Shellwords.escape o.args.join(' ')}" unless o.args.nil?

puts "complete -c colorls #{short_and_long} -d #{Shellwords.escape o.desc.first}#{fixed_args}"
end
end

task default: %w[spec rubocop]
3 changes: 2 additions & 1 deletion lib/colorls/flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def options
flags = o.short + o.long
next if flags.empty?

OpenStruct.new(flags: flags, desc: o.desc)
args = o.pattern.keys if Hash === o.pattern
OpenStruct.new(flags: flags, desc: o.desc, args: args)
end

result.compact
Expand Down

0 comments on commit 2fc1f32

Please sign in to comment.