Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
Last active Feb 12, 2017
Embed
What would you like to do?
Mac用簡易PDF表示スクリプト。ファイル名の一部を入力すると一覧を番号付きで表示する。番号も付けて入力するとそのファイルを表示する。
#!/usr/bin/env ruby
DIRECTORY = '/YOUR/PDF/DIR'
keyword = nil
number = nil
if ARGV.length != 1 and ARGV.length != 2
puts "Usage (1): book keyword"
puts "Example (1): book Galois"
puts "Usage (2): book keyword number"
puts "Example (2): book Galois 3"
abort
end
keyword = ARGV[0]
number = ARGV[1].to_i if ARGV.length == 2
list = `ls #{DIRECTORY} | nkf --ic=UTF-8-MAC --oc=UTF-8 | grep '#{keyword}' | sort`.split(/\n/)
if number and number < list.size
system("open '#{DIRECTORY}/#{list[number]}'")
else
list.each_with_index do |path, index|
puts "#{index}: #{path.sub(/#{DIRECTORY}\//, '')}"
end
end
@hyuki0000

This comment has been minimized.

Copy link
Owner Author

@hyuki0000 hyuki0000 commented Feb 12, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment