r_bash – Telegram
tmyt - is a terminal youtube client

Hi!

I wrote a small bash noscript to browse youtube and consume content via terminal emulator.

​

tmyt's default menu

I know there is ytfzf, but my noscript is a bit snappier, although doesn't have as many features. It has whiptail tui and menus for history and favorite channels.

It does work in tty. Mpv can play music in terminal and also starts x server if video is played. An option to output video frames to ASCII characters could be set but resolution would be low.

The way it works is it curls youtube's search/channel page and finds links and noscripts. It usually gets about 30-40 videos. It doesn't check for available resolutions but gives preset right away and it case the resolution isn't available it will play at the highest resolution available. The noscript downloads video/audio using yt-dlp. It also can take advantage of mpv's option to play and download video at the same time which i like a lot.

github page

Thank you for taking the time :)

https://redd.it/vy443x
@r_bash
Flex on me with your backup noscripts for your home directory.

I'm trying to do something similar to this, which I found online:

#!/bin/bash
DATE=$(date +%d-%m-%Y)
BACKUPDIR="/backup"

# To backup akash's home directory
tar -zcvpf $BACKUP
DIR/akash-$DATE.tar.gz /home/akash

# To delete files older than 15 days
find $BACKUPDIR/* -mtime +15 -exec rm {} \;

Thing is I want the BACKUP\
DIR variable to be a foreign directory on my LAN, raspberry pi 4 w/ a ssd.

I already have an SSH alias in my \~/.ssh/config, how would I go about this?

I want to run the noscript from my host laptop, but am open to whatever is most optimal.

Feel free to throw any tips or tricks, I'm just now learning that you can do commands via ssh without having to open the actual shell on the external comp/server

https://redd.it/vzfyxs
@r_bash
Bash noscript output line disappears from console ?!

Hi,

I have the below noscript which displays the amount of data being archived, and compressed in the same line in the while loop.

ctar=$(tar uvf $basedir$archName -C $basedir $arch $dlog $core $phy $con --warning=none --absolute-names > /dev/null 2>&1 & echo $!)
while kill -0 $ctar >/dev/null 2>&1
do
echo -ne "$(date +"%T.%3N") Archived ${RED}~$archval2 MB${NC} of log data to $archName..\r"
done
echo -e "\n$(date +"%T.%3N") Archiving complete.."
flname=$archName.gz
b=$(gzip $basedir$archName > /dev/null 2>&1 & echo $!)
sleep 1.5
while kill -0 $b >/dev/null 2>&1
do
comval=$(ls -l $basedir$flname | awk '{print $5}')
comval1=$((comval / (1024*1024)))
comval2=$(echo $comval1 | awk '{print int($1+0.5)}')
echo -ne "$(date +"%T.%3N") Compressed $flname to ${RED}~$comval2 MB${NC}..\r"
done
echo -e "\n$(date +"%T.%3N") Compression complete.."

The output from the above command on console screen is

09:08:18.585 Computing data, and disk sizes..
09:08:18.611 Log data size ~3066 MB..
09:08:18.616 Archive VME1_15Jul2022_0908.tar created in /data/storage/..
09:09:36.521 Archived ~2799 MB of log data to VME1_15Jul2022_0908.tar..
09:09:36.522 Archiving complete.. <---
09:13:38.265 Compressed VME1_15Jul2022_0908.tar.gz to ~674 MB..
09:13:38.266 Compression complete.. <---

I want to get rid of lines marked with <--- above from the onscreen console. The problem is if I remove the corresponding echo lines

echo -e "\n$(date +"%T.%3N") Archiving complete.."
echo -e "\n$(date +"%T.%3N") Compression complete.."

The on screen console output appears as follows

09:08:18.585 Computing data, and disk sizes..
09:08:18.611 Log data size ~3066 MB..
09:08:18.616 Archive VME1_15Jul2022_0908.tar created in /data/storage/..

How can I show the below lines on screen console

09:09:36.521 Archived ~2799 MB of log data to VME1_15Jul2022_0908.tar..
09:13:38.265 Compressed VME1_15Jul2022_0908.tar.gz to ~674 MB..

Thank You

https://redd.it/vzkex3
@r_bash
After installing ble.sh, I have to press return twice to execute a command from history. How do I switch this behaviour off?

If I get a command from the history, either by "arrow up" or Ctrl-R, I have to press return once for getting into "edit mode" (for lack of a better denoscription) and then again to execute the command.

I would like to only press return once. When I disable ble.sh, this is the case, but I would like to keep ble.sh's other functionality.

Thanks for any advice!

https://redd.it/vzskog
@r_bash
I created a simple for loop in shell noscript, but instead of showing the correct output its just showing {1..4}. I am using Linux mint 20. Do anyone know the solution?

https://redd.it/w0bq46
@r_bash
I used #!/bin/bash to say happy birthday to my mate...

Hi everyone...

My name is Ze'ev and I am a proper noscript bunny. If I can't noscript it I don't want to do it. Obviously that means BASH and I have a very very close relationship. I use it for everything.

So, it's my mate's birthday today, and he has recently become very interested in BASH, when I showed him how 38 lines can solve a problem they were having at work, that they had been spending weeks on using C#. He was blown away, and now wants to learn BASH.

So I figured, what would be the coolest way to say happy birthday then? Using BASH of course...

I whipped up a small noscript for him this morning, wrote my message out in a text file, then used OBS to record it. BEST BIRTHDAY WISH EVER!!!

#!/bin/bash
declare a=""
while read string
do
for ((i=0; i<=${#string}; i++))
do
a=$( shuf -i 1-5 -n 1 )
mpg123 -q $a.mp3
printf '%s' "${string:$i:1}"
sleep 0.$(( (RANDOM % 5) + 1 ))
done
sleep 0.8
mpg123 -q 0.mp3
echo ""
done < typeit.txt

&#x200B;

https://reddit.com/link/w0anz5/video/ibfdxsz1rvb91/player

https://youtube.com/watch?v=Z3npE5Orqs0&feature=share

https://redd.it/w0anz5
@r_bash
> Input Redirect. Can someone help me understand it?

I originally posted this in r/linuxquestions. Realized this may be the better place for it.

I am trying to get very familiar with bash and the only thing that stumps me, on the topic on redirection, is < input redirection. I'm not understanding how it works really or how to utilize it. I have looked at tutorial after tutorial and its still not clicking.

Can someone give examples of how they typically use it? Perhaps, good examples to really showcase its uses and potential.

\> output redirection is easy, makes sense. but for some reason the input part really throws me off.

https://redd.it/w0pa88
@r_bash
my first ever bash noscript is completed only took 4 hours because im stupid
https://redd.it/w1klky
@r_bash
If I know that my noscript is a bash noscript, is there any reason to use ./noscript.sh instead of bash noscript.sh?

Just realised I still have this very basic question.

./noscript.sh runs into several permission problems with execution & requires I put a shebang in the noscript.

bash noscript.sh doesn't need permissions & doesn't need me to put a shebang.

Is there any reason I should still use ./noscript.sh? Thanks!

https://redd.it/w2kpu7
@r_bash
Centering dynamic text

The below code will sort and format a multi-line string into 2 to 4 columns depending on the size of the screen top left justify leaving a lot of space to the right and bottom.

Is it possible to center it both vertically and horizontally using just built-in linux commands?

clear; echo "$all_denoscriptions" | sort -u | column

https://redd.it/w2yad9
@r_bash
Do You Prefer Backticks () or Parentheses ($()) For Command Substitution

The following two lines of code do the exact same thing:

var=`head -1 file`
var=$(head -1 file)


Which version do you prefer?
I think that backticks look nicer and cleaner but most people use parentheses.
I know that you need to escape nested backticks, so what about using parantheses in that case but backticks otherwise?
Also, there is an insignificant functional difference:

`# user` echo "`echo \"test\" `"
test
`# user` echo "$(echo \"test\" )"
"test"


https://redd.it/w3jqlz
@r_bash
Trying to pipe output of one program into grep but I can't get it right

xflux outputs this:

> Welcome to xflux (f.lux for X)
This will only work if you're running X on console. Found 1 screen.
Your location (lat, long) is -180.0, 35.0. Your night-time color temperature is 3400.
It's night time. Your screen is changing now.
Going to background: 'kill 30031' to turn off

The only important part is the kill process-ID. I want to copy it to an executable file so I can stop the program easily. Just using > for redirection makes it a stream file which cannot be executed even after using chmod +x. Sadly xflux doesn't just have a flag to stop the program built in.

Here's what I tried running:

> xflux -g 35.0 | grep -e "^kill \d+$" > StopFlux

^ means beginning ofa string, \d means a digit, + means one or more of the preceeding, and $ means end of string if I did it right

https://redd.it/w47l61
@r_bash
grep -P vs grep -E vs grep -G

Hello guys!

I did read this post:

https://superuser.com/questions/269803/which-regular-expression-standard-is-used-in-grep

about grep and regex, but I got a noob question, what is the best choice for a general purpose? I remember oftentimes, I had to use \\( \\) \\{ \\} etc... because basic grep does not support meta chars (If I'm not wrong) I started to use grep -P {pattern} and is very comfortable, is that okay? In your experience, what is the best choice?

https://redd.it/w5ige9
@r_bash
Store jquery value as variable in Bash noscript?

So I currently am attempting to create a bash noscript which stores the value of a jquery item and outputs it to a variable. What I am a bit confused about is how to do this. I am currently doing the following:


#!/bin/bash

#Initial Curl Request

GETREQUEST=$(curl --request GET \
--- url https://...... \
--- header '.......... \
--- header '.......... \

#Get value of json response

echo $GET
REQUEST | jq -r '.initial.value'

#Store Value as new variable
Value=$(jq -r '.initial.value')

echo $Value



Now the issue I believe here is when I echo $Value I get nothing because I believe that the new variable is not actually storing anything, am I trying to get this value incorrectly using the jquery?


Whereas with the echo of $GET_REQUEST I actually get the variable because it picks it out of the json response. Is there a way to maybe get that value and then store it as a variable then?


Let me know if any clarification is needed!

https://redd.it/w7l4xi
@r_bash
libby: a simple CLI tool to quickly download books from libgen (Library Genesis)

libby scrapes Library Genesis with curl and pup and gives you a list of downloads with fzf. I made this because I felt the alternatives were too slow. Feel free to add issues/feature requests/PRs!

The tool is available on the AUR as libby-git.

Demo

GitHub

Source

https://redd.it/w6rxrk
@r_bash
Why Does No One Use Inline Comments

In C, there are two ways of writing comments:

// Regular comment
/* Inline comment */


