rubybashunixtreepry

tree command on osx bash


I'm following a screen cast on a ruby gem called pry. At 8:10, the .tree command is used, which I believe is a Unix command.

It does not appear to be working on my system:

[24] pry(main)> .tree
\Error: there was a problem executing system command: tree

and I have traced the issue to here, in which pry references a shell command:

Pry::CommandSet.new do

  command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>") do |cmd|
    if cmd =~ /^cd\s+(.+)/i
      dest = $1
      begin
        Dir.chdir File.expand_path(dest)
      rescue Errno::ENOENT
        output.puts "No such directory: #{dest}"
      end

    else
      if !system(cmd)
        output.puts "Error: there was a problem executing system command: #{cmd}"
      end
    end
  end

from the context of bash I tried using the command tree with no luck:

projects/sms(apps2)$ tree
-bash: tree: command not found
~/projects/sms(apps2)$ .tree
-bash: .tree: command not found

This looks incredibly useful, how can I get this command?


Solution

  • Using homebrew:

    brew install tree

    Using macports:

    sudo port install tree

    Using the source:

    Follow these directions. (Caveat; you should use the flags/etc. that make sense.)

    <rant>All systems should come with tree; I use it a lot. And we can post directory structures as text, not pics.</rant>