./bin/chat_rb in aliens-1.0.77 vs ./bin/chat_rb in aliens-1.0.79

- old
+ new

@@ -25,19 +25,16 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - system 'tput reset &' require 'colored' -puts `cat /dev/urandom|head -c 300`.blue, "\n" +puts `head -c 300 < /dev/urandom`.blue, "\n" if ARGV.join(' ') =~ /--cd=([^\s]+)/ - # puts "cd "+$1 Dir.chdir Regexp.last_match(1) else Dir.chdir Dir.home end @@ -71,35 +68,31 @@ cat, pwd, ls shell builtins file add file to chatgpt input c run command in sh ll, ls -l, Show the contents of folder and beginning of files chrome, run chrome\nrs, restart\nexit, exit\nupdate, update sys\nhelp\nshow this help"; next - # nex when /^file\s/ line = line.sub(/^file\s+/, '') line = File.read(line) when 'exit' exit when 'update' - system 'sudo apt update&&sudo apt upgrade' + system 'sudo apt update && sudo apt upgrade' when 'rs' exec "ruby #{File.expand_path(__FILE__)} --cd=#{Dir.pwd}" - # exit when /^cat\s*[^\s]+$/ require 'colored' l = File.read(line.sub(/^cat\s+/, '')) print l, "\n", '[', l.count("\n"), ' lines', ']', "\n", "\n" - # system 'ls --color=auto' next when /^pwd$/ puts Dir.pwd next when /^cd\s*.*$/ require 'colored' line = line.sub(/^cd\s*/, '').strip line = Dir.home if line == '' - # line = begin Dir.chdir line rescue StandardError begin print "No directory\n" @@ -109,11 +102,10 @@ system 'tput reset' puts Dir.pwd.bold puts system ' ls --color=auto' next - # end when 'chrome' system 'google-chrome 2>/dev/null&' next when /rgrep.+/ when /^ll|(ls -l)($|\s)/ @@ -121,32 +113,27 @@ system 'tput reset' Dir.glob('*').sort.each do |path| File.open(path) do |f| if path.match?(/(png|jpg)$/) puts path.magenta.bold - # puts path.purple.bold - # puts path.magen else puts "#{path} > ".bold + f.read(100).dump end end rescue Errno::EISDIR puts path.blue.bold end next when /^ls(.*?)$/ - # puts 5 system "ls --color=auto #{Regexp.last_match(1)}" next when /^c\s/ line = line.sub(/^c\s+/, '') begin - system line, exception: true # rescue => e begin - # puts 'failed' - # end + system line, exception: true rescue Exception => e begin begin Dir.chdir(line) rescue StandardError @@ -177,11 +164,12 @@ end return line end end -# require 'colored' + + loop do $d = read(1) $t = read(2) # r puts 'Running chatgpt' require 'ruby/openai' @@ -197,10 +185,10 @@ retry end out = response.dig('choices', 0, 'message', 'content') File.write 'out', out File.write Time.new.to_i.to_s, out - system 'cat out | xclip -selection c' + system 'xclip -selection c < out' puts out rescue Interrupt puts end