Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
Last active February 12, 2017 06:17
Show Gist options
  • Save hyuki0000/e84e6bf1edd8ab5008b6bf92b8af2896 to your computer and use it in GitHub Desktop.
Save hyuki0000/e84e6bf1edd8ab5008b6bf92b8af2896 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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