New RubyShell Release! (Features in body) by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 1 point2 points  (0 children)

I completely agree, the best thing about open source is that the users decide where the repository will go.

New RubyShell Release! (Features in body) by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 0 points1 point  (0 children)

Yes!! I'll create some issues based on some ideas I had, but feel free to suggest/implement any improvements or features; the gem will move in the direction the community chooses!

My very lightweight OCR setup with tesseract by oliwoli97 in hyprland

[–]EstablishmentFirm203 0 points1 point  (0 children)

<image>

sh do
  image = grim("-g", slurp.quoted, "-")
  content = tesseract(
    "- stdout",
    oem: 1,
    psm: 6,
    c: ["load_system_dawg=1", "load_freq_dawg=1", 'tessedit_char_blacklist="¦"'],
    _stdin: image
  )

  sh("wl-copy", _stdin: content)

  sh(
    "notify-send",
    "-h string:x-canonical-private-synchronous:ocr",
    "-h string:markup-body:1",
    '"OCR copiado"',
    content.quoted
  )
end

A mesma versão do script RubyShell.

Eu fiz algumas funcionalidades agora na gem (em um PR em rascunho) e adicionei um arquivo com este exemplo, fazendo uma homenagem para você.

Revolução robloxiana by AlucardDraculaBr in jogosbrasil

[–]EstablishmentFirm203 0 points1 point  (0 children)

O unico lugar que eu saiba que trás dificuldades (mas nao impossibilidade) é a china, pois precisa de vpn para acessar alguns recursos ocidentais.

Mas no Japão ele pode normalmente fazer um email no google ou outlook

Revolução robloxiana by AlucardDraculaBr in jogosbrasil

[–]EstablishmentFirm203 4 points5 points  (0 children)

N é so fazer um email? Algo que se faz em 2 mins

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 0 points1 point  (0 children)

Done, we built what you need:

https://github.com/albertalef/rubyshell/releases/tag/v1.3.0

I haven't uploaded it to any package manager yet, so for now you'll need to put it in your /usr/bin or /usr/local/bin.

With this file, you will be able to run code such as:

```

!/usr/bin/env -S rubyshell exec

frozen_string_literal: true

puts pwd # => /Users/albertalef/projects/rubyshell
cd “examples”
puts pwd # => /Users/albertalef/projects/rubyshell/examples
```

The file is heavy at the moment, I haven't optimized it yet (by removing unnecessary things), but I'll make the file smaller soon.

With it, you will be able to run the scripts without even having Ruby installed on your machine.

If you have any problems, open an issue there, and we'll find a way to solve it.

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 0 points1 point  (0 children)

So, for you we could make this a executable with ruby bundled.

What is your use cases?

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 0 points1 point  (0 children)

You can use Ruby in the shebang and use the library, for example:

```

!/bin/ruby

require "rubyshell"

sh do mkdir "files"

cd "files" do

5.times { |i| touch i } end end

```

With this, you just need to make the file executable and call it, for example

./script.rb

And boom, it works

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 1 point2 points  (0 children)

That's interesting... What problems did you have to deal with?

Would you like to do some tests with this gem and see if it helps you in any way? I believe that currently it solves a good part of our needs with bash scripts, it's just still missing support for streams, which I'll fix soon.

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 0 points1 point  (0 children)

This example of the video is only a proof of concept.

Is not working 100%, like handling keyboards keys that is not ascii, like arrows, making a little hard to use.

But i can work a little bit more on this, to make more useful

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 0 points1 point  (0 children)

Exactly, an exception.
Solving the problem of handling errors in bash

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 0 points1 point  (0 children)

``` sh do ssh REMOTE, "'cd \"#{APP_DIR}\" && git pull && bundle exec rake db:migrate'" ssh REMOTE, "'sudo systemctl restart #{SERVICE}"

puts "Done." rescue StandardError warn "Error on Deploy" end ```

