r_bash – Telegram
how do you toogle capslock using the cmd setxkbmap?

Hi, I'd like to add an alias for toogle caps. in this way I will can reverse the cmd:

alias M='setxkbmap -option caps:escape'

and put in work the capslock key again doing again capslock and not more escape.

Thank you and regards!

https://redd.it/1mrsu2m
@r_bash
I created an Fortune 500 enterprise wide product utilizing -only- BASH noscript

Finally some utility from learning BASH. Gonna be honest though, I used AI to remind me syntax. Its been a while since I was a linux admin.

Its an alerting solution for business functions that need immediate support.

That is all. Just feels good to utilize a closet skill.



https://redd.it/1mt89q2
@r_bash
Meet Shownamer | A New Cli Tool to batch rename TV Show files 🎉
https://redd.it/1muc9e4
@r_bash
posting my setup noscript for backup/revert/log

just put this in a noscript called setup, then run it using . ./setup (make sure you are inside of your target new directory for your project): Then you have a nice menu to get to your directory setup. The internal directories will be named by ranked date-time.

I have been using this setup for my work in JavaScript. I could be adaptable to other workflows with small total filesize. There is no compression happening.

The purpose of this type of backup/revert situation is to be able to very freely experiment with the code.

I have been thinking, just now about severing the BASH noscripts from my project and setting them up in their own repo with an empty example directory structure.

Let me know what you think about it.

You end up with a menu system in the home directory. The menu will be accessible by '. ./menu' and then the directory name.

If you choose directory names with a unique first letter, then you are 'TABBING' you way in.


`
mkdir work;


cd work;


echo 'cd $(cat recent
directory);' > resume;
chmod 755 resume;

echo "cd work; . ./resume;" > ../start;
chmod 755 ../start;
echo "cd '$(pwd)'; . ./resume;" > ~/menu$(echo $(pwd | sed 's/\/work$//g' | sed 's/^.*\///g'));
chmod 755 ~/menu
$(echo $(pwd | sed 's/\/work$//g' | sed 's/^.\///g'));
echo "cd '$(pwd)'; . ./resume; explorer .;" > ~/menux_$(echo $(pwd | sed 's/\/work$//g' | sed 's/^.
\///g'));
chmod 755 ~/menux$(echo $(pwd | sed 's/\/work$//g' | sed 's/^.*\///g'));

mkdir 2024
06June30Sunday024053;
echo './work/202406June30Sunday024406' > 202406June30Sunday024053/.precedingdirectory;
mkdir 2024
06June30Sunday024406;
echo './work/202406June30Sunday024406' > recentdirectory;
echo './work/202406June30Sunday024053' > 202406June30Sunday024406/.precedingdirectory;

cd 2024
06June30Sunday024406/;

echo 'cd $(cat .precedingdirectory); mv precedingdirectory .precedingdirectory; mv succeedingdirectory succeedingdirectoryreverted; . ./backup; rm succeedingdirectoryreverted;' > revert;
chmod 755 revert;

echo "mv .precedingdirectory precedingdirectory; echo '../'\$(date +%Y%m%B%d%A%H%M%S)'/' > succeedingdirectory; mkdir \$(echo \$(cat succeedingdirectory)); mv precedingdirectory tmp; echo \$(pwd) > precedingdirectory; cp -r * \$(echo \$(cat succeedingdirectory)); mv tmp precedingdirectory; cd \$(echo \$(cat succeedingdirectory)); rm tmp; rm succeedingdirectory; echo \$(pwd) > ../recentdirectory; mv precedingdirectory .precedingdirectory;" > backup;
chmod 755 backup;

echo 'echo >> ../logfile;' >> log;
echo 'echo >> ../logfile;' >> log;
echo 'echo >> ../logfile;' >> log;
echo "echo ' # # # # # # # # # # # # # # #' >> ../logfile;" >> log;
echo "echo ' # #' >> ../logfile;" >> log;
echo "echo ' # '\$(date +'%Y/%m/%d %H:%M:%S')' #' >> ../logfile;" >> log;
echo "echo ' # #' >> ../logfile;" >> log;
echo "echo ' # # # # # # # # # # # # # # #' >> ../logfile;" >> log;
echo "echo >> ../logfile;" >> log;
echo 'echo $(pwd) >> ../logfile;' >> log;
echo 'echo >> ../logfile;' >> log;
echo 'echo >> ../logfile;' >> log;
echo 'vi + ../logfile;' >> log;
chmod 755 log;

. ./backup;

echo ' ' > ../logfile;
echo ' # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # Assalamu Alaikum, # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # To get back into the most recent directory # ' >> ../logfile;
echo ' # use the following commands at the prompt: # ' >> ../logfile;
echo ' #
posting my setup noscript for backup/revert/log

just put this in a noscript called setup, then run it using . ./setup (make sure you are inside of your target new directory for your project): Then you have a nice menu to get to your directory setup. The internal directories will be named by ranked date-time.

I have been using this setup for my work in JavaScript. I could be adaptable to other workflows with small total filesize. There is no compression happening.

The purpose of this type of backup/revert situation is to be able to very freely experiment with the code.

I have been thinking, just now about severing the BASH noscripts from my project and setting them up in their own repo with an empty example directory structure.

Let me know what you think about it.

You end up with a menu system in the home directory. The menu will be accessible by '. ./menu_' and then the directory name.

If you choose directory names with a unique first letter, then you are 'TABBING' you way in.


`
mkdir work;


