quote help
I am trying to build information for my bash prompt. The following command works in the terminal.
git worktree list 2>/dev/null | grep -v "^${HOME} " | sed -e 's/^.\[//' -e 's/\]$//'
When I add this to .bashrc, I get an error stating the following:
grep: ": No such file or directory
This is the line in the .bashrc file
PS1="${PS1}$(git worktree list 2>/dev/null | grep -v \"^${HOME} \" | sed -e 's/^.[//' -e 's/\]$//')"
https://redd.it/12dgc05
@r_bash
I am trying to build information for my bash prompt. The following command works in the terminal.
git worktree list 2>/dev/null | grep -v "^${HOME} " | sed -e 's/^.\[//' -e 's/\]$//'
When I add this to .bashrc, I get an error stating the following:
grep: ": No such file or directory
This is the line in the .bashrc file
PS1="${PS1}$(git worktree list 2>/dev/null | grep -v \"^${HOME} \" | sed -e 's/^.[//' -e 's/\]$//')"
https://redd.it/12dgc05
@r_bash
Reddit
r/bash on Reddit: quote help
Posted by u/linux478 - No votes and 3 comments
Optimizing bash noscripts?
How? I've read somewhere over the Internet that the *sh family is inherently slow. How could we reduce the impact of this nature so that bash noscripts can perform faster? Are there recommended habits to follow? Hints? Is there any primordial advice?
https://redd.it/12drpy9
@r_bash
How? I've read somewhere over the Internet that the *sh family is inherently slow. How could we reduce the impact of this nature so that bash noscripts can perform faster? Are there recommended habits to follow? Hints? Is there any primordial advice?
https://redd.it/12drpy9
@r_bash
Reddit
r/bash on Reddit: Optimizing bash noscripts?
Posted by u/Mark_1802 - No votes and 8 comments
Can someone explain how [:print:] works?
So one of the noscript is:
echo /sys/devices/pci0000:00/0000:00:14.0/i2c-4/4-002e/hwmon/hwmon[[:print:\]\]*/pwm2
I understand the result, but how does it work? What is it call in bash?
https://redd.it/12du8ed
@r_bash
So one of the noscript is:
echo /sys/devices/pci0000:00/0000:00:14.0/i2c-4/4-002e/hwmon/hwmon[[:print:\]\]*/pwm2
I understand the result, but how does it work? What is it call in bash?
https://redd.it/12du8ed
@r_bash
Reddit
r/bash on Reddit: Can someone explain how [[:print:]] works?
Posted by u/paulsiu - No votes and no comments
Checkbox menu without whiptail or dialog
I'm wanting to write a menu with checkboxes in bash. Installing whiptail or dialog are not options.
Is it even possible to a menu with checkboxes in bash without whiptail or dialog?
https://redd.it/12e8hbl
@r_bash
I'm wanting to write a menu with checkboxes in bash. Installing whiptail or dialog are not options.
Is it even possible to a menu with checkboxes in bash without whiptail or dialog?
https://redd.it/12e8hbl
@r_bash
Reddit
r/bash on Reddit: Checkbox menu without whiptail or dialog
Posted by u/DaveR007 - No votes and no comments
What am I doing wrong?
the noscript:
find /path/to/folder -type f \\( -iname "*.flac" -o -iname "*.wav" -o -iname "*.alac" -o -iname "*.aiff" -o -iname "*.ape" -o -iname "*.dsd" \\) -o -iname "*.mp3" -exec bash -c '
for audio_file do
audio_basename="$(basename "${audio_file}")"
target_file="/path/to/tracks/${audio_basename%.*}.flac"
[[ -f "${target_file}" \]\] && continue
lossless_file=""
for ext in flac alac wav aiff ape dsd; do
lf="${audio_file%.*}.${ext}"
[[ -f "${lf}" \]\] && lossless_file="${lf}" && break
done
[[ -z "${lossless_file}" \]\] && lossless_file="${audio_file}"
mp3_file="${audio_file%.*}.mp3"
if [[ -f "${mp3_file}" && "${lossless_file}" != "${audio_file}" \]\]; then
mtime_mp3="$(stat -f '%m' "${mp3_file}")"
mtime_lossless="$(stat -f '%m' "${lossless_file}")"
if [[ "${mtime_mp3}" -gt "${mtime_lossless}" \]\]; then
lossless_file="${mp3_file}"
fi
fi
cp -n "${lossless_file}" "${target_file}"
done' bash {} +
It should comb through a folder structure with audio files and copy them to a new folder. If there are two files with the same name it should prioritise the lossless format. When i run the noscript, I only get files with .flac format in the new folder. What am I missing?
https://redd.it/12eouk3
@r_bash
the noscript:
find /path/to/folder -type f \\( -iname "*.flac" -o -iname "*.wav" -o -iname "*.alac" -o -iname "*.aiff" -o -iname "*.ape" -o -iname "*.dsd" \\) -o -iname "*.mp3" -exec bash -c '
for audio_file do
audio_basename="$(basename "${audio_file}")"
target_file="/path/to/tracks/${audio_basename%.*}.flac"
[[ -f "${target_file}" \]\] && continue
lossless_file=""
for ext in flac alac wav aiff ape dsd; do
lf="${audio_file%.*}.${ext}"
[[ -f "${lf}" \]\] && lossless_file="${lf}" && break
done
[[ -z "${lossless_file}" \]\] && lossless_file="${audio_file}"
mp3_file="${audio_file%.*}.mp3"
if [[ -f "${mp3_file}" && "${lossless_file}" != "${audio_file}" \]\]; then
mtime_mp3="$(stat -f '%m' "${mp3_file}")"
mtime_lossless="$(stat -f '%m' "${lossless_file}")"
if [[ "${mtime_mp3}" -gt "${mtime_lossless}" \]\]; then
lossless_file="${mp3_file}"
fi
fi
cp -n "${lossless_file}" "${target_file}"
done' bash {} +
It should comb through a folder structure with audio files and copy them to a new folder. If there are two files with the same name it should prioritise the lossless format. When i run the noscript, I only get files with .flac format in the new folder. What am I missing?
https://redd.it/12eouk3
@r_bash
Reddit
r/bash on Reddit: What am I doing wrong?
Posted by u/lucidgazorpazorp - No votes and no comments
search and replace (if not equal)
I am hoping someone can help
I need to create a simple bash noscript
read through /etc/hosts
if IP does not equal "X.X.X.X" then rename it to Y.Y.Y.Y
I can run that whenever I would like and just change the IPs as necessary
Similarly, I want to do the same with printers.conf with a twist
if printer name starts with A, then change IP to X.X.X.X if printer name starts with B then change IP to Y.Y.Y.Y
Can anyone help with that, please
thank you
https://redd.it/12ex3mq
@r_bash
I am hoping someone can help
I need to create a simple bash noscript
read through /etc/hosts
if IP does not equal "X.X.X.X" then rename it to Y.Y.Y.Y
I can run that whenever I would like and just change the IPs as necessary
Similarly, I want to do the same with printers.conf with a twist
if printer name starts with A, then change IP to X.X.X.X if printer name starts with B then change IP to Y.Y.Y.Y
Can anyone help with that, please
thank you
https://redd.it/12ex3mq
@r_bash
Reddit
r/bash on Reddit: search and replace (if not equal)
Posted by u/runningonempty999 - No votes and no comments
Properly attach tmux session Jupyter Lab
Lately I have been running long Python noscripts in Jupyter lab on a remote server. However, when the server disconnects for some reason I lose all the progress, and I need to start over. Sorry in advance, I'm really new to this so I might sound plain stupid.
So I learned that a work around for this is to use tmux, in which I operate a noscript in the background? However, I am having trouble with it.
So first I open the ssh connection with the server in bash. Then I create a new tmux session (I have no other tmux sessions). Then I type the python environment I want to use and jupyter lab to open it in the browser.
Okay so I am running all the cells and then de-attach the tmux using ctrl+b and d. All good (I assume).
But then when I disconnect, and then try to connect again by attaching the tmux, I only get the log info. How am I supposed to open Jupyter lab again properly? I cannot type in that window. (Excuse my ignorance)
Anyways, I have tried creating a new pane using 'ctrl+b and %' and typing in the environment and jupyter lab to open. And also another window. I also just used the link it provides in the log window. In all cases, when I go to the noscript, it is not running at all, and there is no output?? I don't understand what I really need to do, or what went wrong.
I've also lost so much time on this lol, so currently I am running my code in the middle of the night, with my laptop on, the old fashion way. I'm going to sleep in a bit hoping the server didn't disconnect. But I feel like there gotta be something I am missing or just doing wrong. Does anyone know? I can provide more information. Thanks for the help anyway!
https://redd.it/12f3tam
@r_bash
Lately I have been running long Python noscripts in Jupyter lab on a remote server. However, when the server disconnects for some reason I lose all the progress, and I need to start over. Sorry in advance, I'm really new to this so I might sound plain stupid.
So I learned that a work around for this is to use tmux, in which I operate a noscript in the background? However, I am having trouble with it.
So first I open the ssh connection with the server in bash. Then I create a new tmux session (I have no other tmux sessions). Then I type the python environment I want to use and jupyter lab to open it in the browser.
Okay so I am running all the cells and then de-attach the tmux using ctrl+b and d. All good (I assume).
But then when I disconnect, and then try to connect again by attaching the tmux, I only get the log info. How am I supposed to open Jupyter lab again properly? I cannot type in that window. (Excuse my ignorance)
Anyways, I have tried creating a new pane using 'ctrl+b and %' and typing in the environment and jupyter lab to open. And also another window. I also just used the link it provides in the log window. In all cases, when I go to the noscript, it is not running at all, and there is no output?? I don't understand what I really need to do, or what went wrong.
I've also lost so much time on this lol, so currently I am running my code in the middle of the night, with my laptop on, the old fashion way. I'm going to sleep in a bit hoping the server didn't disconnect. But I feel like there gotta be something I am missing or just doing wrong. Does anyone know? I can provide more information. Thanks for the help anyway!
https://redd.it/12f3tam
@r_bash
Reddit
r/bash on Reddit: Properly attach tmux session Jupyter Lab
Posted by u/augusts99 - No votes and no comments
yt-dlp file name variable
Hello I am unable to get the file name created in the previous line by yt-dlp. I guess I could slice it when I input the url but I would like to build on this noscript later to do be able to handle whole playlists. Hoping a bash wizard out there has a good solution. Thank you.
​
#! /bin/bash
timestamp=$(date +%Y-%m-%d:%H:%M)
echo "enter youtube url"
read url
yt-dlp "$url" --list-formats
echo $file
echo "Enter the resolution of the clip or leave blank for audio only"
read res
# Uses || logical operator that should the first command fail runs the second one to only get audio.
yt-dlp -f "bvheight=$res+ba" "$url" -o '%(id)s.%(ext)s' || yt-dlp -f "ba" "$url" -o '%(id)s.audio.%(ext)s'
# can not get the file name created in line 14
ffmpeg -i "$%(id)s.audio.webm" -c:a libvorbis -b:a 64k "$file.audio.ogg"
https://redd.it/12frno2
@r_bash
Hello I am unable to get the file name created in the previous line by yt-dlp. I guess I could slice it when I input the url but I would like to build on this noscript later to do be able to handle whole playlists. Hoping a bash wizard out there has a good solution. Thank you.
​
#! /bin/bash
timestamp=$(date +%Y-%m-%d:%H:%M)
echo "enter youtube url"
read url
yt-dlp "$url" --list-formats
echo $file
echo "Enter the resolution of the clip or leave blank for audio only"
read res
# Uses || logical operator that should the first command fail runs the second one to only get audio.
yt-dlp -f "bvheight=$res+ba" "$url" -o '%(id)s.%(ext)s' || yt-dlp -f "ba" "$url" -o '%(id)s.audio.%(ext)s'
# can not get the file name created in line 14
ffmpeg -i "$%(id)s.audio.webm" -c:a libvorbis -b:a 64k "$file.audio.ogg"
https://redd.it/12frno2
@r_bash
Reddit
r/bash on Reddit: yt-dlp file name variable
Posted by u/Admirable_Mistake832 - No votes and no comments
what am I doing wrong
This is a function that will install a window manager based on a ps3 prompt
these are the variables
#wm's (wms_inst)
PS3="Would you like to install any's: "
options=("SpectrWM" "CWM" "Qtile" "Hyprland" "AwesomeWM" "Skip")
this is the function
#installs window managers
wms_inst () {
select opt in "${options[@]}"
while True
do
case $opt in
"SpectrWM", "spectrWM", "Spectrwm", "spectrwm")
nix-env -iA nixpkgs.spectrwm
;;
"CWM", "cWM", "Cwm", "cwm")
nix-env -iA nixpkgs.cwm
;;
"Qtile", "qtile")
nix-env -iA nixpkgs.qtile
;;
"Hyprland", "hyprland")
nix-env -iA nixpkgs.hyprland
;;
"AwesomeWM", "awesomeWM", "Awesomewm")
nix-env -iA nixpkgs.awesome
;;
"Skip", "skip")
read -p "Do you want to select another Y/N " wmselect;
if [ "$wmselect" = "y" ]; then
done
fi
;;
*) echo "invalid option";;
esac
done
}
It is failing at this part
`select opt in "${options[@]}"
while True
do`
there is an error with the select and the while loop but I cannot figure it out.
does anyone know the answer?
https://redd.it/12fst5l
@r_bash
This is a function that will install a window manager based on a ps3 prompt
these are the variables
#wm's (wms_inst)
PS3="Would you like to install any's: "
options=("SpectrWM" "CWM" "Qtile" "Hyprland" "AwesomeWM" "Skip")
this is the function
#installs window managers
wms_inst () {
select opt in "${options[@]}"
while True
do
case $opt in
"SpectrWM", "spectrWM", "Spectrwm", "spectrwm")
nix-env -iA nixpkgs.spectrwm
;;
"CWM", "cWM", "Cwm", "cwm")
nix-env -iA nixpkgs.cwm
;;
"Qtile", "qtile")
nix-env -iA nixpkgs.qtile
;;
"Hyprland", "hyprland")
nix-env -iA nixpkgs.hyprland
;;
"AwesomeWM", "awesomeWM", "Awesomewm")
nix-env -iA nixpkgs.awesome
;;
"Skip", "skip")
read -p "Do you want to select another Y/N " wmselect;
if [ "$wmselect" = "y" ]; then
done
fi
;;
*) echo "invalid option";;
esac
done
}
It is failing at this part
`select opt in "${options[@]}"
while True
do`
there is an error with the select and the while loop but I cannot figure it out.
does anyone know the answer?
https://redd.it/12fst5l
@r_bash
Reddit
r/bash on Reddit: what am I doing wrong
Posted by u/04AE - No votes and 1 comment
Need to unhide output
I have an embedded system I'm poking around in and from what I gather it's running bash. I'm taking a wild guess based on looking through the firmware.
I can get out of the application and drop to a shell however the following happens: blinking cursor, can type anything but when I hit enter it drops the blinking cursor to a new line and no output from the command is posted to the screen.
Using the Up, down, left, right keys produce characters such as, "^[D" when the left key is pressed, etc.
CTRL +ALT + DEL restarts the machine.
Enter moves the blinking cursor to the next line.
ESC produces "^[".
Tab works and moves the cursor over like it would in Windows.
What I'm looking for is a way to get the terminal/she'll to echo the output of the command or show the command prompt so I can see what's going on.
Any ideas? Excuse me if I'm in the wrong sub.
[https://redd.it/12g1knv
@r_bash
I have an embedded system I'm poking around in and from what I gather it's running bash. I'm taking a wild guess based on looking through the firmware.
I can get out of the application and drop to a shell however the following happens: blinking cursor, can type anything but when I hit enter it drops the blinking cursor to a new line and no output from the command is posted to the screen.
Using the Up, down, left, right keys produce characters such as, "^[D" when the left key is pressed, etc.
CTRL +ALT + DEL restarts the machine.
Enter moves the blinking cursor to the next line.
ESC produces "^[".
Tab works and moves the cursor over like it would in Windows.
What I'm looking for is a way to get the terminal/she'll to echo the output of the command or show the command prompt so I can see what's going on.
Any ideas? Excuse me if I'm in the wrong sub.
[https://redd.it/12g1knv
@r_bash
Reddit
r/bash on Reddit: Need to unhide output
Posted by u/patg84 - No votes and no comments
confusion over read ...or maybe printf?
So I'm doing some synthetic testing in order to better understand how read works, but now I think I'm getting tripped up with how printf works? The only thing I know for certain is I am confused.
I'm feeding the two arguments
bash-5.2$ read readitem < <(printf '%s\t%s\n' 'hello\' 'world') && echo "$readitem"
hello world
The \\t escape sequence is seemingly not negated, and the '\\' escape character itself is gone. Compare this to negating a newline in the format
bash-5.2$ read readitem < <(printf '%s\n%s\n' 'hello\' 'world') && echo "$readitem"
helloworld
And it works as I expect, with the
https://redd.it/12g8wvz
@r_bash
So I'm doing some synthetic testing in order to better understand how read works, but now I think I'm getting tripped up with how printf works? The only thing I know for certain is I am confused.
I'm feeding the two arguments
'hello\' 'world' to printf with the format %s\t%s\n. The 'hello\\' is deliberate as to negate the '\\t' escape sequence. The input stream is fed into the read command and I echo the variable. I'm expecting this to be pretty straight forward, with the output being something like 'helloworld', wherein the tab has been negated and the string is without any whitespace. After which I was expecting to add the -r option to read and see something like hello\ world because the backslash would be ignored as an escape character. When I actually run the command though...bash-5.2$ read readitem < <(printf '%s\t%s\n' 'hello\' 'world') && echo "$readitem"
hello world
The \\t escape sequence is seemingly not negated, and the '\\' escape character itself is gone. Compare this to negating a newline in the format
%s\n%s\n...bash-5.2$ read readitem < <(printf '%s\n%s\n' 'hello\' 'world') && echo "$readitem"
helloworld
And it works as I expect, with the
\n character being negated. Why am I able to escape the newline but not the tab?https://redd.it/12g8wvz
@r_bash
Reddit
r/bash on Reddit: confusion over read ...or maybe printf?
Posted by u/windows_sans_borders - No votes and 1 comment
bash returns me an error when reading a string with "/" from CSV file
This error `sed: -e expression #1, character 20: unknown option for s'` happens when `sed` reads a `/`.
I have a code that reads a CSV file, where there are cells with `/`. Here's a small portion of the code:
while read col1 col2
do
name1 = $col1 # here are cells that include "/"
name2 = $col2
for i in ${!name1[@]}
do
sed -i s/$name_place/"${name1[i]// /\\ }"/ file.noscript
# + more stuff here
done
done < $CSVfile
How can I fix it so the output includes the `/`?
https://redd.it/12gmok0
@r_bash
This error `sed: -e expression #1, character 20: unknown option for s'` happens when `sed` reads a `/`.
I have a code that reads a CSV file, where there are cells with `/`. Here's a small portion of the code:
while read col1 col2
do
name1 = $col1 # here are cells that include "/"
name2 = $col2
for i in ${!name1[@]}
do
sed -i s/$name_place/"${name1[i]// /\\ }"/ file.noscript
# + more stuff here
done
done < $CSVfile
How can I fix it so the output includes the `/`?
https://redd.it/12gmok0
@r_bash
Reddit
r/bash on Reddit: bash returns me an error when reading a string with "/" from CSV file
Posted by u/AlbertoAru - No votes and 2 comments
5 Bash String Manipulation Methods That Help Every Developer
https://levelup.gitconnected.com/5-bash-string-manipulation-methods-that-help-every-developer-49d4ee38b593?sk=e454f60397c41cd73d9e4810ee7869f8
https://redd.it/12h9c9h
@r_bash
https://levelup.gitconnected.com/5-bash-string-manipulation-methods-that-help-every-developer-49d4ee38b593?sk=e454f60397c41cd73d9e4810ee7869f8
https://redd.it/12h9c9h
@r_bash
Medium
5 Bash String Manipulation Methods That Help Every Developer
Process strings productively in your automation noscripts with these syntaxes
need help implementing s feature into a noscript
I have been working on a noscript that allows me to choose a host in my ~/.ssh/config file in my termux installation on my phone. The noscript works great as is.
The noscript allows for pushing a file or folder to the selected remote host or pulling a remote folder to my phone. I've gotten the push files section to allow for switching between selecting [a] file or folder.
I want to be able to do the same with the pull section. I can currently either set it for files or folders which is ok but I know it can be done just haven't figured out how yet.
Also another thing I have been trying to implement is selecting multiple files or folders and getting it to properly transfer I currently get an error when selecting multiple files that seems to come from fzf output it looks like this
`rsync: [sender] change_dir "/data/data/com.termux/files/home/.shortcuts/home\#012/data/data/com.termux/files/home/.shortcuts/love\#012/data/data/com.termux/files/home/.shortcuts" failed: No such file or directory`
Here is the current noscript any suggestions or help is very much appreciated
#!/bin/bash
function get-remote-hosts {
grep -iw host ~/.ssh/config | grep -v "exec" | cut -d ' ' -f 2
}
function backup-files {
mapfile -t REMOTE_HOSTS < <(get-remote-hosts)
if [ ${#REMOTE_HOSTS[@]} -eq 0 ]; then
printf "No remote hosts found in ~/.ssh/config\n"
return 1
fi
printf "Select a remote host:\n"
select remote_host in "${REMOTE_HOSTS[@]}"; do
printf "Select an option:\n"
select option in "Push files to remote directory" "Pull files from remote directory" "Exit" ; do
case "$option" in
"Push files to remote directory")
if command -v fzf >/dev/null 2>&1; then
FZF_DEFAULT_COMMAND='find "$HOME"/ /sdcard/ -maxdepth 2 -type f | grep -iv music | sort -f'
local_source_dir=$(eval "$FZF_DEFAULT_COMMAND" | sort -f | fzf --bind 'ctrl-d:reload(find "$HOME"/ /sdcard/ -maxdepth 1 -type d | sort -f),ctrl-f:reload(find "$HOME"/ /sdcard/ -maxdepth 2 -type f | grep -iv music | sort -f)' -m --layout=reverse --reverse)
else
local_source_dir=$(dialog --stdout --noscript "Select a directory" --dselect "$HOME/" 14 48)
fi
exit_status=$?
if [ $exit_status -ne 0 ]; then
printf "Error: Failed to select local directory\n"
return 1
fi
temp_file=$(mktemp)
ssh "$remote_host" 'find $HOME/ /media/nowhereman/nowhereman/ -maxdepth 1 -type d | sort -f' | sort -f > "$temp_file"
if command -v fzf >/dev/null 2>&1; then
remote_dest_dir=$(cat "$temp_file" | fzf --reverse)
else
remote_dest_dir=$(dialog --stdout --noscript "Select a remote directory" --fselect "$temp_file" 14 48)
fi
rm "$temp_file"
exit_status=$?
if [ $exit_status -ne 0 ]; then
printf "Error: Failed to select remote directory\n"
return 1
fi
if rsync -avz --progress "$local_source_dir" "$remote_host":"$remote_dest_dir"; then
printf "Files pushed successfully\n"
else
printf "Error: Failed to push files\n"
return 1
fi
break
;;
"Pull files from remote directory")
temp_file=$(mktemp)
ssh "$remote_host" 'find $HOME/
I have been working on a noscript that allows me to choose a host in my ~/.ssh/config file in my termux installation on my phone. The noscript works great as is.
The noscript allows for pushing a file or folder to the selected remote host or pulling a remote folder to my phone. I've gotten the push files section to allow for switching between selecting [a] file or folder.
I want to be able to do the same with the pull section. I can currently either set it for files or folders which is ok but I know it can be done just haven't figured out how yet.
Also another thing I have been trying to implement is selecting multiple files or folders and getting it to properly transfer I currently get an error when selecting multiple files that seems to come from fzf output it looks like this
`rsync: [sender] change_dir "/data/data/com.termux/files/home/.shortcuts/home\#012/data/data/com.termux/files/home/.shortcuts/love\#012/data/data/com.termux/files/home/.shortcuts" failed: No such file or directory`
Here is the current noscript any suggestions or help is very much appreciated
#!/bin/bash
function get-remote-hosts {
grep -iw host ~/.ssh/config | grep -v "exec" | cut -d ' ' -f 2
}
function backup-files {
mapfile -t REMOTE_HOSTS < <(get-remote-hosts)
if [ ${#REMOTE_HOSTS[@]} -eq 0 ]; then
printf "No remote hosts found in ~/.ssh/config\n"
return 1
fi
printf "Select a remote host:\n"
select remote_host in "${REMOTE_HOSTS[@]}"; do
printf "Select an option:\n"
select option in "Push files to remote directory" "Pull files from remote directory" "Exit" ; do
case "$option" in
"Push files to remote directory")
if command -v fzf >/dev/null 2>&1; then
FZF_DEFAULT_COMMAND='find "$HOME"/ /sdcard/ -maxdepth 2 -type f | grep -iv music | sort -f'
local_source_dir=$(eval "$FZF_DEFAULT_COMMAND" | sort -f | fzf --bind 'ctrl-d:reload(find "$HOME"/ /sdcard/ -maxdepth 1 -type d | sort -f),ctrl-f:reload(find "$HOME"/ /sdcard/ -maxdepth 2 -type f | grep -iv music | sort -f)' -m --layout=reverse --reverse)
else
local_source_dir=$(dialog --stdout --noscript "Select a directory" --dselect "$HOME/" 14 48)
fi
exit_status=$?
if [ $exit_status -ne 0 ]; then
printf "Error: Failed to select local directory\n"
return 1
fi
temp_file=$(mktemp)
ssh "$remote_host" 'find $HOME/ /media/nowhereman/nowhereman/ -maxdepth 1 -type d | sort -f' | sort -f > "$temp_file"
if command -v fzf >/dev/null 2>&1; then
remote_dest_dir=$(cat "$temp_file" | fzf --reverse)
else
remote_dest_dir=$(dialog --stdout --noscript "Select a remote directory" --fselect "$temp_file" 14 48)
fi
rm "$temp_file"
exit_status=$?
if [ $exit_status -ne 0 ]; then
printf "Error: Failed to select remote directory\n"
return 1
fi
if rsync -avz --progress "$local_source_dir" "$remote_host":"$remote_dest_dir"; then
printf "Files pushed successfully\n"
else
printf "Error: Failed to push files\n"
return 1
fi
break
;;
"Pull files from remote directory")
temp_file=$(mktemp)
ssh "$remote_host" 'find $HOME/
/media/nowhereman/nowhereman -maxdepth 1 -type d' | sort -f > "$temp_file"
if command -v fzf >/dev/null 2>&1; then
remote_source_dir=$(cat "$temp_file" | grep -iv pictures | fzf --reverse)
else
remote_source_dir=$(dialog --stdout --noscript "Select a remote directory" --fselect "$temp_file" 14 48)
fi
rm "$temp_file"
exit_status=$?
if [ $exit_status -ne 0 ]; then
printf "Error: Failed to select remote directory\n"
return 1
fi
if command -v fzf >/dev/null 2>&1; then
local_dest_dir=$(find "$HOME"/ /sdcard/ -maxdepth 1 -type d | sort -f | fzf --reverse)
else
local_dest_dir=$(dialog --stdout --noscript "Select a directory" --dselect "$HOME/" 14 48)
fi
exit_status=$?
if [ $exit_status -ne 0 ]; then
printf "Error: Failed to select local directory\n"
return 1
fi
if rsync -avz --progress "$remote_host":"$remote_source_dir" "$local_dest_dir"; then
printf "Files pulled successfully\n"
else
printf "Error: Failed to pull files\n"
return 1
fi
break
;;
"Exit")
break
;;
*)
printf "Invalid option. Please select a valid option.\n"
;;
esac
done
break
done
}
PS3="𝝅) "
# Execute the backup-files function
backup-files
https://redd.it/12hbdwl
@r_bash
if command -v fzf >/dev/null 2>&1; then
remote_source_dir=$(cat "$temp_file" | grep -iv pictures | fzf --reverse)
else
remote_source_dir=$(dialog --stdout --noscript "Select a remote directory" --fselect "$temp_file" 14 48)
fi
rm "$temp_file"
exit_status=$?
if [ $exit_status -ne 0 ]; then
printf "Error: Failed to select remote directory\n"
return 1
fi
if command -v fzf >/dev/null 2>&1; then
local_dest_dir=$(find "$HOME"/ /sdcard/ -maxdepth 1 -type d | sort -f | fzf --reverse)
else
local_dest_dir=$(dialog --stdout --noscript "Select a directory" --dselect "$HOME/" 14 48)
fi
exit_status=$?
if [ $exit_status -ne 0 ]; then
printf "Error: Failed to select local directory\n"
return 1
fi
if rsync -avz --progress "$remote_host":"$remote_source_dir" "$local_dest_dir"; then
printf "Files pulled successfully\n"
else
printf "Error: Failed to pull files\n"
return 1
fi
break
;;
"Exit")
break
;;
*)
printf "Invalid option. Please select a valid option.\n"
;;
esac
done
break
done
}
PS3="𝝅) "
# Execute the backup-files function
backup-files
https://redd.it/12hbdwl
@r_bash
Reddit
r/bash on Reddit: need help implementing s feature into a noscript
Posted by u/nowhereman531 - No votes and no comments
Delete only files in a directory with a specific extension when there isn't also a file with the same name, but a different extension?
Basically, Skyrim can't delete old
So, how would I go about mass-deleting
Quicksave0C385D2FF153686F6B6574686961Tamriel00104020230407173815221.skse
Quicksave0C385D2FF153686F6B6574686961Tamriel00104120230407173849221.skse
Quicksave0C385D2FF153686F6B6574686961Tamriel00104420230407174210221.skse
Quicksave0C385D2FF153686F6B6574686961Tamriel00111820230407181617231.skse
Quicksave0C385D2FF153686F6B6574686961Tamriel00115620230407185421241.ess
Quicksave0C385D2FF153686F6B6574686961Tamriel00115620230407185421241.skse
So, as an example, I'd like to be able to delete the first four
I could, I guess, copy the paired files (there's only a few dozen, though finding them in the list would be painful) somewhere safe, then just
Thank you in advance.
https://redd.it/12hj8we
@r_bash
Basically, Skyrim can't delete old
*.skse files when it updates or deletes its *.ess save files, leaving lots of orphaned *.skse files that are now useless (only the most recent is used for anything and can sometimes break a savefile if it goes missing). Currently over 10,000 files in the directory, which is quite annoying to prune by hand. :/So, how would I go about mass-deleting
*.skse files that don't have a matching *.ess? The types of filenames I'm looking at are...Quicksave0C385D2FF153686F6B6574686961Tamriel00104020230407173815221.skse
Quicksave0C385D2FF153686F6B6574686961Tamriel00104120230407173849221.skse
Quicksave0C385D2FF153686F6B6574686961Tamriel00104420230407174210221.skse
Quicksave0C385D2FF153686F6B6574686961Tamriel00111820230407181617231.skse
Quicksave0C385D2FF153686F6B6574686961Tamriel00115620230407185421241.ess
Quicksave0C385D2FF153686F6B6574686961Tamriel00115620230407185421241.skse
So, as an example, I'd like to be able to delete the first four
*.skse files since they have no matching *.ess files, but keep the last two because they properly pair.I could, I guess, copy the paired files (there's only a few dozen, though finding them in the list would be painful) somewhere safe, then just
rm the remaining, but I'd rather be able to slap a noscript in ~/.local/bin to run whenever I happen to think of it...Thank you in advance.
https://redd.it/12hj8we
@r_bash
Reddit
r/bash on Reddit: Delete only files in a directory with a specific extension when there isn't also a file with the same name, but…
Posted by u/JDGumby - No votes and 3 comments
Sshto update
Hi, I've played a bit with this new filter feature and it's proved to be very handy. But I've noticed few bugs:
1. It creates dupes in the list if same hosts scattered through subgroups
2. 'Select hosts' didn't work for filtered group
3. 'Edit conf' didn't work for filtered group
These are fixed, but who knows how many remains) I've also add 'quick commands' section to the CONTENTS view to be able to start filter from there. And renamed CONNECT button in first menu to CONNECT/SELECT to correspond new feature.
The link to sshto
Enjoy)
https://redd.it/12htrl2
@r_bash
Hi, I've played a bit with this new filter feature and it's proved to be very handy. But I've noticed few bugs:
1. It creates dupes in the list if same hosts scattered through subgroups
2. 'Select hosts' didn't work for filtered group
3. 'Edit conf' didn't work for filtered group
These are fixed, but who knows how many remains) I've also add 'quick commands' section to the CONTENTS view to be able to start filter from there. And renamed CONNECT button in first menu to CONNECT/SELECT to correspond new feature.
The link to sshto
Enjoy)
https://redd.it/12htrl2
@r_bash
GitHub
GitHub - vaniacer/sshto: Small bash noscript to manage your ssh connections. It builds menu (via dialog) from your ~/.ssh/config.…
Small bash noscript to manage your ssh connections. It builds menu (via dialog) from your ~/.ssh/config. It can not only connect but also to run commands, copy files, tunnel ports. - vaniacer/sshto
grep and force header (show filename) behaviour. How to format the output?
I have very basic noscript along the lines
for i in $(run some command that gives a list of files)
do grep -H $i ^pattern
done
which is giving me the output
/home/user1/textfile1.txt:pattern is matched in this line
/home/user1/textfile2.txt:pattern is a match here in this line
/home/user1/textfile33.txt:pattern is a word in this file
That is, the filename and the matched grep are concatenated altogether on one line with a colon field separator in between.
What I'd like, without too much more effort, is to put the output on separate lines more like
/home/user1/textfile1.txt
pattern is matched in this line
/home/user1/textfile2.txt
pattern is matched here in this line
/home/user1/textfile33.txt
pattern is matched
Can grep do this? Or do I need to get complicated with the noscript and do something stupid like run grep twice or use an if to print file name if grep returns a result?
Also, using sed to change that colon into a line break isn't going to work where either the filename/path or the matched line include a colon. Grep doesn't appear to have an option to change the field separator from colon to anything else, either (very interesting design choice, I think).
https://redd.it/12i4iqz
@r_bash
I have very basic noscript along the lines
for i in $(run some command that gives a list of files)
do grep -H $i ^pattern
done
which is giving me the output
/home/user1/textfile1.txt:pattern is matched in this line
/home/user1/textfile2.txt:pattern is a match here in this line
/home/user1/textfile33.txt:pattern is a word in this file
That is, the filename and the matched grep are concatenated altogether on one line with a colon field separator in between.
What I'd like, without too much more effort, is to put the output on separate lines more like
/home/user1/textfile1.txt
pattern is matched in this line
/home/user1/textfile2.txt
pattern is matched here in this line
/home/user1/textfile33.txt
pattern is matched
Can grep do this? Or do I need to get complicated with the noscript and do something stupid like run grep twice or use an if to print file name if grep returns a result?
Also, using sed to change that colon into a line break isn't going to work where either the filename/path or the matched line include a colon. Grep doesn't appear to have an option to change the field separator from colon to anything else, either (very interesting design choice, I think).
https://redd.it/12i4iqz
@r_bash
Reddit
r/bash on Reddit: grep and force header (show filename) behaviour. How to format the output?
Posted by u/homelaberator - No votes and 1 comment
Well, experts, show me the way. Not able to get the construction right off if loop
Here is a short program, which restricts the search within the directory(how trivial it may sound to ya)
​
Alright, now running this inside a git repo produced the right output , like this ,
​
Now, running this on a normal directory i.e. not a git repo, produces this:
​
In short, it is not working as "expected" due to the logical flaw in the loop construct, I am not able to fix it.
So, shed some light. ...and please be precise.
https://redd.it/12i6gv7
@r_bash
Here is a short program, which restricts the search within the directory(how trivial it may sound to ya)
#!/usr/bin/env bash12 check_git="git -C $PWD rev-parse"34 usage()5 {6 echo Provide name with regex delimeters.-- 7 echo Example : $(basename $0) \"*bash*\"8 }910 if [ $# -eq 0 ];then11 usage12 exit 113 fi1415 local_search()16 {17 if [[ "$(eval "$check_git")" == "" ]];then1819 git grep -n "$1"2021 elif [[ ! -d .git ]];then2223 find "$PWD" -type f,d -name "$1" -ls2425 else26 :27 fi28 }2930 local_search "$@"​
Alright, now running this inside a git repo produced the right output , like this ,
~/LaTeX_Workouts [master|✔]08:15 $ local_search "tex"Bhaskar_Chowdhury.log:1:This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020 Gentoo Linux) (preloaded format=pdflatex 2020.8.23) 23 AUG 2020 10:59​
Now, running this on a normal directory i.e. not a git repo, produces this:
tp_x250_08:17:40_Tue Apr 11: :~/Music>local_search "Mark"fatal: not a git repository (or any of the parent directories): .gitfatal: not a git repository (or any of the parent directories): .git​
In short, it is not working as "expected" due to the logical flaw in the loop construct, I am not able to fix it.
So, shed some light. ...and please be precise.
https://redd.it/12i6gv7
@r_bash
Reddit
r/bash on Reddit: Well, experts, show me the way. Not able to get the construction right off if loop
Posted by u/unixbhaskar - No votes and no comments