8 ## some definitions {{{
9 def current() $data[$adr1] end
11 def get() current[$adr2] end
13 def set(x) current[$adr2] = x end
16 return false if $cleared
17 !$db.get_first_row("SELECT * FROM nyu WHERE type='cmd' AND key=?;", key).nil?
21 $db.execute("UPDATE nyu SET mtime=?, value=?, descr=?, info1=? WHERE type='cmd' AND key=?;", Time.now.to_i, data['value'], data['descr'], data['tab'], key)
25 $db.execute("INSERT INTO nyu (key,type,ctime,mtime,value,descr,info1) VALUES (?, 'cmd', ?,?,?,?,?);", key, Time.now.to_i, Time.now.to_i, data['value'], data['descr'], data['tab'])
29 ## reading the data about commands from command.rb
31 file = File.join(File.dirname(__FILE__), 'commands.rb')
32 File.read(file).each_line do |line|
33 if line =~ /^#\s*([\w\d]+)(?:\s*\.\s*([\w\d]+))?(?:\s*:\s*(.+))?/
34 next if current and get.empty?
39 current['descr'] = $3 if $3
55 puts 'current path: ' + Dir.pwd + '/'
56 print 'write to which file? (leave free to print) '
64 file = File.expand_path($_.strip)
67 puts "file = #{file.inspect}"
68 print "is that correct? (yes/no) "
70 break if %w[yes no].include? $_.strip!
76 ## if okay, write stuff to db
78 print "clear old commands before applying new ones? (clear/no) "
79 break if %w[clear no].include? gets.strip!
83 $db = db = SQLite3::Database.new(file)
85 if $cleared = ($_ == 'clear')
86 db.execute "DELETE FROM nyu WHERE type='cmd'"
93 puts " ) #{key} found. updating."
96 puts "+) #{key} not found. creating."