I always preferred the second type of comment because it allows you to make inline comments.
I know a lot of programmers who agree with this.
bash also has two ways of writing comments:

# Regular comment
`# Inline comment`


But I have never seen anyone ever use this.
I wonder why.
Is it not portable to every other shell?
I like to use it because it has a beginning and an end.
Are there any downsides to bash's inline comments?

https://redd.it/w8dy8d
@r_bash
Script with arguments with spaces in it.

Hello people...I have a situation that is driving me crazy and I can't solve it. I have a noscript with a function that takes 4 arguments (paths and names of a file) from a text file (I could do it with 3, but I got used to all 4).

It works great when there is no space in the file/folder name, but the moment the space appears, I think what it does is take the next word as a newline and unset everything.

This is the part of the noscript:

#!/bin/bash

driveplex="Plex:Plex/Peliculas"
drive
rtorrent="rtorrent:rtorrent"
localdostb=$"/home/user/2tb"

func () {
hora=$(date +'%T')
local
moviepath=$(cut -d '/' -f1-7 <<< "${1/\/data\/Plex/$localdostb\/archivos}")
plexmoviepath=$(cut -d '/' -f1-3 <<< "${1/\/data\/Plex\/Peliculas/$driveplex}")
file
name=$2
localsourcepath="${3/\/data/$localdostb}"
rtorrent
sourcepath="${3/\/data\/transmission/$drivertorrent}"
rtorrentsourcefolder="${4/\/data\/transmission/$drivertorrent}"
local
sourcefolder="${4/\/data/$localdostb}"
archivo="$localsourcefolder/$filename"

echo -e "localmoviepath: $localmoviepath
filename: $filename
localsourcepath: $localsourcepath
rtorrentsourcepath: $rtorrentsourcepath
rtorrentsourcefolder: $rtorrentsourcefolder
plexmoviepath: $plexmoviepath" >> /home/user/log.log
}


