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 ' #
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
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
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
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
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
GitHub
GitHub - cybrota/recaller: A blazing fast, command-line term-ui app to recall your shell history with absolute precision
A blazing fast, command-line term-ui app to recall your shell history with absolute precision - cybrota/recaller
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
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
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Why my PS1 is acting like this ?
After configuring my
But when I start using it, this happens:
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
I isolated some functions, and what I understand is that the
https://redd.it/1mveqbg
@r_bash
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
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
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
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
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
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
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
GitHub
GitHub - GitXpresso/InstallScripts: Bash noscripts that used the steps on to install a package example: librewolf for the other distro's…
Bash noscripts that used the steps on to install a package example: librewolf for the other distro's that the package is available too. - GitXpresso/InstallScripts
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
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
GitHub
GitHub - GitXpresso/InstallScripts: Bash noscripts that used the steps on to install a package example: librewolf for the other distro's…
Bash noscripts that used the steps on to install a package example: librewolf for the other distro's that the package is available too. - GitXpresso/InstallScripts
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
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
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
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
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
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
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
That's it. Help messages auto-generate and stay in sync. Flag bundling works (
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
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
GitHub
GitHub - klapptnot/barg.sh: A kind of argument parser in pure bash (builtins)
A kind of argument parser in pure bash (builtins). Contribute to klapptnot/barg.sh development by creating an account on GitHub.
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
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
cf ${XDGCONFIGHOME:-$HOME/.config}
Then I have this noscript called
#!/bin/sh
shortcut="$HOME/shortcut"
path="$(grep "^$2 " "$shortcut" | awk '{print $2}')"
ln -s "$1" "$path"
However I get error running
But if I add
https://redd.it/1mzo6mk
@r_bash
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 ofcf ${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 directoryBut 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
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
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.
Currently the noscript uses drive names as array variables and uses namerefs (
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
-- 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
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
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
built
Last week I spent 2 hours debugging why
So I built
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
Turns out
Exhibit B: The Helpful Alias
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:
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
check_builtin.sh - a Bash tool that catches when your commands aren't what you think they areLast 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 implementationExhibit 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 -aGitHub: 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
GitHub
Fix path handling in cd · adonespitogo/gvm@be0e53a
The use of `$*` prevents correctly cd'ing into a directory with spaces in its path name since each segment of the name around the space is treated as if it is a separate argument.
Examp...
Examp...
Nrip, a modern, safe replacement for rm written in rust
Tired of `rm` eating your files forever? 🪦
Check out **nrip** — a safe replacement written in Rust.
Instead of deleting files, it sends them to a *graveyard* where you can:
\- list them,
\- resurrect them (restore),
\- or cremate them (delete permanently).
It even comes with `fzf` integration for interactive picking.
This is my first real Rust project, so any feedback is welcome! 🙏
https://github.com/Samtroulcode/NRip
https://redd.it/1n0imre
@r_bash
Tired of `rm` eating your files forever? 🪦
Check out **nrip** — a safe replacement written in Rust.
Instead of deleting files, it sends them to a *graveyard* where you can:
\- list them,
\- resurrect them (restore),
\- or cremate them (delete permanently).
It even comes with `fzf` integration for interactive picking.
This is my first real Rust project, so any feedback is welcome! 🙏
https://github.com/Samtroulcode/NRip
https://redd.it/1n0imre
@r_bash
GitHub
GitHub - Samtroulcode/NRip: A safe and modern replacement for rm with a graveyard, written in rust
A safe and modern replacement for rm with a graveyard, written in rust - Samtroulcode/NRip
Return to the fist terminal to finish noscript?
Occasionally I think of something that will make my Ubuntu desktop experience better, and I think it will be a super simple bash noscript, but it almost never is LOL! I am using an application installed with pip and every time I start it I have to open the terminal and issue a few commands and then open a web browser. So I wanted a noscript to start it that I could launch from a .desktop icon. These are the steps:
#!/bin/bash
cd ~/lute3
source myenv/bin/activate
python -m lute.main
brave-browser http://localhost:5001
https://redd.it/1n0wh8e
@r_bash
Occasionally I think of something that will make my Ubuntu desktop experience better, and I think it will be a super simple bash noscript, but it almost never is LOL! I am using an application installed with pip and every time I start it I have to open the terminal and issue a few commands and then open a web browser. So I wanted a noscript to start it that I could launch from a .desktop icon. These are the steps:
#!/bin/bash
cd ~/lute3
source myenv/bin/activate
python -m lute.main
brave-browser http://localhost:5001
So of course what happens is that launching lute.main opens a new terminal and so the browser here does not launch. It's not a huge deal because even just with the first 3 lines, then all I have to do is open a bookmark in my browser, that is good. But it would be super cool to get the browser to launch. I tried searching for help on this but probably was not using the correct terms. Thankshttps://redd.it/1n0wh8e
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
I created an online configurator for Bash!
Have you ever wondered how much you can “squeeze” out of Bash? I have. I present an opinionated Bash configuration, whose colors can be dynamically configured in a web interface with a preview (with unix porn lovers in mind).
https://preview.redd.it/io58rhkrcflf1.png?width=980&format=png&auto=webp&s=6efe0f97c3dda56f60d9de12cdc2b99528c3558c
The configuration includes features such as:
* Git information if the current folder is a repository.
* History search using arrows.
* Number of background processes.
* Visual separation of executed commands.
* Exit code.
* Date and time.
* Unique host emblem.
Since I use it all the time myself, I thought someone else might like it too. So I'm making it more widely available, enjoy! [**https://github.com/czoczo/BetterBash**](https://github.com/czoczo/BetterBash)
If you like the project, you may consider giving a 🌟 on GitHub to show your support.
https://redd.it/1n0xd3k
@r_bash
Have you ever wondered how much you can “squeeze” out of Bash? I have. I present an opinionated Bash configuration, whose colors can be dynamically configured in a web interface with a preview (with unix porn lovers in mind).
https://preview.redd.it/io58rhkrcflf1.png?width=980&format=png&auto=webp&s=6efe0f97c3dda56f60d9de12cdc2b99528c3558c
The configuration includes features such as:
* Git information if the current folder is a repository.
* History search using arrows.
* Number of background processes.
* Visual separation of executed commands.
* Exit code.
* Date and time.
* Unique host emblem.
Since I use it all the time myself, I thought someone else might like it too. So I'm making it more widely available, enjoy! [**https://github.com/czoczo/BetterBash**](https://github.com/czoczo/BetterBash)
If you like the project, you may consider giving a 🌟 on GitHub to show your support.
https://redd.it/1n0xd3k
@r_bash
Why
Why
Hi, I was looking for files starting with the letter L and not its Backup. I have 2 option for list them 1 is using the l (letter l from lile, love)
I was doing so 2 cmd
and in twice cmd ls found Lubuntu and Lubuntu~
"l" (l from love, letter) cmd is an build-in alias for
When I did
what about the flag -B?
Shouldn't the option -b filter the backup that the ls command finds?
Thank you and Regards!
https://redd.it/1n11noh
@r_bash
* is more important than -B in ls cmd?Why
* is more important than -B in ls cmd?Hi, I was looking for files starting with the letter L and not its Backup. I have 2 option for list them 1 is using the l (letter l from lile, love)
l L*and 2 using ls -B L* I was doing so 2 cmd
l L* (l of love, letter) cmd and ls -B L* cmd too! and in twice cmd ls found Lubuntu and Lubuntu~
"l" (l from love, letter) cmd is an build-in alias for
ls -B filtering Backups (files ending in ~) and ls -B L* do the same. When I did
l (l of letter) L* cmd ( and ls -B L* cmd too )" both cmd found Lubuntu and Lubuntu~ what about the flag -B?
Shouldn't the option -b filter the backup that the ls command finds?
* is above -B flag ... I don't understand why star is over -BThank you and Regards!
https://redd.it/1n11noh
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community