r_bash – Telegram
How to do tab completion with denoscription?

I'm using ZSH, but what I'm looking for is how to make an application written in bash noscript to show these completions for flags on tab

​

​

https://preview.redd.it/jrcpe1rf6q991.png?width=968&format=png&auto=webp&s=88787f987f4d8779ed87acc55f2205c35adf89af

https://redd.it/vrukx2
@r_bash
Pipe to my noscript

SOLVED

How do I make my noscript use piped input?

What I've tried is this:

>INPUT=$@
>
>echo "$INPUT"

​

I'm writing a wrapper for fzf. I want to use fzf from gui applications and call it from python noscripts, but also pipe command outputs to the scritpt

​

Thanks everyone.

This is the final noscript:

#!/bin/env sh
OUTPUTFILE=$HOME/.cache/menu
INPUT
FILE=$HOME/.cache/menutmp
cat > $INPUT
FILE
$TERM -t fzf -e bash -c "cat $INPUTFILE | fzf > $OUTPUTFILE"
cat $(echo $HOME/.cache/menu)

If you have improvements let me know

https://redd.it/vrvex7
@r_bash
completion how-to: completing to things that your $SHELL would have completed (eg: from $PATH)

tl;dr Writing a bash completion, but want to complete to programs available to you (executables, functions, etc). So I think I need a list of all said things (like all executables across all $PATHs, all aliases that alias would print, etc.). How do I get that list without re-inventing half the searching and listing logic that bash itself implements (or for that matter, which or command or the myriad other such programs implement)?


I think the above is enough to go on, but just in case that's confusing, let me take a step back...

## background

I have a program - say analyzer - whose first argument should always be another executable. The intended use-case is perhaps there's a program - say some-program - in your environment (ie: in your $PATH) that you were just executing or about to execute and you thought "wait let me pass that to `analyzer` first by calling `analyzer some-program`"

To clarify, here's example usage lines:

$ analyzer analyzer
$ analyzer bash
$ analyzer type

# or imagine this is defined somewhere else and somehow is sourced into
# your current environment:
# function foobar() { ...write and then forget what you wrote... }
$ analyzer foo
bar

## problem to solve

So now I want to write a bash completion for analyzer so that you can tab-complete that first argument. Eg: a session in your shell might look like:

# can successfully get the same completion as b[TAB] being my $0
$ analyzer bTAB
base32 base64 basename bash

# can successfully get the same completion as he[TAB] being my $0
$ analyzer heTAB
head help hex2hcd hex2rgb hexdump

Writing a bash completion isn't that hard, but producing this list I want seems pretty tricky...

https://redd.it/vsidsx
@r_bash
partially known file pattern

I have a file that will either be called

fileday.log
Or
file
night.log

I need to grep inside this file remotely for a pattern

Tried a few combinations and getting file doesn't exist error.

Any suggestions

https://redd.it/vtdroz
@r_bash
bash philosophy on noscripts?

Not a programmer but I create simple bash noscripts for reading values in the operating system and whatnot.
Basically one liners gathered into single noscripts.
Over time any simple noscript turns into a noisy noscript with a bunch of if/then's all throughout to keep it running or anticipate wrinkles. I'd like to get back to the simplest smallest lines again.
Is there something that should be added universally that might deal with commands behaviors overall?

https://redd.it/vtllxo
@r_bash
Need help with a loop

I'd be very grateful if you could help me with a loop. I have a directory full of files named like this:

T01s1new.file
T01s2new.file
T02s1new.file
T02s2new.file

And so on and so forth up to 100. What I need to do is run a command that takes T01s1new.file and T01s2new.file as two inputs at the same time, then it will automatically loop through and start on T02s1new.file and T02s2new file. Then on to the two inputs of T03, T04...

I've tried all sorts of bash ranges like for i in {T01..T100} but no luck, I can't get it to connect the s1new.file part.

My command without a loop will look something like this...

myprog -o myref -i T01s1new.file T01s2new.file

And so on and so forth. I could do them individually but it would take forever. Any advice is greatly appreciated.

https://redd.it/vtk5hg
@r_bash
Bash - store which elements of an array failed to execute some command

read -r -p "Enter the filenames: " -a arr

for filenames in "${arr[@]}"; do
if [[ -e "${filenames}" ]]; then
echo "${filenames} file exists (no override)"
else
cp -n ~/Documents/library/normal.py "${filenames}"
fi
done

Suppose, I've B.py D.py in a folder.

When I run this noscript in the same folder and write A.py B.py C.py D.py (undefined number of inputs)
Files named A.py C.py are copied successfully.

Whereas for B.py D.py, it shows B.py file exists (no override) and D.py file exists (not override) respectively.


I want to store elements which did worked and which didn't work in separate arrays from main array ${arr[@]}

arr=('A.py' 'B.py' 'C.py' 'D.py')
didworked=('A.py' 'C.py')
notworked=('B.py' 'D.py')


How can i do that? Any suggestions, please.

https://redd.it/vu4jo2
@r_bash
Show largest installed packages

Hi all!
I have created a small utility named pkgtop to show largest installed packages. It uses bash, awk, sort and some other external commands existing in very base systems to implement its functionality.
There are also some filtering and counting features and support for the most popular GNU/Linux distributions:
\- Ubuntu/Debian;
\- Fedora/RedHat/CentOS/OpenSUSE;
\- ArchLinux;
\- OpenWRT;

The colour output makes it possible to compare installed packages visually.

If you are intrested, welcome to the project's page on github. I would be happy if you also will find it useful.

https://redd.it/vugvqs
@r_bash
working with text

lets say i have a line: "blah blah blah ID blah blah blah request_id=432784 blah blah" stored in a text file text.txt(this file containes multiple lines like this one). now i want just to print request id i.e. 432784. how will i do that?

https://redd.it/vv0ojn
@r_bash
using apt in a noscript?

Hey, I want to create a noscript for my linux system, which downloads a few things, create folders and executing other Linux shell commands...

Could you recommend me a tutorial?
I'm familiar with "normal" programming, but I never worked with bash yet.

Thanks!

https://redd.it/vvngnm
@r_bash
Interactive practice based on "Advanced Bash Scripting Guide"?

Is there an online interactive practice site based on "Advanced Bash Scripting Guide"?

https://redd.it/vwh70k
@r_bash
permission Denied

Hi everyone,

I'm currently learning about OSs alongside an IT Support Specialist course (complete novice). I'm trying to execute some simple commands in Bash on my Chrome OS Acer Chromebook but keep getting "Permission Denied"

This happens when I try something as simple as "mkdir documents"

Anyone who can spare a few secs to school a newbie would be much appreciated.

https://redd.it/vwfaxf
@r_bash
Help - terminal noscript to export activity data

I'm trying to save data from Activity Monitor (Mac OS), ideally specific categories & columns (ie. GPU -Process Name & Memory), and export as csv but there's no way to within the program.

I figure it would be a simple terminal noscript to display the same data in Terminal and save to a file but I'm don't really know enough to write it.

Can anyone help?

https://redd.it/vxyl3o
@r_bash
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