Last active
February 12, 2017 06:17
Mac用簡易PDF表示スクリプト。ファイル名の一部を入力すると一覧を番号付きで表示する。番号も付けて入力するとそのファイルを表示する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://snap.textfile.org/20160701151217/
参照。