ThePrimeagen / .dotfiles

3.01k stars 303 forks source link

fix: make tmux-cht.sh works correctly #37

Closed saccarosium closed 10 months ago

saccarosium commented 1 year ago

Hi, I know you don't really care about form, especially on scripts, but I think that you should take a little of time to learn how to properly do some stuff in bash scripting because you teach some of this stuff in your paid courses... And the majority of your scripts have major bug or have a not very solid implementation.

An example:

tmux neww bash -c "echo \"curl cht.sh/$selected/$query/\" & curl cht.sh/$selected/$query & while [ : ]; do sleep 1; done"

You are trying to concatenate 2 commands one another and you are using the & operator. The & operator will execute a chain of command, but it will not respect the order. It will run the fastest first then the second fastest and so on. This is probably why you run the query two times, because you had found that sometimes it went to the loop without printing anything. The correct approach is using the && operator witch will execute the second command only if the first one finished and succeded.

Also another thing don't use `` backticks for spawning a sub shell, use $() instead because the first method has been deprecated.

I doubt you are gonna listen to my advice but a great resource for learning bash scripting is the bash bible

fseiixas commented 1 year ago

@saccarosium I was looking in your script, pretty nice BTW. Where to add "less" command to improve usability?

saccarosium commented 1 year ago

Hi @fseiixas, I've updated the PR to use less. I didn't use it at first because I didn't know how to have it interpret colours correctly. I found out that if you call less -r all the colours are correctly handled.