cd work;


echo 'cd $(cat recent_directory);' > resume;
chmod 755 resume;

echo "cd work; . ./resume;" > ../start;
chmod 755 ../start;
echo "cd '$(pwd)'; . ./resume;" > ~/menu_$(echo $(pwd | sed 's/\/work$//g' | sed 's/^.*\///g'));
chmod 755 ~/menu_$(echo $(pwd | sed 's/\/work$//g' | sed 's/^.*\///g'));
echo "cd '$(pwd)'; . ./resume; explorer .;" > ~/menux_$(echo $(pwd | sed 's/\/work$//g' | sed 's/^.*\///g'));
chmod 755 ~/menux_$(echo $(pwd | sed 's/\/work$//g' | sed 's/^.*\///g'));

mkdir 2024_06_June_30_Sunday_02_40_53;
echo './work/2024_06_June_30_Sunday_02_44_06' > 2024_06_June_30_Sunday_02_40_53/.preceding_directory;
mkdir 2024_06_June_30_Sunday_02_44_06;
echo './work/2024_06_June_30_Sunday_02_44_06' > recent_directory;
echo './work/2024_06_June_30_Sunday_02_40_53' > 2024_06_June_30_Sunday_02_44_06/.preceding_directory;

cd 2024_06_June_30_Sunday_02_44_06/;

echo 'cd $(cat .preceding_directory); mv preceding_directory .preceding_directory; mv succeeding_directory succeeding_directory_reverted; . ./backup; rm succeeding_directory_reverted;' > revert;
chmod 755 revert;

echo "mv .preceding_directory preceding_directory; echo '../'\$(date +%Y_%m_%B_%d_%A_%H_%M_%S)'/' > succeeding_directory; mkdir \$(echo \$(cat succeeding_directory)); mv preceding_directory tmp; echo \$(pwd) > preceding_directory; cp -r * \$(echo \$(cat succeeding_directory)); mv tmp preceding_directory; cd \$(echo \$(cat succeeding_directory)); rm tmp; rm succeeding_directory; echo \$(pwd) > ../recent_directory; mv preceding_directory .preceding_directory;" > backup;
chmod 755 backup;

echo 'echo >> ../logfile;' >> log;
echo 'echo >> ../logfile;' >> log;
echo 'echo >> ../logfile;' >> log;
echo "echo ' # # # # # # # # # # # # # # #' >> ../logfile;" >> log;
echo "echo ' # #' >> ../logfile;" >> log;
echo "echo ' # '\$(date +'%Y/%m/%d %H:%M:%S')' #' >> ../logfile;" >> log;
echo "echo ' # #' >> ../logfile;" >> log;
echo "echo ' # # # # # # # # # # # # # # #' >> ../logfile;" >> log;
echo "echo >> ../logfile;" >> log;
echo 'echo $(pwd) >> ../logfile;' >> log;
echo 'echo >> ../logfile;' >> log;
echo 'echo >> ../logfile;' >> log;
echo 'vi + ../logfile;' >> log;
chmod 755 log;

