r_bash | Unsorted

Telegram-канал r_bash - r_bash

46

Credits: @r_channels & @reddit2telegram

Subscribe to a channel

r_bash

bash debugger
https://redd.it/1utcg27
@r_bash

Читать полностью…

r_bash

TUIs for everything

TLDR: Looking for bash-only TUI tools far using on multiple platforms

The long version: I’m not entirely a command line noob, but also I’m bad at remembering things. What I’m trying to do is assemble a collection of TUIs that I can get relatively the same functional experience with whether I’m on a Linux distro, BSD, or whatever.
And before anyone asks, yes I like TUIs, they’re easier for me, yes I realize they can be slower, yes I understand that all the pro haxorz use super lightweight custom optimized bash scripts. I don’t care about that. I’m trying to make life easier for myself when I’m constantly switching systems. That being said, if anyone has some recommendations for their favorites, please feel free to drop them in the comments! Much appreciated! Hope you all have a wonderful day.

https://redd.it/1us0m32
@r_bash

Читать полностью…

r_bash

Rclone backup script feedback (My first ever time shell scripting)

I'm really just looking for advice since I'm unaware of conventions, as well as just the best way to really do anything.

I made it since I wanted to use a old laptop I had sitting around to host a minecraft server, but I did not want to lose access to automatic backups like I have had with the large free server providers. It's worked pretty well with my testing, and I plan to set it up as a cron job to run every day.


# rclone backup script



# ====== Configuration ======



# Please ensure all directories exist at all times or the script may fail to properly backup your data.
SOURCE="/home/YOURUSER/item"
REMOTEBACKUPLOCATION="gdrive:backups"
LOCALBACKUPLOCATION="/home/YOURUSER/backups" # enter "none" if you do not want any local backups.


LOCALBACKUPAMOUNT=5
REMOTEBACKUPAMOUNT=5
BACKUPNAME="automatedbackup" # Timestamp will appear after this name.


# ===========================


# -------- Variables --------


# WARNING: do not touch these unless you know what you are doing.


TIMESTAMP=$(date "+%Y-%m-%d
%Hh%Mm%Ss") # Please use a timestamp that will display in a descending order so that old backups will be cleaned up problerly. This WILL break the script.
# You can almost certainly safely remove the seconds and minutes from the timestamp unless you are making several backups in an hour.


# ---------------------------


echo "Starting backup."


if [ "$LOCAL_BACKUP_LOCATION" != "none" ]; then
    tar -czf "${LOCALBACKUPLOCATION}"/"${BACKUPNAME}"${TIMESTAMP}.tar.gz "${SOURCE}"
    rclone copy "${LOCAL
BACKUPLOCATION}"/"${BACKUPNAME}"${TIMESTAMP}.tar.gz "${REMOTEBACKUPLOCATION}"


    echo "Cleaning up local backup directory."
    backups=$(rclone lsf "${LOCALBACKUPLOCATION}" --filter="+ "${BACKUPNAME}*"" --filter="- *" | sort -r)


    backup
control=0


    for backup in $backups; do
            ((backupcontrol++))
            if ((backup
control > $LOCALBACKUPAMOUNT)); then
            rm -rf "${LOCALBACKUPLOCATION}"/"${backup}"
            fi
    done
    echo "Old local backups removed."
fi


if [ "$LOCAL_BACKUP_LOCATION" == "none" ]; then
    tempdir=$(mktemp -d)
    tar -czf "${temp
dir}"/"${BACKUPNAME}"${TIMESTAMP}.tar.gz "${SOURCE}"
    rclone copy "${temp
dir}"/"${BACKUPNAME}"${TIMESTAMP}.tar.gz "${REMOTEBACKUPLOCATION}"
    rm -rf "${temp
dir}"
fi


echo "Backup Complete."


echo "Cleaning up remote backup directory."
backups=$(rclone lsf "${REMOTEBACKUPLOCATION}" --filter="+ ${BACKUPNAME}*" --filter="- *" | sort -r)


