Last active
October 14, 2017 07:04
-
-
Save junegunn/8c3796a965f22e6a803fe53096ad7a75 to your computer and use it in GitHub Desktop.
only-dir and with-dir
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 | |
require 'set' | |
base = ARGV.first || '.' | |
dirs = Set.new | |
$stdin.each_line do |line| | |
dir = File.dirname(line) | |
anc = [] | |
while dirs.add?(dir) | |
anc << dir | |
break if dir == base | |
dir = File.dirname(dir) | |
end | |
puts anc.reverse unless anc.empty? | |
end |
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 | |
require 'set' | |
base = ARGV.first || '.' | |
dirs = Set.new | |
$stdin.each_line do |line| | |
dir = File.dirname(line) | |
anc = [] | |
while dir != base && dirs.add?(dir) | |
anc << dir | |
dir = File.dirname(dir) | |
end | |
puts anc.reverse unless anc.empty? | |
print line | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment