Skip to content

Commit

Permalink
escape single quotes before insert & select all command
Browse files Browse the repository at this point in the history
  • Loading branch information
0catac0 committed Jul 1, 2014
1 parent ccd9e21 commit a2ca939
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions bin/co
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ if(ARGV[0] == 'save')

cmd = `tail -n 1 ${HOME}/.bash_history`
cmd.strip!
cmd.gsub!("\'","\'\'")

description = options[:description]
description.gsub!("\'","\'\'") unless description == nil

#treat any tokens that start with @ as tags
tags = []
Expand All @@ -60,7 +62,8 @@ if(ARGV[0] == 'save')
#insert stuff into the database
begin
#find or insert command
db.execute "INSERT OR IGNORE INTO commands(cmd,description) VALUES ('#{cmd}','#{description}');"
db.execute("INSERT OR IGNORE INTO commands(cmd,description) VALUES ('#{cmd}','#{description}');")

cmd_id = db.get_first_value "SELECT id from commands WHERE cmd = '#{cmd}';"

tags.each do |tag|
Expand All @@ -79,8 +82,16 @@ if(ARGV[0] == 'save')
exit #quit
end

#select all commands
if(ARGV[0] == 'list' && ARGV[1] == 'all')
rows = db.execute "SELECT * from commands"
for row in rows do
puts row.join "\s | \s"
end
end

#select all commands in current pwd
if(ARGV[0] == 'list')
if(ARGV[0] == 'list' && ARGV[1] != 'all')
tag = "@#{pwd}"
if(ARGV[1] != nil && ARGV[1].start_with?("@"))
tag = ARGV[1]
Expand Down

0 comments on commit a2ca939

Please sign in to comment.