r_bash | Unsorted

Telegram-канал r_bash - r_bash

46

Credits: @r_channels & @reddit2telegram

Subscribe to a channel

r_bash

Started learning Linux from zero , just hit file permissions and my brain is melting (in a good way) lol 🐧
https://redd.it/1tfkfyi
@r_bash

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

r_bash

Bash Scripting vs. Python

For those of you who also write scripts in Python or another language besides Bash, How do you decide when to write a script in Python vs. a script in Bash? I'm trying to be economical with my study time, because if I spend a lot of time learning some limited use functionality in one language, I could have used that time to learn a more general use functionality in another language. Here's an example: I've spent a fair amount of time learning awk, but I've never been great at using it, and sometimes I think that I should have just used Path and regex objects in Python, instead.

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

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

r_bash

Is it OK if I use an appimage-browser like default browser?

Hi, I am using a browser from an appimage. Could I use it like browser by default from bash?

I did the commands before for change one browser by another... maybe I can use these steeps again and change to new browser-appimage like default...

PS: what is the meaning of "submission" flag here in this sub?

Thank you and Regards!

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

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

r_bash

Building a multi-agent system from scratch: 50 lines of bash + git
https://en.andros.dev/blog/ed26ea98/building-a-multi-agent-system-from-scratch-50-lines-of-bash-git/

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

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

r_bash

i made a tool zed

zed

what is zed?

zed is a tool where you can do these stuff listed:
1. overwrite, overwrite is basically you enter a whole new text and the program writes the text to the file

2. linewrite, linewrite is basically you select the line in the file, and you enter the text you want to change, and the program changes the file line with the chosen text!

3. read, reads any file you throw at it

4. delete, self explanatory

5. delline, delete a specific line in a specific file


I WANT THE SOURCE CODE NOW:

ok chill, heres the source code link don't worry you can do whatever to it **https://gitlab.com/giorgich11/zed/-/blob/main/source.sh?ref\_type=heads**


oh... i am to lazy i want the compiled version:
sure go to **https://gitlab.com/giorgich11/zed/-/raw/main/zed?ref\_type=heads**


i want to install this:

okay, when you get the binary or just the .sh just do:

chmod +x zed


if you have the binary you can do 'mv zed /usr/bin/zed' requires sudo! if you don't want to just do whatever to it


I DON'T LIKE THIS I HATE IT:

if you hate it, just leave this post alone please, i beg...

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

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

r_bash

I MADE A TOOL zed

zed

