Skip to content

Instantly share code, notes, and snippets.

@junegunn

junegunn/only-dir

Last active Oct 14, 2017
Embed
What would you like to do?
only-dir and with-dir
#!/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
#!/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