func "${1}" "${2}" "${3}" "${4}"

This is the input example:

/data/Plex/Peliculas/Divergent.(2014)/Divergent 2014 1080p BluRay DTS-HDMA 7.1 x264-RUXi.mkv
Divergent 2014 1080p BluRay DTS-HDMA 7.1 x264-RUXi.mkv
/data/transmission/radarr/Divergent 2014 1080p BluRay DTS-HDMA 7.1 x264-RUXi.mkv
/data/transmission/radarr

This is how i pass the file:

noscriptname $(<textfile)

This is what it returns:

localmoviepath: /home/user/2tb/archivos/Peliculas/Divergent.(2014)
filename: 2014
local
sourcepath: 1080p
rtorrent
sourcepath: 1080p
rtorrent
sourcefolder: BluRay
plex
moviepath: Plex:Plex/Peliculas/Divergent.(2014)

This is what it returns if there are no spaces:

local
moviepath: /home/user/2tb/archivos/Peliculas/Divergent.(2014)
file
name: Divergent.2014.1080p.BluRay.DTS-HDMA.7.1.x264-RUXi.mkv
localsourcepath: /home/user/2tb/transmission/radarr/Divergent.2014.1080p.BluRay.DTS-HDMA.7.1.x264-RUXi.mkv
rtorrentsourcepath: rtorrent:rtorrent/radarr/Divergent.2014.1080p.BluRay.DTS-HDMA.7.1.x264-RUXi.mkv
rtorrentsourcefolder: rtorrent:rtorrent/radarr
plexmoviepath: Plex:Plex/Peliculas/Divergent.(2014)

I've tried enclosing variables in quotes, in curly braces, tried escaping spaces with backslashes, even tried passing quoted arguments from the file directly, but still get the same behavior.

If you could give me a guide, I would really appreciate it.

Thanks!

https://redd.it/wapmlk
@r_bash