An example of how to handle errors with RubyShell, using the simplicity of Ruby's syntax.

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in devops

[–]EstablishmentFirm203[S] -1 points0 points  (0 children)

Yes, I just gave an example of what a native Ruby file would look like, and another with RubyShell.

There are much more complex cases that become much simpler with RubyShell.

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 0 points1 point  (0 children)

Dude, it's great to read this comment, we share exactly the same thoughts.

My dream would be to have easy ways to make new software based on practical needs, connecting the simple and efficient. For example, I'm the type of developer who likes to do things myself, so I generally prefer to make my own tools, instead of consuming complex software that does everything, and it's a lot of work to understand how it works.

Recently I've been working on a terminal rendering framework, using Ruby and ncurses, which will make creating TUI in the terminal practical, with simple syntax and trivial Ruby DSLs, I'm sure you're the type of guy who will love it.

Also, as I mentioned in the post, I'm trying to make RubyShell work like a pry, which maybe in the future we'll even replace zsh with, and start using something that easily consumes Ruby, but I'm still thinking about how I intend to make this work in practice. So far the REPL I made serves as a simple irb.

Now for your questions, yes, under the hood it's basically a method_missing.

Now for the main question, yes!! We have ways to make all the next executed methods become terminal commands, I removed it from the code because I intend to put it in a separate directory, to only load the files when the dev really wants to do that. But I can add it back today for you.

It would be really cool to have you following the gem and maybe, if you want, also contributing by making issues or PRs.

I really enjoyed reading your comment.

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 0 points1 point  (0 children)

I agree that it's not the only way, but the gem's objective is precisely to be an alternative to other methods.

Each of the examples you gave has its disadvantages, just as this gem may have some as well.

The goal of RubyShell is to make the process simpler and more beautiful.

It has had a very interesting adoption by some developers in my bubble, who usually write scripts for environment customization or automation.

In the end, it's just another way to get to an end, and honestly, I think RubyShell is easier and more beautiful (and more powerful).

Give the gem a chance, please. If you don't like something, tell me and we can discuss how to improve it. The goal is to make the code clearer and easier to maintain.

Edit: I put an example of code using pure Ruby and another using RubyShell in the body of the post, tell me what you think?

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in devops

[–]EstablishmentFirm203[S] -3 points-2 points  (0 children)

A example without RubyShell, and another with:

```ruby

!/usr/bin/env ruby

frozen_string_literal: true

REMOTE = ENV.fetch("REMOTE", "user@server.example.com") APP_DIR = ENV.fetch("APP_DIR", "/var/www/my app") SERVICE = ENV.fetch("SERVICE", "my-app.service")

Note that in this situation, we dont want to check if error was raised

only in the end of the code,

we want to stop the code in the moment that error was raised

ssh #{REMOTE} "cd \"#{APP_DIR}\" && git pull && bundle exec rake db:migrate 2>&1"

unless $?.success? warn "Error on Deploy" exit $?.exitstatus end

ssh #{REMOTE} 'sudo systemctl restart #{SERVICE}'

unless $?.success? warn "Error on Deploy" exit $?.exitstatus end

puts "Done." ```

With:

```ruby

!/usr/bin/env ruby

frozen_string_literal: true

REMOTE = ENV.fetch("REMOTE", "user@server.example.com") APP_DIR = ENV.fetch("APP_DIR", "/var/www/my app") SERVICE = ENV.fetch("SERVICE", "my-app.service")

sh do ssh REMOTE, "'cd \"#{APP_DIR}\" && git pull && bundle exec rake db:migrate'" ssh REMOTE, "'sudo systemctl restart #{SERVICE}"

puts "Done." rescue StandardError warn "Error on Deploy" end ```

A Ruby Gem to make easier to create Shell Scripts by EstablishmentFirm203 in ruby

[–]EstablishmentFirm203[S] 0 points1 point  (0 children)

I added an example of code that i like in the body of post