backup
control=0


for backup in $backups; do
        ((backupcontrol++))
        if ((backup
control > $REMOTEBACKUPAMOUNT)); then
                rclone deletefile "${REMOTEBACKUPLOCATION}"/"${backup}"
        fi
done
echo "Old remote backups removed."


echo "Full backup sequence complete. ${TIMESTAMP}"

# rclone backup script



# ====== Configuration ======



# Please ensure all directories exist at all times or the script may fail to properly backup your data.
SOURCE="/home/YOURUSER/item"
REMOTEBACKUPLOCATION="gdrive:backups"
LOCALBACKUPLOCATION="/home/YOURUSER/backups" # enter "none" if you do not want any local backups.


LOCALBACKUPAMOUNT=5
REMOTEBACKUPAMOUNT=5
BACKUPNAME="automatedbackup" # Timestamp will appear after this name.


# ===========================


# -------- Variables --------


# WARNING: do not touch these unless you know what you are doing.


TIMESTAMP=$(date "+%Y-%m-%d
%Hh%Mm%Ss") # Please use a timestamp that will display in a descending order so that old backups will be

Читать полностью…

r_bash

Help with file renaming task

I have a directory containing a bunch of directories whose names all start with a year. They are all formatted as either "YYYY Title" or "(YYYY) Title" but I want to rename them all to "YYYY - Title". This seems like it should be a simple task but I'm still pretty inexperienced and my brain is fried lol

I imagine one way would be something like:

- iterate over the directories with a for loop

- for each one, use regex to match four digits in a row (\d\d\d\d)

- assign only the matching part of the string to a variable (this is the part I don't know how to do)

- use sed or awk or something to replace the first 6 characters with this variable plus " -", then mv to rename to the output of that

Would appreciate any help!

https://redd.it/1ur8jih
@r_bash

Читать полностью…

r_bash

Decoding the obfuscated bash script on a Uniqlo t-shirt
https://tris.sherliker.net/blog/obfuscated-self-evaluating-bash-script-by-cdn-akamai-being-supplied-to-consumers-via-retail-stores/

https://redd.it/1uqvhd9
@r_bash

Читать полностью…

r_bash

Overwrite shell interface

Hello! I'm still fairly new to Linux, and since I'm trying to use the terminal as my primary interface, I've been spending a lot of time working in Bash.

After about a month of daily use, I've noticed a few things that make the experience less comfortable. Features like autocompletion, syntax highlighting, and autosuggestions are easy enough to add with plugins, but there's one feature I haven't been able to find anywhere.

I'd love to have the command prompt stay fixed (sticky) at the bottom of the terminal, similar to the input box in a chat application.

For example, when I scroll up to review previous output, I'd like the prompt to remain visible at the bottom instead of scrolling away with the rest of the terminal. If I start typing while I'm viewing older output, it shouldn't automatically jump back to the latest line. The prompt should stay fixed until I explicitly choose to return to the bottom with ENTER key.

The idea is similar to this Bash workaround:

```

\# .bashrc

_prompt() {

tput cup "$LINES" 0

}

PROMPT_COMMAND="_prompt; $PROMPT_COMMAND"

```

This kind of interface would make it much easier to review previous output while continuing to type new commands, much like how chat interfaces work.

Is it possible to achieve something like this in Bash?

https://redd.it/1uqq6z4
@r_bash

Читать полностью…

r_bash

Need help with bash scripting? PM me.

My help is free and I have alot time to kill lately.
I can also teach you alot about linux in general.

You can also email me: reddit.king002@passmail.net

https://redd.it/1uq9oyc
@r_bash

Читать полностью…

r_bash

LeetCode for shell / bash

i'm looking for a place to practice bash or just shell in general, is there a place like such where i can practice daily and improve my muscle memory when it comes to shell commands? at the moment leetcode only offers like 5 shell problems and other focus more on teaching the basics or is more focused on solving mini problems than the shell itself like sadservers.

is there any platform where i can daily practice shell just like platforms where you can daily practice competitive programming problems?

TIA and sorry for grammar erros, english isnt my first language.

https://redd.it/1upql5q
@r_bash

Читать полностью…

r_bash

duplicate print of i iteration?

#!/usr/local/bin/bash
StartUp_Run=false
Iterator_For_File_Toucher_With_NCPU_While=0
Total_NCPU_For_File_Toucher_With_NCPU_while=$(nproc --all)

while true
do
if [ $StartUp_Run == false ]; then
while [ $Iterator_For_File_Toucher_With_NCPU_While -lt $Total_NCPU_For_File_Toucher_With_NCPU_while ]; do
echo "$Iterator_For_File_Toucher_With_NCPU_While"
touch core$Iterator_For_File_Toucher_With_NCPU_While-temp_orders.csv
let "Iterator_For_File_Toucher_With_NCPU_While+=1"
done
echo "ncpu amount = $Total_NCPU_For_File_Toucher_With_NCPU_while"
StartUp_Run=true
fi
done

prints, why? :

# sh LastStage.sh
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
ncpu amount = 16

https://redd.it/1upc93i
@r_bash

Читать полностью…

r_bash

Help scripting Caps lock on off status

Hey everyone. I have been using linux mint since a year and loved it. It just works without manual tinkering. But now, captivated by the tiling managers, i jumped to Cachy hyprland. It's interesting but doesn't have many basic functionalities like alerting user about Caps lock key status through sound. I took help of ai but it somehow spikes my cpu usage and i have to reboot to make it normal again. Here is the Script :

\#!/bin/bash

\# Target the specific caps lock directory (adjust if you have a specific one like input3::capslock)

LED_PATH=$(ls -d /sys/class/leds/*::capslock | head -n 1)

\# Fallback paths for the sounds

SOUND_ON="/usr/share/sounds/freedesktop/stereo/dialog-information.oga"

SOUND_OFF="/usr/share/sounds/freedesktop/stereo/dialog-warning.oga"

\# Read initial state

last_state=$(cat "$LED_PATH/brightness")

while true; do

\# Instant raw read of the file system

current_state=$(cat "$LED_PATH/brightness")

if [ "$current_state" != "$last_state" \]; then

if [ "$current_state" -eq 1 \]; then

\# Using pw-play or paplay with low-latency flags

pw-play "$SOUND_ON" &

else

pw-play "$SOUND_OFF" &

fi

last_state=$current_state

fi

\# 20ms polling rate (0.02s) gives instant human response time

\# without hurting CPU performance

sleep 0.02

done



Can you guys please help me out.

https://redd.it/1uo83ru
@r_bash

Читать полностью…

r_bash

how do you call the Calendar app from terminal?

Hi, I have installed Calendar, but I can not call it from cmd line...
How doy you call it from terminal?
screenshot GUI
Thank you and Regards!

https://redd.it/1umsv0t
@r_bash

Читать полностью…

r_bash

I can't even do the simple - inotify. please help
/r/linux4noobs/comments/1um3lha/i_cant_even_do_the_simple_inotify_please_help/

https://redd.it/1umcmqy
@r_bash

Читать полностью…

r_bash

Volume Mixer for Rotary Knob

Hi all, I've only been using Linux and bash for less than a year now and was wondering if i could get some feedback on a code i just finished. The script is for a rotary knob on my keyboard, that doesn't get much use. I really wanted it to be used for volume control but, the control it gave me out the box only controlled the main volume. So i made a script that gave me finer control over all active applications with the center button on the rotary knob cycling the apps and turning the knob adjusting the volume. Thanks

https://github.com/Thothermese/VolumeMixer

https://redd.it/1um1wf9
@r_bash

Читать полностью…

r_bash

Share your best custom shell commands/scripts!

I want to know what custom commands/scripts you guys made that you think made a diffrence to your experience with linux or saved alot of effort for you, or even for fun, anything, i just want to hear you guys' projects and ideas

https://redd.it/1ukrkq6
@r_bash

Читать полностью…

r_bash

Built a modular AWS CLI manager in Bash to learn shell scripting and AWS

https://redd.it/1ujfqx7
@r_bash

Читать полностью…

r_bash

OP tries to make terminal setups easier!
https://redd.it/1usgo18
@r_bash

Читать полностью…

r_bash

cleaned up problerly. This WILL break the script.
# You can almost certainly safely remove the seconds and minutes from the timestamp unless you are making several backups in an hour.


# ---------------------------


echo "Starting backup."


if [ "$LOCAL_BACKUP_LOCATION" != "none" ]; then
    tar -czf "${LOCALBACKUPLOCATION}"/"${BACKUPNAME}"${TIMESTAMP}.tar.gz "${SOURCE}"
    rclone copy "${LOCAL
BACKUPLOCATION}"/"${BACKUPNAME}"${TIMESTAMP}.tar.gz "${REMOTEBACKUPLOCATION}"


    echo "Cleaning up local backup directory."
    backups=$(rclone lsf "${LOCALBACKUPLOCATION}" --filter="+ "${BACKUPNAME}*"" --filter="- *" | sort -r)


    backup
control=0


    for backup in $backups; do
            ((backupcontrol++))
            if ((backup
control > $LOCALBACKUPAMOUNT)); then
            rm -rf "${LOCALBACKUPLOCATION}"/"${backup}"
            fi
    done
    echo "Old local backups removed."
fi


if [ "$LOCAL_BACKUP_LOCATION" == "none" ]; then
    tempdir=$(mktemp -d)
    tar -czf "${temp
dir}"/"${BACKUPNAME}"${TIMESTAMP}.tar.gz "${SOURCE}"
    rclone copy "${temp
dir}"/"${BACKUPNAME}"${TIMESTAMP}.tar.gz "${REMOTEBACKUPLOCATION}"
    rm -rf "${temp
dir}"
fi


echo "Backup Complete."


echo "Cleaning up remote backup directory."
backups=$(rclone lsf "${REMOTEBACKUPLOCATION}" --filter="+ ${BACKUPNAME}*" --filter="- *" | sort -r)


backup
control=0


for backup in $backups; do
        ((backupcontrol++))
        if ((backup
control > $REMOTEBACKUPAMOUNT)); then
                rclone deletefile "${REMOTEBACKUPLOCATION}"/"${backup}"
        fi
done
echo "Old remote backups removed."


echo "Full backup sequence complete. ${TIMESTAMP}"



https://redd.it/1uqrnj0
@r_bash

Читать полностью…

r_bash

RE: Overwrite shell interface

[Deleted Post](https://www.reddit.com/r/bash/comments/1uqq6z4/overwrite_shell_interface/)

>Hello! I’m still fairly new to Linux, and since I’m trying to use the terminal as my primary interface, I’ve been spending a lot of time working in Bash.
>
>After about a month of daily use, I’ve noticed a few things that make the experience less comfortable. Features like autocompletion, syntax highlighting, and autosuggestions are easy enough to add with plugins, but there’s one feature I haven’t been able to find anywhere.
>
>I’d love to have the command prompt stay fixed (sticky) at the bottom of the terminal, similar to the input box in a chat application.
>
>For example, when I scroll up to review previous output, I’d like the prompt to remain visible at the bottom instead of scrolling away with the rest of the terminal. If I start typing while I’m viewing older output, it shouldn’t automatically jump back to the latest line. The prompt should stay fixed until I explicitly choose to return to the bottom with ENTER key.
>
>The idea is similar to this Bash workaround.
>
>\`\`\`
>
>\# .bashrc
>
>\_prompt() {
>
>tput cup '$LINES' 0
>
>}
>
>PROMPT\_COMMAND="\_prompt;
$PROMPT\_COMMAND"
>
>\`\`\`
>
>This kind of interface would make it much easier to review previous output while continuing to type new commands, much like how chat interfaces work.
>
>Is it possible to achieve something like this in Bash?

EDIT: blockquotes got messed up, had to fix that

*Gaise! What are we* doing?

The OP has deleted their account! Probably out of disgust. Now, the answers to their queries were far too much tangential. I cannot fathom whether fellow sub-redditors ignored this person's intent or got subdued by the LLM - inflicted atrophy.

It is a \*\*brilliant\*\* solution to a stupefying problem. Using the \`PROMPT\_COMMAND\` hook to position the cursor at the bottom of the terminal viewport is remarkably nifty. OP should be crowned or somethin'.

I have already added this as a function in my run commands. In webdev terms it gives you a sticky prompt, with scrollback and "streaming" STDOUT. \*chuckles\*

Dear mods, please, we need to encourage such ideas. I urge fellow sub-redditors to not be apprehensive of such topics, not look down upon newbs and with utmost respect to LLMs and search engines, please consider the actual ideas and intuition behind that those ideas before commenting blatantly.

Here is a \`bash\` script for a \`tmux\` dual-pane oriented solution:

#!/usr/bin/env bash
set -euo pipefail

SOCKET_PATH="${1:-$HOME/.tmux/bashsplit.sock}"
SESSION="bashsplit"
LOG="${HOME}/bashsplit.log"

tmux -S "$SOCKET_PATH" kill-session -t "$SESSION" 2>/dev/null || true

tmux -S "$SOCKET_PATH" new-session -d -s "$SESSION" -n main
tmux -S "$SOCKET_PATH" split-window -t "$SESSION":0 -v

BASH_PANE="$(tmux -S "$SOCKET_PATH" list-panes -t "$SESSION":0 -F '#{pane_id}' | sed -n '1p')"
VIEW_PANE="$(tmux -S "$SOCKET_PATH" list-panes -t "$SESSION":0 -F '#{pane_id}' | sed -n '2p')"

tmux -S "$SOCKET_PATH" send-keys -t "$BASH_PANE" "bash" Enter
tmux -S "$SOCKET_PATH" pipe-pane -t "$BASH_PANE" -o "cat > '$LOG'"
tmux -S "$SOCKET_PATH" send-keys -t "$VIEW_PANE" "tail -f '$LOG'" Enter

tmux -S "$SOCKET_PATH" attach -t "$SESSION"

twimc

https://redd.it/1urb2t9
@r_bash

Читать полностью…

r_bash

bash playground with viz support
https://redd.it/1uqsuwc
@r_bash

Читать полностью…

r_bash

UPDATE: Google Calendar TUI written in Bash
https://redd.it/1uqu0ix
@r_bash

Читать полностью…

r_bash

I built a terminal ai agent in bash (~190 lines core loop)

Every agent framework I tried felt like a lot of machinery around what is, at its core, a loop: send messages, maybe run a tool, append the result, repeat. So I built one with no framework at all, just bash, jq, and curl. The core loop is \~190 lines; the whole thing (ten tools, permissions, skills, three providers) is \~1,200. Repo: https://github.com/aziz0x00/agent.sh

The design decisions that I think are interesting:

Tools are one file each, no registration. A tools/Foo.sh defines a TOOL_DEF JSON schema and two functions: PreFoo validates the model's args and builds a human-readable preview (a real diff for Edit/Write), then Foo executes. Drop a file in tools/, it's a tool.

Permissions are per-signature, not per-tool. Approval prompts show the preview (the actual diff, the actual command), and "always allow" whitelists that exact signature, not the whole tool. Read-only tools are pre-approved. --free bypasses everything when you're feeling brave.

Context is a JSON file you can just... edit. /state opens the exact request payload in $EDITOR mid-conversation; /continue sends whatever you saved. Delete a bloated tool result, rewrite the model's last answer, it's yours.

https://redd.it/1uqaikw
@r_bash

Читать полностью…

r_bash

bashmemo: search command notes and push them into Bash history
https://redd.it/1upsj5s
@r_bash

Читать полностью…

r_bash

Help with bash scripting executing apps with flags/arguments.

I'm new to linux bash scripting and running into an issue executing an app with arguments, when I run "steamosctl get-default-desktop-session" from a terminal the command runs fine, if I run the same command from a bash script I get the error "no such file or directory" the script has the shebang #!/bin/bash, set -x, steamosctl get-default-desktop-session.

Now if I run "steamosctl help" or "steamosctl -h" from the same script it works fine but for some reason adding arguments that contain multiple "-" minus signs in the argument the script gives the "no such file or directory" error, I've tried with other apps and also launching them with "sh" and "exec" with arguments containing multiple minus's and got the same error. My guess is I need to wrap the command or arguments some how so the arguments aren't interpreted as a path, I've done some research and tried several ways of writing the script as suggested in other topics with no success. Any help or suggestions would be greatly appreciated, Thanks in advance!

https://redd.it/1uploo9
@r_bash

Читать полностью…

r_bash

İ made with aliases on docker:

İ made shell with aliases on docker:
https://github.com/selfitis/DockerOS-S/

https://redd.it/1uoudnc
@r_bash

Читать полностью…

r_bash

[VinMail] Bash-ing out emails: built a Bash-based terminal mail manager for multiple email accounts

https://redd.it/1un5gl6
@r_bash

Читать полностью…

r_bash

What is your notification system for long running comands

Hi I usually do large backups that take time and need a notification system that notify me when is done.

Ideally I would like a notification on my phone but any alternative is ok.

Should I set up an email or there is something that is less painful?

https://redd.it/1umhmfg
@r_bash

Читать полностью…

r_bash

Beginner here — A personal backup script, would love feedback

Not an experienced programmer. I wrote a Bash script to back up my files to an external drive, Learnt a lot doing that, and I'm posting here because I'd like more experienced people to look at it and tell me what I'm still missing.

The basic idea: it uses rsync with --link-dest to make daily snapshot backups. Each backup looks like a full copy of your files, but files that haven't changed are hard-linked instead of copied again, so it doesn't waste disk space. Something similar to "Time Machine".

Repo is here if anyone wants to look at the code or try to break it: https://github.com/UFpondiboy/linux-snapshot-backup

Any feedback — big picture or nitpicky — is genuinely welcome. I'd rather find out what's wrong now than trust it blindly.

https://redd.it/1um58zt
@r_bash

Читать полностью…

r_bash

Intellisense autocompletions inside of Bash

https://redd.it/1ukyy8k
@r_bash

Читать полностью…

r_bash

Script to replicate the copy/move behavior in typical file managers (prompt to overwrite?)

AFAIK in file managers in Windows/Linux, they have the same convenient behavior where if you copy one folder into another folder of the same name and there's a conflict (e.g. a folder of the same name already exists), instead of aborting, it prompts to "overwrite" (merge the contents of the folder), recursively. If any of the files result in conflict (e.g. a file of the same name already exists), it prompts the user whether they want to overwrite, letting the user know which is larger and which is newer.

The above is useful if e.g. you abort the copy/move progress half and then want to resume at a later point.

------

Does anyone have a similar script they can share? How would such a script be implemented? I know rsync can do something similar. With these file managers, they seem to update one file at a time, e.g. when a file is successfully moved during the process, the source file is removed. With rsync, a file gets removed after rsync finishes(?) which is not as intuitive because it does not reflect the latest state of the progress.


Implementation-wise, is it as simple as rsyncing each file one at a time, checking for potential overwrites before rsync and comparing the file size and modification time of files ith stat, then prompting the user if there are conflicts, else rsync that file? Is there a way to do this more efficiently (or ideas for a better UX)? Can rsync or similar tools handle more of this?

Any tips are much appreciated.

https://redd.it/1ujo7vc
@r_bash

Читать полностью…

r_bash

I am Working on an Artix install Script

Would love some feedback

https://paste.myst.rs/gbet27pm

https://redd.it/1ujdeat
@r_bash

Читать полностью…
Subscribe to a channel