. ./backup;

echo ' ' > ../logfile;
echo ' # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # Assalamu Alaikum, # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # To get back into the most recent directory # ' >> ../logfile;
echo ' # use the following commands at the prompt: # ' >> ../logfile;
echo ' #
# ' >> ../logfile;
echo ' # From the BASH startup directory press this: # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # . ./menu_ then press <tab> # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # cd ~ will return to the # ' >> ../logfile;
echo ' # starting directory. # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # From /name/ directory press this: # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # . ./start # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # From /name/work/ directory use this: # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # . ./resume # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # Using the backup and revert noscripts is easy, # ' >> ../logfile;
echo ' # just press these from within the directory # ' >> ../logfile;
echo ' # system that has been prepared: # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # . ./backup (use before experimenting) # ' >> ../logfile;
echo ' # . ./revert (use to restore previous ) # ' >> ../logfile;
echo ' # . ./log (use this to make notes ) # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ' >> ../logfile;
cat ../logfile;
echo ' # # ' >> ../logfile;
echo ' # BEGINNING OF LOGFILE # ' >> ../logfile;
echo ' # # ' >> ../logfile;
echo ' # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ' >> ../logfile;
. ./log;
`

Best wishes,

-dckimGUY

https://redd.it/1mufr6p
@r_bash
Recaller: A fast command-line tool to recall your bash history with absolute precision & instant command documentation

Hi, community, we are open-sourcing a Go terminal application called **Recaller** that fetches command history based on your actions.

https://github.com/cybrota/recaller

Recaller suggests shell history (bash) based on recency & frequency making things more relevant for you. It also provides documentation to various types of commands (K8s, Docker, Linux man pages, AWS CLI etc.) instantly for options reference and learning.

Combined with a fuzzer like `fzf`, curated history shows up right in the shell. App is < 5 MB in size, and runs locally. The tool uses optimization techniques (AVL-trees & Caching) to achieve its lookup speeds.

https://redd.it/1mukkjp
@r_bash
Aliasses yes or No?

Hi! I was thinking Is it better to use or not alias?
They accelerate the writing of commands but makes us forget the original, complete, long command.
I think: And... if we have to be on another PC without those alias put in the ~/.bashrc, how do we remember the original command?
Thanks and Regards!

https://redd.it/1mvcswc
@r_bash
Why my PS1 is acting like this ?

After configuring my .bashrc, it looks like this:

➜  ~daniel~  git:(  )


But when I start using it, this happens:

aaaaaaniel~  git:(  )  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa


For this example, I decided to type only one letter to observe the behavior. What happens is that when the text I'm typing reaches a point on the screen that isn't even the end of the line, it starts to overwrite the PS1 on the same line. This is probably caused by a miscalculation of the space, I guess.

I don't get it — maybe a skill issue on my part made me misunderstand this, but here is my .bashrc. If anyone knows how to fix that:

_format_dir() {
original_user="${SUDO_USER:-$USER}"
original_home=$(getent passwd "${original_user}" | cut -d: -f6)
user_tag="~${original_user}~"

if [[ "$PWD" == "$original_home" ]]; then
echo -n "$user_tag"
elif [[ "$PWD" == "$original_home/"* ]]; then
rel_path="${PWD#$original_home/}"
IFS='/' read -r -a parts <<< "${rel_path}"
part_count="${#parts[@]}"

if (( part_count <= 2 )); then
echo -n "~/$rel_path"
else
echo -n "~/.../${parts[-1]}"
fi
else
echo -n "$PWD"
fi
}

get_git_info() {
if git rev-parse --git-dir > /dev/null 2>&1; then
branch=$(git branch --show-current 2>/dev/null)
if [ -n "$branch" ]; then
printf "\ue0a0 $branch"
else
printf "󱈸󰋖"
fi
else
printf "󱈸󰋖"
fi
}

if [[ $EUID -eq 0 ]]; then
export PS1="\n\[\e[1m\]\[\033[38;2;194;114;126m\]➜\[\e[0m\] \[$(tput sgr0)\] \[$(tput bold)\]\[\033[38;2;220;124;126m\]root\[$(tput sgr0)\] in \[$(tput bold)\]\[\033[38;2;72;205;232m\]\$(_format_dir)\[$(tput sgr0)\] \[\001\033[1m\033[38;2;66;99;105m\002\]git:(\[\033[38;2;194;114;126m\]\$(get_git_info)\[\001\033[38;2;66;99;105m\002\])\001\033[0m\002\033[22m "
else
export PS1="\n\[\e[1m\]\[\033[38;2;194;114;126m\]➜\[\e[0m\] \[$(tput sgr0)\] \[$(tput bold)\]\[\033[38;2;72;205;232m\]\$(_format_dir)\[$(tput sgr0)\] \[\001\033[1m\033[38;2;66;99;105m\002\]git:(\[\033[38;2;194;114;126m\]\$(get_git_info)\[\001\033[38;2;66;99;105m\002\])\001\033[0m\002\033[22m "
fi


I isolated some functions, and what I understand is that the get_git_info() function is the problem. I can't make it work properly.




https://redd.it/1mveqbg
@r_bash
Does anyone use local uncompressed backup? Git-everything-always? Or layered approach?

I'm just wondering... I am new to Git, about three weeks in. Does anyone out there use a local uncompressed backup system for fast backups and reversions? Or is the Git-everything philosophy the best route?

I have been reading up on it and it seems like there is something useful about having a local reversion system outside of Git. Something simpler. Something closer to a 'layered approach'.

Write me a line.

Thanks,

-dckimGUY

https://redd.it/1mw2ujo
@r_bash
Bash Librewolf Installation

Github Repository: InstallScripts

Created a bash noscript that supports all the distros that librewolf ( privacy focused fork of firefox ) supports and I finished the noscript just need to test it on the other distros using docker, so far Debian, fedora and opensuse were successful.

https://redd.it/1mwsvo4
@r_bash
Prompt that repeats until user give correct input ( while loop )

Here's is an example of the code

while true; do
read -p "Would you like to continue? (yes/no): " yesorno # Outputs a Prompt
if "$yes_or_no" == "yes" ; then
echo "Continuing with the noscript..."
elif "$yes_or_no" == "no" ; then
echo "Not continuing with the noscript, exiting..."
exit 1
else # Executes if user does input "yes or no"
echo "Invalid input, try again..."
clear # clears the terminal
fi # ending block for the if statement
done # ending block for while loop

look at [Github: InstallScripts\](https://github.com/gitxpresso/InstallScripts)

https://redd.it/1mwt31f
@r_bash
What safe config file format do you recommend?

I don't want to source something in case it executes code. For now I am using json and jq. I would use yaml instead but yq isn't among programs I can justify installing

I could parse a text file. Sugestions? I just need key and value.

https://redd.it/1myf0xk
@r_bash
Does anyone use select menus?

They looked like a useful feature at first, but then I realized that select only prints the prompt ($PS3) but not the list. If whatever command you ran before prints a lot of text to stderr/stdout, you will not be able to see the list of options.

https://redd.it/1myi7zd
@r_bash
Made a bash argument parser

So I got tired of getopts and while loops for manual parsing. Plus help messages never staying in sync when you update your parser.

Built barg.sh - pure bash, performant enough to beat Python argparse by 3x (in my PC a simple hello world in python was 5 ms slower than barg generating the help message, lol), zero dependencies.

#!/usr/bin/bash
source barg.sh

barg::parse "${@}" << BARG
meta { helpmsg: true }
f/force :flag => FORCE "Force overwrite"
o/output :str => OUTPUT "Output directory"
v/verbose :flag => VERBOSE "Verbose mode"
BARG


That's it. Help messages auto-generate and stay in sync. Flag bundling works (-fv). Subcommands supported. Choice validation built in, has something I think switch is a good name, types, default values, etc.

GitHub

PS: This is just what I use on my own machine. For portable noscripts, I still stick to while loops since I don't want to make bash noscripts require downloading dependencies for everyone. These files live on my PC and work great for my environment, just thought it was cool enough to share.

https://redd.it/1myvo86
@r_bash
Why doesn't this for loop work in this scenario?

https://preview.redd.it/3dcydksxdzkf1.png?width=420&format=png&auto=webp&s=078e873c8b65149c8cc06496ec3c280f6769806f

https://preview.redd.it/5yc2ewzydzkf1.png?width=380&format=png&auto=webp&s=7593eacab4d0d4b7b2108aa8121d65c8e25cf4ea

For whatever reason, the first for loop (i = 0;) doesn't work. It simply calls the progress bar once, sleeps and then quits. However, the second one works fine. Does anyone know why this is the case?

https://redd.it/1myxpl0
@r_bash
Getting a directory path from a file

Hi all, I want to make a noscript to get a directory path from a file.

Let say I have this file called shortcut which has a line of

cf ${XDGCONFIGHOME:-$HOME/.config}

Then I have this noscript called sln to get the dir path from shortcut and then symlink some file to that path

#!/bin/sh

shortcut="$HOME/shortcut"
path="$(grep "^$2 " "$shortcut" | awk '{print $2}')"
ln -s "$1" "$path"

However I get error running sln <some_file> cf: ln: failed to create symbolic link '${XDG_CONFIG_HOME:-$HOME/.config}': No such file or directory

But if I add eval "path=$path" right before symlink will solve this problem. Does anyone know why is that?

https://redd.it/1mzo6mk
@r_bash
A recommended way to parse a config?

I have a backup noscript to manage my many external HDDs--each are associated with certain paths on the host's filesystem and when I don't want to manually specify those paths--just the drives themselves and it will back up their associated paths. E.g. driveA=(/pathA /pathB /pathD).

Currently the noscript uses drive names as array variables and uses namerefs (declare -n) where drive name as argument to noscript is passed to determine its associated paths. But this is problematic because 1) bash variable names cannot contain dash (-) which is useful as a drive name and 2) I would like to separate these variables into a config separate from the noscript.

Is there a standard and/or recommended (i.e. with little caveats) way to easily parse a suitable config for my purposes? I'm not sure what format is desirable. E.g. I'll need a reliable way to parse each drive for their paths in the noscript (doesn't have to be in this format, just an example. It can be assumed path names are absolute paths so begin with a / and drive names don't start with a /. Order of paths for a drive matter.):

-- driveA
/pathA/subdir
/pathB
/pathD

-- driveB
/pathF

-- driveC
/pathY
/pathZ

A simpler way would be to use a config for each drive name if there isn't a good way to go about this; however, I find it much more useful to work with one config so I can easily see and manage all the paths, associating them with different drives.

https://redd.it/1mztyus
@r_bash
built check_builtin.sh - a Bash tool that catches when your commands aren't what you think they are

Last week I spent 2 hours debugging why cd wasn't working properly with directory names containing spaces. Turns out Go version manager (GVM) had quietly replaced it with a function that was using $* instead of $@ - breaking argument parsing. Found the bug and fix here.

So I built check_builtin.sh - a Bash tool that catches when your commands aren't what you think they are.(MIT/BSD Licensde)

A few days ago someone was asking about aliases usage in this channel, so I wanted to put this out there. Its big and not light weight. There are simpler ways to do similar things , but I like fancy and easy to understand.

Exhibit A: The Phantom Function


$ source check_builtin.sh
$ check_builtin::main cd

COMMAND STATUS INFO

------- ------ ----

cd function override | function builtin



Turns out .gvm had been intercepting every cd forever with a buggy implementation

Exhibit B: The Helpful Alias


$ check_builtin::main ls

COMMAND STATUS INFO

------- ------ ----

ls alias override | alias → ls --color=auto | external → /usr/bin/ls



At least this one was harmless but it always bothered me as a security researcher that it was this easy to gloss-over coreutils...

## What It Does

Scans your live shell for command hijacking

Shows the full precedence chain (aliases beat functions beat builtins beat externals)

Flags critical commands like rm, sudo, mv that you really don't want overridden

Works by sourcing (because aliases/functions don't inherit to child processes - fundamental bash behavior)

The tool caught my purposeful overrides in my "matrix.dot.files" shell that I had baked in.

Quick test: source check_builtin.sh && check_builtin::main -a

GitHub: https://github.com/shadowbq/check_builtins

## Feedback plse:

Have you ever been burned by a command that wasn't what you expected?

Would something like this be useful in your workflow?

What other "gotcha" scenarios should this catch?

Built this out of frustration, but curious if others have hit similar pain points or if I'm just special at breaking things 😅

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