welcome:
hello, this is zed. what is zed? zed is basically the one that your girlfriend says to not worry about, but we know you should worry about :3
\---
\#what the hell does it do?
basically you can write,read,change lines,delete fles, delete lines. in 1 tool, in any shit linux distro you have, yes arch users you can use this if you hate vim to your very CORE
\---
hey bombastic, how do i install yo tool?
don't ever call me bombastic, also heres the link https://gitlab.com/giorgich11/zed/-/raw/main/zed?ref\_type=heads
\---
yo, i got it but where the hell do i put it ???????
i got you do this, like a good boy/girl:
\# change zed to whatever freak location your binary folder is
sudo mv zed /usr/bin/zed
\# ...
done! enjoy or else...
\---
by giorgich11, made by giorgich11, licensed by giorgich11, license by giorgich11. lol, everything i made ;(zed

welcome:
hello, this is zed. what is zed? zed is basically the one that your girlfriend says to not worry about, but we know you should worry about :3
\---
what the hell does it do?
basically you can write,read,change lines,delete fles, delete lines. in 1 tool, in any shit linux distro you have, yes arch users you can use this if you hate vim to your very CORE
\---
hey bombastic, how do i install yo tool?
don't ever call me bombastic, also heres the link https://gitlab.com/giorgich11/zed/-/raw/main/zed?ref\_type=heads
\---
yo, i got it but where the hell do i put it ???????
i got you do this, like a good boy/girl:
\# change zed to whatever freak location your binary folder is
sudo mv zed usr/bin/zed
\# ...
done! enjoy or else...
\---
by giorgich11, made by giorgich11, licensed by giorgich11, license by giorgich11. lol, everything i made ;(

(repo is at https://gitlab.com/giorgich11/zed/-/tree/main )

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

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

r_bash

Can someone explain the real-world usage of /etc/profile, profile.d, and bashrc?
/r/linuxupskillchallenge/comments/1tbwqu5/can_someone_explain_the_realworld_usage_of/

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

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

r_bash

Probably unnecessarily scared of wget's spider function

Trying to find a way to have wget check (maybe in the background?) the size of a website before I attempt to archive it. So if I wanted to run ````wget -m -k https://example-web.site````, I want a script that'll guesstimate how much space it'll take. I found [this](https://stackoverflow.com/a/6986163), with [this](https://github.com/izkreny/website-size/blob/master/website-size.sh) as the main script; dunno why you'd install the script when you can just copy-paste it into an executable file, but maybe I'm missing something.

So I was about to do that, when I came across [this](https://unix.stackexchange.com/a/743176):

> ...````--spider```` option i think unexpectedly deletes all files on disk and so my download of many Gigabytes and thousands of files was being accidentally deleted by this feature. so i run the command in a temporary directory to stop this behavior from accidently deleting files.

And now I'm petrified. Please advise!

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

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

r_bash

How to make an alias has completion support?

Im using archlinux, i have in my .bashrc alias pacin="sudo pacman -S" and alias pacrem="sudo pacman -Rns" how to make when i type pacin or pacrem and hit tab its shows completion?

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

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

r_bash

Is there a way to capture keystrokes even though you're not at a prompt?

I'm spending a lot of time on the terminal, (/dev/ttyX, framebuffer, no X/wayland).

I have made some key binds to control screen brightness, set the font size, volume up/down, limit CPU clock frequency, ...

Problem is, it only works if I'm at a Bash prompt and not if a program is open (mc, vim, chawan, ...)

If eg, I've got vim open, I need to either find a terminal that has a Bash prompt open or exit vim before I can change the screen brightness.

My problem would be fixed if there would be some kind of a way for bash to capture certain key sequences even though a program is running.

Is that possible at all?

thanks!

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

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

r_bash

I want start using linux , best way to learn bash scripts ?

I’m thinking seriously about switching to Linux. My idea is to first learn Bash scripting, try making some simple scripts, and at the same time start learning more about Linux distros and how the system works.

I feel like learning Bash first could help me understand Linux better instead of just using it casually.

What’s the best way to learn Bash scripting as a beginner?

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

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

r_bash

Are you supposed to return 0 or 1 or anything from an EXIT trap handler?

#!/usr/bin/env bash

function handle_exit() {
validate_args_count 4 "$#" "${FUNCNAME[0]}" || return 1

local -r exit_code="$1"

local -r enable_logging="${2:-true}"

local -r archive_tar_path="$3"
local -r raw_dump_path="$4"
shift 4

validate_non_empty_arg "archive_tar_path" "${archive_tar_path}" "${FUNCNAME[0]}" || return 1
validate_non_empty_arg "enable_logging" "${enable_logging}" "${FUNCNAME[0]}" || return 1
validate_non_empty_arg "exit_code" "${exit_code}" "${FUNCNAME[0]}" || return 1
validate_non_empty_arg "raw_dump_path" "${raw_dump_path}" "${FUNCNAME[0]}" || return 1

validate_boolean_arg "enable_logging" "${enable_logging}" "${FUNCNAME[0]}" || return 1
validate_integer_arg "exit_code" "${exit_code}" "${FUNCNAME[0]}" || return 1

# Clean up the generated directory and the tar.gz file if they exist, since they are intermediate files and should not be kept after the dump process is completed
# Technically they should exist only on failure, since on success they should be removed by the tar and brotli commands, but we will clean them up just in case
[[ -d "${raw_dump_path}" ]] && rm -rf "${raw_dump_path}"
[[ -f "${archive_tar_path}" ]] && rm -f "${archive_tar_path}"

if [[ "${exit_code}" -ne 0 ]]; then
log_error "dump process failed with exit_code: %d\n" "${exit_code}"
else
[[ "${enable_logging}" = true ]] && log_info "dump process completed successfully with exit_code: %d\n" "${exit_code}"
fi
}

function main() {
// ... other lines
trap "handle_exit \$? \"${enable_logging}\" \"${archive_tar_path}\" \"${raw_dump_path}\"" EXIT
// ... other lines
}

- I did ask AI before anyone points out. Some of them say you should return 0 for good and 1 for error conditions. Others say it is not a good idea to return exit codes from a trap handler. Hence, asking the human experts here?
- You got an EXIT trap handler and something goes wrong inside it...
- Are you supposed to return 0 or 1 from it or should you just pretend nothing happened?



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

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

r_bash

What should I do to make my code more readable?

Hello
I am starting with bash scripting and I am creating a script to automate the configuration of my system, but the bash syntax is not very readable and the more I write the more confusing it becomes for me to read and I wanted to know what improvements I could make to my script to make it more readable.

#!/usr/bin/env bash
sudo xbps-install -u xbps
sudo xbps-install -Su
sudo xbps-install -Sy xarchiver xfce4-plugins thunar-archive-plugin \
lua ncurses-term uv git \
fzf xclip tar ripgrep \
xset nodejs tmux alacritty \
xdg-utils keepassxc neovim unzip \
wget curl mpv

sudo uv tool install ruff ty

sudo xbps-install -Sy lua-language-server StyLua

cat >> .bashrc << "EOF"

trash() {
mv "$@" ~/.trash/
}

xset b off

if command -v tmux &>/dev/null && [ -z "$TMUX" ]; then
tmux attach-session -t default || tmux new-session -s default
fi
EOF

# Install Icons
wget -qO- https://git.io/papirus-icon-theme-install | sh

# Install Fonts
FONTS_PATH="$HOME/.local/share/fonts"

mkdir -p "$FONTS_PATH"

wget -O "$FONTS_PATH"/JetBrainsMono.zip https://download.jetbrains.com/fonts/JetBrainsMono-2.304.zip
unzip "$FONTS_PATH"/JetBrainsMono.zip

mv "$FONTS_PATH"/JetBrainsMono/fonts/variable/* "$FONTS_PATH"
rm -rf "$FONTS_PATH"/JetBrainsMono/ "$FONTS_PATH"/JetBrainsMono.zip

fc-cache -fv "$FONTS_PATH"

clear

echo "configuration completed"

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

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

r_bash

tfetch
https://redd.it/1t7tbj7
@r_bash

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

r_bash

A simple Bash wrapper for marking AI-assisted Git commits

I wrote a tiny Bash helper called with_ai that wraps tools like codex or claude, preserves the human author, and appends a marker like [AI:Codex] to commits created by that tool.

It’s basically a low-friction way to make AI-assisted lines stand out later in git blame without obscuring the human who is accountable for them. It also puts tool info into a $AI_TOOL environment variable so it's available to other programs.

There's also a blog post with a bit more context here: Blaming the Agent.

I'd love any feedback on the Bash approach, including cleaner wrapping patterns or obvious portability issues I might be missing.

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

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

r_bash

play music using youtube-dl
https://redd.it/1tfiw8k
@r_bash

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

r_bash

Improving the "command failed with exit 129" errors; check out my project: dexit - "Decode Exit".
https://github.com/eatnumber1/dexit

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

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

r_bash

i made a new tool imager

\-imager-

what the hell is it?:

it is a tool that gives your more time to spend with your imaginary girlfriend, basically you spend 15-20 minutes figuring out the FUCKING syntax of appimage tools, but imager is the guy that your imaginary girlfriend said to 'not worry about'

what does the tool do:

you enter the name, you select the location of a file, example binary or a shell script,select the image, or you can just skip, pick the output directory. and done you have more time with your imaginary girlfriend, YAY

I WANT THE SOURCE CODE NOW NOW NOW NOW:

chill, here https://gitlab.com/giorgich11/imager/-/blob/main/sourcecode.sh

i am lazy give me the appimage link:

sure here https://gitlab.com/giorgich11/imager/-/raw/main/imager.AppImage

if you don't like this tool, don't flame it please, i am a new developer😢

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

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

r_bash

Sync Wallpaper with Terminator background image?
/r/xfce/comments/1tddprn/sync_wallpaper_with_terminator_background_image/

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

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

r_bash

Bash history not staying after restarts (Synology NAS)
/r/synologynas/comments/1tcyob8/bash_history_not_staying_after_restarts/

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

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

r_bash

Apprendre à utiliser mon terminal

Hello,

Utilisateur de mac de longue date,

Profil de crea bricoleur mais pas dev, je souhaite comprendre un peu mieux l'utilisation du terminal et ses fonctions.

Comment puis je me former en français assez simplement ?

Merci.

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

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

r_bash

Show r/bash: Ano – bash, Claude Code and team chat in one window
http://ano.chat

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

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

r_bash

Bash commands fore files system I learned as a beginner — feedback welcome!
https://redd.it/1tbbfxy
@r_bash

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

r_bash

What is a command for "execute" an appimage? I'd like to put a flag for mute silent quiet load without errors on loading appimage

**Hi**, I'd like to write an alias for open an app with the flag -mute

today I am using this alias:

alias He='~/Documentos/helium/helium-0.10.7.1-x86_64.AppImage'

what will be the command where I can put a flag for load in silent quiet?

*Thank you and Regards!*

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

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

r_bash

Beginner roadmap for IT networking and Linux, is this good?

I found my roadmap as beginner It networking student .

Learn Linux basics
Learn Bash
Learn Python
Learn networking fundamentals

What do you think guys ?

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

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

r_bash

OC I made a minimal fuzzel-based wallpaper picker that works on any WM fuzz-wall

Hey everyone,

I wrote a small POSIX shell script called fuzz-wall that lets you pick wallpapers interactively using fuzzel's dmenu mode. I wanted something dead simple that worked regardless of which WM or wallpaper setter I was using, so I built it.

What it does

You run fuzz-wall, fuzzel opens with a list of your wallpapers, you pick one, it gets applied. ESC to exit. No config file, no GUI, no bloat.

Supported wallpaper setters

\- swaybg (Sway)

\- swww (Hyprland, with fade transitions)

\- hyprpaper (Hyprland)

\- feh (i3, bspwm, dwm)

\- nitrogen (openbox, bspwm)

\- xwallpaper (general purpose)

The script auto-detects which one you have installed. On Wayland it prefers Wayland-native setters, on X11 it falls back to X11 setters.

Configuration

There is only one option, the wallpaper directory. It defaults to \~/Pictures/wallpapers and can be overridden:

FUZZ_WALL_DIR=\~/Pictures/walls fuzz-wall

You can bind it to a key in your WM config:

\# Hyprland

bind = $mod, W, exec, fuzz-wall

\# Sway

bindsym $mod+w exec fuzz-wall

\# i3

bindsym $mod+w exec fuzz-wall

Install

It is on the AUR:

```paru -S fuzz-wall

yay -S fuzz-wall```

Or clone manually and copy to \~/.local/bin.

Source: https://github.com/youngcoder45/fuzz-wall

AUR: https://aur.archlinux.org/packages/fuzz-wall

This is an AUR package. Happy to hear feedback, bug reports, or suggestions for new wallpaper setters to support. If your WM or setter is not listed, open an issue and I will add it.

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

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

r_bash

Bash script to cull syslog.x files when disk is low

this is for scenario i have where server are used a log fowarders, its the sole job of the server spool logs that get pushed upstream, does the logic look ok, any gotchas you can see, i made a check for locks on syslog.1 as i don't know if logrotate or syslog could be doing something with the file.



#!/bin/bash

# cleanup_syslog.sh

# Checks free disk space on the partition holding /var/log.

# If free space is below 10% OR below 3 GB, deletes the oldest

# syslog archive file in /var/log.

LOG_DIR="/var/log"

THRESHOLD_PERCENT=10

THRESHOLD_BYTES=$((3 * 1024 * 1024 * 1024)) # 3 GB in bytes



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

# Get filesystem stats for the partition that holds /var/log

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

# df output (POSIX): Filesystem 1K-blocks

read -r fs total_kb used_kb avail_kb use_pct mount \

< <(df -P "$LOG_DIR" | tail -1)



avail_bytes=$(( avail_kb * 1024 ))

total_bytes=$(( total_kb * 1024 ))



# Calculate free percentage

if [[ "$total_bytes" -eq 0 ]]; then

echo "ERROR: Could not determine total disk size for $LOG_DIR" >&2

exit 1

fi



free_pct=$(( avail_bytes * 100 / total_bytes ))



echo "Partition : $fs (mounted at $mount)"

echo "Total : $(( total_bytes / 1024 / 1024 / 1024 )) GB"

echo "Free : $(( avail_bytes / 1024 / 1024 / 1024 )) GB ($free_pct%)"

echo "Thresholds: < ${THRESHOLD_PERCENT}% OR < $(( THRESHOLD_BYTES / 1024 / 1024 / 1024 )) GB"

echo ""



# Check whether cleanup is needed

needs_cleanup=0



if [[ "$free_pct" -lt "$THRESHOLD_PERCENT" ]]; then

echo "WARNING: Free space is ${free_pct}% which is below the ${THRESHOLD_PERCENT}% threshold."

needs_cleanup=1

fi



if [[ "$avail_bytes" -lt "$THRESHOLD_BYTES" ]]; then

echo "WARNING: Free space is $(( avail_bytes / 1024 / 1024 )) MB which is below the 3 GB threshold."

needs_cleanup=1

fi



if [[ "$needs_cleanup" -eq 0 ]]; then

echo "Disk space is OK. No cleanup needed."

exit 0

fi



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

# Find the oldest syslog archive and delete it

# Syslog archives match: syslog.*.gz or syslog.* (rotated by logrotate)

# Use ls -t (newest first) and take the last entry = oldest file.

# -1 ensures one file per line; grep narrows to syslog archives only.

oldest_archive=$(

ls -1t "$LOG_DIR"/syslog.* 2>/dev/null \

| grep -E 'syslog\.[0-9]' \

| tail -1

)



if [[ -z "$oldest_archive" ]]; then

echo "No syslog archive files found in $LOG_DIR to delete."

exit 0

fi



if fuser "$oldest_archive" > /dev/null 2>&1; then

echo "File is in use, skipping"

else



echo "Deleting oldest syslog archive: $oldest_archive"

rm -f "$oldest_archive"

fi



if [[ $? -eq 0 ]]; then

echo "Successfully deleted: $oldest_archive"

else

echo "ERROR: Failed to delete $oldest_archive" >&2

exit 1

fi



exit 0





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

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

r_bash

cht.sh is offline

Hi,

This post is in hopes the owners(or someone who knows) sees it. I know of no way to let them know.

Thanks.

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

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

r_bash

Run vim in command substitution?

I have a script that launches terminal on some temp file so I can edit it with vim bindings then on quit, prints the content and removes the temp file. I want to assign the output to a variable--is this possible? When I attempt this it vim doesn't run because it's inside the command substitution(?).

Do I need to workaround this by providing an option for the script to not delete the temp file and handle it manually after by the other script running it after getting its contents?

P.S. Unrelated, but I have a lua plugin for mpv which runs this shell script to launch a new terminal instance with vim running. If I close mpv, this new terminal instance with vim still persists. I expect this to close since it's a child(?) process and the contents of the script as well as running the script itself are all done in the foreground. I came across a stackoverflow about something to do with a grandparent process that might contribute to this behavior where the child process doesn't terminate (not sure if it's related) and was wondering if anyone has a guess how to deal with this.

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

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

r_bash

fold, a directory of text files into one markdown file (and back)

ok so small thing i wrote (full disclosure: my project) because i was sick of zipping folders just to share a few files in chat. fold takes a directory of text files and packs them into one self-describing markdown file. unfold reverses it.

two commands:

fold ./notes              # → notes.folded.md
unfold ./notes.folded.md # → ./notes/


the .folded.md is plain markdown. open it in any editor, read it normally. file sections inside have html-comment delimiters with the original paths so unfold can rebuild the tree.

how it differs from tar/zip:

- its text. you can scroll through a .folded.md in any editor and skim the contents. tar/zip you have to extract first.
- artifacts are pasteable. into a chat, a gist, an issue. that was the actual point for me.
- for binaries, use tar. fold only handles text.

bash only right now. install:

curl -sSLf https://fold.dom.vin/skill | bash -s ~/tools


free, source on github, linked from the homepage if you want to read the script before running it.

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

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