Skip to content

Commit

Permalink
open command
Browse files Browse the repository at this point in the history
  • Loading branch information
forresty committed Apr 19, 2012
1 parent 43908cd commit aa56333
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
10 changes: 8 additions & 2 deletions README.md
Expand Up @@ -40,6 +40,14 @@ Show user info

v2ex user livid

Open topic/node/user in your web browser (Mac only)

v2ex open t TOPIC_ID

v2ex open u USERNAME

v2ex open n NODE_NAME

Show all nodes

v2ex nodes
Expand All @@ -50,8 +58,6 @@ For more information, pass --help

## TODO

Commands to open web pages to topics/users/nodes etc

REPL mode (Read, Eval, Print, Loop)

## Contributing
Expand Down
19 changes: 19 additions & 0 deletions bin/v2ex
Expand Up @@ -58,6 +58,20 @@ command :user do |c|
end
end

command :open do |c|
c.syntax = 'v2ex open ARGS'
c.description = 'open topics/users/nodes in your browser'
c.action do |args, options|
case args.first
when 't' then `open #{v2ex_prefix}/t/#{args.last}`
when 'u' then `open #{v2ex_prefix}/member/#{args.last}`
when 'n' then `open #{v2ex_prefix}/go/#{args.last}`
else
puts "Wrong arguments. First argument should be 't', 'u' or 'n'."
end
end
end

command :nodes do |c|
c.syntax = 'v2ex nodes'
c.description = 'list all nodes'
Expand Down Expand Up @@ -93,11 +107,16 @@ def print_topic(topic, options={ :show_content => false })
puts "\n#{topic[:content]}" if options[:show_content]
end

def v2ex_prefix
'http://www.v2ex.com'
end

alias_command :l, :latest
alias_command :t, :topic
alias_command :ut, :user_topics
alias_command :nt, :node_topics
alias_command :u, :user
alias_command :n, :nodes
alias_command :o, :open

default_command :latest

0 comments on commit aa56333

Please sign in to comment.