Killport - A Simple Script to Kill Processes on a Port
Have you ever encountered the issue of not being able to start a process because the port is already in use? Killport is a simple noscript that allows you to quickly kill any process running on a specified port.
Using Killport is easy. Simply provide the port number as a command-line argument and the noscript will automatically find and kill any process running on that port. The noscript works on both macOS and Linux, and it is easy to install.
​
killport
Give it a try and let me know what you think.
give a ✨ star, if you liked it. Github
https://redd.it/113jses
@r_bash
Have you ever encountered the issue of not being able to start a process because the port is already in use? Killport is a simple noscript that allows you to quickly kill any process running on a specified port.
Using Killport is easy. Simply provide the port number as a command-line argument and the noscript will automatically find and kill any process running on that port. The noscript works on both macOS and Linux, and it is easy to install.
​
killport
Give it a try and let me know what you think.
give a ✨ star, if you liked it. Github
https://redd.it/113jses
@r_bash
Question How would I rewrite this command using no pipe?
Hey, today I wanted to create a tcp shell. But I don't want to write the pipe (|) symbol. Is there a way to restructure this command without breaking its functionality?
https://redd.it/113t90p
@r_bash
Hey, today I wanted to create a tcp shell. But I don't want to write the pipe (|) symbol. Is there a way to restructure this command without breaking its functionality?
nc $IP $PORT < myfifo | /bin/bash -i > myfifo 2>&https://redd.it/113t90p
@r_bash
Reddit
[Question] How would I rewrite this command using no pipe?
Posted in the bash community.
How can I run commands in parallel and write the output of each command to different linux terminals, one linux terminal for each command running in parallel.
I want to run commands in parallel with a bash noscript. I know adding the ampersand allows to run a command in background and continue with the noscript without waiting for the launched process to finish. I think the processess launched in background with ampersand do not output a log on a terminal though.
​
Is there any way to launch several commands in parallel while the output/log of each command is written to a different terminal window? I would like to see the logs of each process launched in parallel after all of them finish their execution.
Thanks
https://redd.it/1140cr2
@r_bash
I want to run commands in parallel with a bash noscript. I know adding the ampersand allows to run a command in background and continue with the noscript without waiting for the launched process to finish. I think the processess launched in background with ampersand do not output a log on a terminal though.
​
Is there any way to launch several commands in parallel while the output/log of each command is written to a different terminal window? I would like to see the logs of each process launched in parallel after all of them finish their execution.
Thanks
https://redd.it/1140cr2
@r_bash
Reddit
r/bash - How can I run commands in parallel and write the output of each command to different linux terminals, one linux terminal…
Posted in the bash community.
Turbocharge your terminal productivity with zsh-autosuggestions! (1mn)
https://www.youtube.com/watch?v=0r1mxuAzqS0
https://redd.it/1142z89
@r_bash
https://www.youtube.com/watch?v=0r1mxuAzqS0
https://redd.it/1142z89
@r_bash
YouTube
Turbocharge your terminal productivity with zsh-autosuggestions!!!
Source: https://github.com/zsh-users/zsh-autosuggestions
We're also available on:
- Twitter: https://www.twitter.com/RubyCademy
- Medium: https://www.medium.com/@rubycademy
- Reddit: https://www.reddit.com/r/rubycademy
- Tiktok: https://www.tik…
We're also available on:
- Twitter: https://www.twitter.com/RubyCademy
- Medium: https://www.medium.com/@rubycademy
- Reddit: https://www.reddit.com/r/rubycademy
- Tiktok: https://www.tik…
fun with sed/awk
i do have to say it is a bit frustrating that some binaries in freeBSD/macOS dont translate over to other *nixs..probably licensing, however..
​
i have out input in a var that reads as below, new lines and spaces:-
this is string 1
this is string two
this is string threeee
​
and so forth, i have been able to get them on to one line and get quotes on the end in the standard macOS bash scrpit, but for the love of god, i cant get it into the right format, i've tried awk, sed and tr.
​
what i need:
"this is string 1" "this is string two" "this is string threee"
grateful for any ideas..
https://redd.it/114hh6p
@r_bash
i do have to say it is a bit frustrating that some binaries in freeBSD/macOS dont translate over to other *nixs..probably licensing, however..
​
i have out input in a var that reads as below, new lines and spaces:-
this is string 1
this is string two
this is string threeee
​
and so forth, i have been able to get them on to one line and get quotes on the end in the standard macOS bash scrpit, but for the love of god, i cant get it into the right format, i've tried awk, sed and tr.
​
what i need:
"this is string 1" "this is string two" "this is string threee"
grateful for any ideas..
https://redd.it/114hh6p
@r_bash
Reddit
r/bash - fun with sed/awk
Posted in the bash community.
Show Output for Two Simultaneous Uploads
I have a noscript that uploads a file, at the same time, to two different platforms. I want to be able to see the progress of both uploads, at the same time. Here is part of my noscript:
#When the transfer is complete, attempt upload the mp4:
if [[ ! -f $SAJSON ]];
then
echo -e "No json file found. Not uploading. Please manually upload."
elif [[ {$OUTPUT} = *"Movie Info"* ]]; then
cp $SRVPATH/Archive/$yyyy/$EMAILFILENAME.mp4 \
$SRVPATH/Archive/$yyyy/$SA-ID.mp4
{ echo -e "Uploading to SA...\n" & \
rclone move $SRVPATH/Archive/$yyyy/$SA-ID.mp4 \
sa-auto:sa-id-text -P -v & echo -e "Uploading to YouTube...\n" & \
youtubeuploader -filename $SRVPATH/Archive/$yyyy/$EMAILFILENAME.mp4 \
-secrets $SRVPATH/AppData/youtubeuploader/client_secrets.json \
-cache $SRVPATH/AppData/youtubeuploader/request.token \
-metaJSON $YTJSON; } 2>&1
echo -e "\nDone.\n"
echo -e "Removing ${SAJSON##*/} & ${YTJSON##*/}\n"
rm $SAJSON $YTJSON
echo "Done."
fi
As you can see, I attempted `{ echo & command1 & echo & command2; } 2>&1` but it produces:
Uploading to SA...
Uploading to YouTube...
Uploading file '/srv/dev-disk-by-uuid-49e4aa1a-279a-45ce-b23e-467c2b2a4162/Archive/2023/2023-02-19_14-45-23.mp4'
And the rest is just the transferring status of YouTube only (I think; maybe it's a mixture?). Once YouTube completes, then it shows the other platform upload, but it als shows a weird mixture of both (my comments in the code):
Uploading to SA...
Uploading to YouTube...
#This is is YouTube:
Uploading file '/srv/dev-disk-by-uuid-49e4aa1a-279a-45ce-b23e-467c2b2a4162/Archive/2023/2023-02-19_14-45-23.mp4'
#This is SA platform:
2023-02-17 14:10:07 INFO : 2172307128007.mp4: Copied (new)
2023-02-17 14:10:07 INFO : 2172307128007.mp4: Deleted
#I'm not sure what this is:
Transferred: 56.265 MiB / 56.265 MiB, 100%, 622.384 KiB/s, ETA 0s
Checks: 2 / 2, 100%
Deleted: 1 (files), 0 (dirs)
Renamed: 1
Transferred: 1 / 1, 100%
Elapsed time: 1m18.0s
2023/02/17 14:10:07 INFO :
Transferred: 56.265 MiB / 56.265 MiB, 100%, 622.384 KiB/s, ETA 0s
Checks: 2 / 2, 100%
Deleted: 1 (files), 0 (dirs)
Renamed: 1
Transferred: 1 / 1, 100%
Elapsed time: 1m18.0s
#This is the SA platform (using Dropbox):
2023/02/17 14:10:07 INFO : Dropbox root 'sa-id-text': Commiting uploads - please wait...
Progress: 9.57 Mbps, 58998558 / 58998558 (100.000%) ETA 0s
#This is YouTube again:
Upload successful! Video ID: asdfghjkl
Video added to playlist 'Playlist Title' (qwertyuio-)
https://redd.it/114tyym
@r_bash
I have a noscript that uploads a file, at the same time, to two different platforms. I want to be able to see the progress of both uploads, at the same time. Here is part of my noscript:
#When the transfer is complete, attempt upload the mp4:
if [[ ! -f $SAJSON ]];
then
echo -e "No json file found. Not uploading. Please manually upload."
elif [[ {$OUTPUT} = *"Movie Info"* ]]; then
cp $SRVPATH/Archive/$yyyy/$EMAILFILENAME.mp4 \
$SRVPATH/Archive/$yyyy/$SA-ID.mp4
{ echo -e "Uploading to SA...\n" & \
rclone move $SRVPATH/Archive/$yyyy/$SA-ID.mp4 \
sa-auto:sa-id-text -P -v & echo -e "Uploading to YouTube...\n" & \
youtubeuploader -filename $SRVPATH/Archive/$yyyy/$EMAILFILENAME.mp4 \
-secrets $SRVPATH/AppData/youtubeuploader/client_secrets.json \
-cache $SRVPATH/AppData/youtubeuploader/request.token \
-metaJSON $YTJSON; } 2>&1
echo -e "\nDone.\n"
echo -e "Removing ${SAJSON##*/} & ${YTJSON##*/}\n"
rm $SAJSON $YTJSON
echo "Done."
fi
As you can see, I attempted `{ echo & command1 & echo & command2; } 2>&1` but it produces:
Uploading to SA...
Uploading to YouTube...
Uploading file '/srv/dev-disk-by-uuid-49e4aa1a-279a-45ce-b23e-467c2b2a4162/Archive/2023/2023-02-19_14-45-23.mp4'
And the rest is just the transferring status of YouTube only (I think; maybe it's a mixture?). Once YouTube completes, then it shows the other platform upload, but it als shows a weird mixture of both (my comments in the code):
Uploading to SA...
Uploading to YouTube...
#This is is YouTube:
Uploading file '/srv/dev-disk-by-uuid-49e4aa1a-279a-45ce-b23e-467c2b2a4162/Archive/2023/2023-02-19_14-45-23.mp4'
#This is SA platform:
2023-02-17 14:10:07 INFO : 2172307128007.mp4: Copied (new)
2023-02-17 14:10:07 INFO : 2172307128007.mp4: Deleted
#I'm not sure what this is:
Transferred: 56.265 MiB / 56.265 MiB, 100%, 622.384 KiB/s, ETA 0s
Checks: 2 / 2, 100%
Deleted: 1 (files), 0 (dirs)
Renamed: 1
Transferred: 1 / 1, 100%
Elapsed time: 1m18.0s
2023/02/17 14:10:07 INFO :
Transferred: 56.265 MiB / 56.265 MiB, 100%, 622.384 KiB/s, ETA 0s
Checks: 2 / 2, 100%
Deleted: 1 (files), 0 (dirs)
Renamed: 1
Transferred: 1 / 1, 100%
Elapsed time: 1m18.0s
#This is the SA platform (using Dropbox):
2023/02/17 14:10:07 INFO : Dropbox root 'sa-id-text': Commiting uploads - please wait...
Progress: 9.57 Mbps, 58998558 / 58998558 (100.000%) ETA 0s
#This is YouTube again:
Upload successful! Video ID: asdfghjkl
Video added to playlist 'Playlist Title' (qwertyuio-)
https://redd.it/114tyym
@r_bash
Reddit
r/bash - Show Output for Two Simultaneous Uploads
Posted in the bash community.
Script to change system spelling language
Right now I'm using an AppleScript to do this, but the noscript is a bit long to execute, plus it shows some UI elements and I'd like for the process to be hidden.
Is there a defaults write command that would allow to toggle the system spelling language between US English and French?, or at least to switch from one to the other?
Thanks.
https://redd.it/114wjw1
@r_bash
Right now I'm using an AppleScript to do this, but the noscript is a bit long to execute, plus it shows some UI elements and I'd like for the process to be hidden.
Is there a defaults write command that would allow to toggle the system spelling language between US English and French?, or at least to switch from one to the other?
Thanks.
https://redd.it/114wjw1
@r_bash
Reddit
r/bash - Script to change system spelling language
Posted in the bash community.
posix Properly store positional arguments in string
I have the following noscript:
cmd="rg --ignore-case --files-with-matches {q} $@"
file=$(
FZFDEFAULTCOMMAND="rg --files $@" fzf \
--bind "ctrl-a:select-all" \
--bind "change:reload:$cmd" \
--disabled \
--preview "rg --ignore-case --pretty --context 2 {q} {}"
)
Here I store the positional arguments (paths for rg to search from) into the string variable
To test, I made a directory with a space in its name and ensures it should containing a match, then past this as an argument to the noscript quoted. Sure enough, it doesn't show up so apparently the directory named "test me" is not interpreted as "test" "me" where the quotes are lost.
So is the issue here that "quotes" are lost since POSIX doesn't support arrays, making everything space delimited, which is problematic when you also have spaces in the arguments? How would I go about properly storing the positioning arguments with them quoted to account for spaces in the
Essentially, the line
--bind "change:reload:rg --ignore-case --files-with-matches {q} '/home/user/bin' '/home/user/test me'" \
when the noscript is passed the arguments:
Much appreciated.
https://redd.it/1150jis
@r_bash
I have the following noscript:
cmd="rg --ignore-case --files-with-matches {q} $@"
file=$(
FZFDEFAULTCOMMAND="rg --files $@" fzf \
--bind "ctrl-a:select-all" \
--bind "change:reload:$cmd" \
--disabled \
--preview "rg --ignore-case --pretty --context 2 {q} {}"
)
Here I store the positional arguments (paths for rg to search from) into the string variable
$cmd, which is then passed as a literal string in --bind "change:reload:$cmd" \. However, shellcheck throws an error regarding assigning array to string that I don't understand if it's relevant.To test, I made a directory with a space in its name and ensures it should containing a match, then past this as an argument to the noscript quoted. Sure enough, it doesn't show up so apparently the directory named "test me" is not interpreted as "test" "me" where the quotes are lost.
So is the issue here that "quotes" are lost since POSIX doesn't support arrays, making everything space delimited, which is problematic when you also have spaces in the arguments? How would I go about properly storing the positioning arguments with them quoted to account for spaces in the
cmd string then? I'm pretty sure the suggested solution from shellcheck does not apply--the page doesn't mention any sort of quoting issue either.Essentially, the line
--bind "change:reload:$cmd" \ should be expanded to e.g. --bind "change:reload:rg --ignore-case --files-with-matches {q} '/home/user/bin' '/home/user/test me'" \
when the noscript is passed the arguments:
~/bin "~/test me"Much appreciated.
https://redd.it/1150jis
@r_bash
File with a variable of the date as part of the filename.
I am trying to use bash to create a backup of an existing file with a variable of the date as part of the filename.
This is the output I get
When looking in the file directory with a file manager I can see that is the only file that exists and it just keeps getting overwritten. sorry if this is a silly issue but I'm new to bash and I looked for about an hour on various forums and how to guides but was not able to find the solution.
https://redd.it/1159gor
@r_bash
I am trying to use bash to create a backup of an existing file with a variable of the date as part of the filename.
#!/bin/bash
dateandtime= date +%F-%H-%M-%S
sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist${dateandtime}.bak
echo "Mirror file backup created: /etc/pacman.d/mirrorlist${dateandtime}.bak"
sudo reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
echo "Mirror list update complete."
This is the output I get
Mirror file backup created: /etc/pacman.d/mirrorlist.bak
When looking in the file directory with a file manager I can see that is the only file that exists and it just keeps getting overwritten. sorry if this is a silly issue but I'm new to bash and I looked for about an hour on various forums and how to guides but was not able to find the solution.
https://redd.it/1159gor
@r_bash
Reddit
r/bash - File with a variable of the date as part of the filename.
Posted in the bash community.
Need helping figuring out what's wrong with this noscript on MacOS
I'm currently trying to turn some bash noscript that's in the form of a '.command' file into an App/Quickaction that can be run, using Automator on MacOS.
This is the original noscript: \(pastbin link\)
This is as far as I've gotten: \(pastebin link\)
When running the noscript, the finder window appears to choose a folder, I get a GUI popup to input a password, but then I get this error:
The action “Run Shell Script” encountered an error: “-: -c: line 143: syntax error: unexpected end of file”
I'm not really sure how to end this noscript, googling is not helping in this specific case either.
Any help would be appreciated!
https://redd.it/115a407
@r_bash
I'm currently trying to turn some bash noscript that's in the form of a '.command' file into an App/Quickaction that can be run, using Automator on MacOS.
This is the original noscript: \(pastbin link\)
This is as far as I've gotten: \(pastebin link\)
When running the noscript, the finder window appears to choose a folder, I get a GUI popup to input a password, but then I get this error:
The action “Run Shell Script” encountered an error: “-: -c: line 143: syntax error: unexpected end of file”
I'm not really sure how to end this noscript, googling is not helping in this specific case either.
Any help would be appreciated!
https://redd.it/115a407
@r_bash
Pastebin
#!/bin/bashfunction folder_dialog(){ local result=$(osanoscript << EOT - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
How to force a noscript to wait for its child gnome-terminal windows to finish before continuing its own execution
How can I force a noscript to wait for its child gnome-terminal windows to finish before continuing its own execution? When I run the noscript below, the father noscript does not wait for the children to finish execution and outputs "Finished" while they are still running.
I have this code:
gnome-terminal -- bash -c "cd /home;find . -name "foo" | tee /home/$USER/log-home.txt";
gnome-terminal -- bash -c "cd /home/$USER; find . -name "foo" | tee /home/$USER/log-$USER.txt";
wait;
echo "Finished";
Thanks
https://redd.it/115cwde
@r_bash
How can I force a noscript to wait for its child gnome-terminal windows to finish before continuing its own execution? When I run the noscript below, the father noscript does not wait for the children to finish execution and outputs "Finished" while they are still running.
I have this code:
gnome-terminal -- bash -c "cd /home;find . -name "foo" | tee /home/$USER/log-home.txt";
gnome-terminal -- bash -c "cd /home/$USER; find . -name "foo" | tee /home/$USER/log-$USER.txt";
wait;
echo "Finished";
Thanks
https://redd.it/115cwde
@r_bash
Reddit
r/bash - How to force a noscript to wait for its child gnome-terminal windows to finish before continuing its own execution
Posted in the bash community.
mapping to control key
Hi,
is it possible to map a function key (f9 say) to a key with control-prefix (control-n say)?
I have tried
bind "\e20~":"\C-n"
But that does not work...
Many thanks.
[https://redd.it/115hree
@r_bash
Hi,
is it possible to map a function key (f9 say) to a key with control-prefix (control-n say)?
I have tried
bind "\e20~":"\C-n"
But that does not work...
Many thanks.
[https://redd.it/115hree
@r_bash
Reddit
r/bash on Reddit: mapping to control key
Posted by u/ghiste - No votes and no comments
Trouble finding info on for loops that include and print out user input?
I can't seem to find any examples online of a noscript that repeats user input to stdout a certain number of times??
#!/bin/bash
# Display message 5 times
for ((i = 0 ; i < 5 ; i++)); do
echo "Welcome $i times."
done
Here's a C-style for loop but what if I want to repeat a string, like "look at this repeat" for a set amount of times? I feel incredibly dumb I can't do this.
https://redd.it/115k1ot
@r_bash
I can't seem to find any examples online of a noscript that repeats user input to stdout a certain number of times??
#!/bin/bash
# Display message 5 times
for ((i = 0 ; i < 5 ; i++)); do
echo "Welcome $i times."
done
Here's a C-style for loop but what if I want to repeat a string, like "look at this repeat" for a set amount of times? I feel incredibly dumb I can't do this.
https://redd.it/115k1ot
@r_bash
Reddit
r/bash - Trouble finding info on for loops that include and print out user input?
Posted in the bash community.
Bash on M2 not accepting multi-line code.
Previously, I've always been able to paste my noscripts into iTerm/ Bash 5 without issue. Ever since migrating from the 2018 mini to the 2023 M2 Mac mini, no multi-line code seems to work. I'm even having trouble running noscripts "./mynoscript.sh" after chmod of 777. Am I going crazy?
https://redd.it/11603we
@r_bash
Previously, I've always been able to paste my noscripts into iTerm/ Bash 5 without issue. Ever since migrating from the 2018 mini to the 2023 M2 Mac mini, no multi-line code seems to work. I'm even having trouble running noscripts "./mynoscript.sh" after chmod of 777. Am I going crazy?
https://redd.it/11603we
@r_bash
Reddit
r/bash - Bash on M2 not accepting multi-line code.
Posted in the bash community.
I have files in .epub and .mobi format, most are in both formats, but I want to find out (recursively) if any are in one format only
Just to make it clear, the basenames are the same, only the extensions differ if a file is in both formats. Files could be anywhere in a directory tree, but always grouped together.
Is there an easy way (which I can't think of at the moment) to spit out the unique files in one format which have no counterpart in the other format?
https://redd.it/116kl4b
@r_bash
Just to make it clear, the basenames are the same, only the extensions differ if a file is in both formats. Files could be anywhere in a directory tree, but always grouped together.
Is there an easy way (which I can't think of at the moment) to spit out the unique files in one format which have no counterpart in the other format?
https://redd.it/116kl4b
@r_bash
Reddit
r/bash - I have files in .epub and .mobi format, most are in both formats, but I want to find out (recursively) if any are in one…
Posted in the bash community.
bash-completor: Creating a bash completion noscript in a declarative way
Writing a [programmable completion](https://www.gnu.org/software/bash/manual/html_node/A-Programmable-Completion-Example.html) for Bash is difficult for novices. It may take much time on debugging.
Even though there is a library of completion noscripts like [scop/bash-completion](https://github.com/scop/bash-completion), it only includes common commands. For some commands that are not commonly used, we have to write completion noscripts by hand.
To reduce the painful time developers spend with developing, I created [bash-completor](https://github.com/adoyle-h/bash-completor).
It is a Bash completion noscript generator written in bash noscript. It provides a declarative way to help developer to implement bash completions quickly.
## Feature
* Declarative programming. You only need to know the most basic bash syntax.
* Only `bash` and `sed` are needed on at compile time. Only `bash` is needed on at runtime. No other dependencies.
* Support for command format looks like `<cmd> [options] [arguments]`.
* Support for sub-commands, which looks like \`<cmd> \[cmd-options\] <subcmd> \[subcmd-options\] \[arguments\]\`.
* Support for `-o`, `--option`, `--option <value>`, `--option=`, `+o`, `+option` format.
* Support for completing file or directory paths.
* Support for completing word lists.
* Support for custom completion functions.
* Friendly config typo checking and suggestions.
## Requirements
* For building noscript.
* Bash v4.3+
* cat, sed (GNU or BSD compatible)
* For runtime.
* Bash v4.0+
# [Installation](https://github.com/adoyle-h/bash-completor#installation)
## Usage
Take the example of creating bash-completor's own completion noscript.
First, create the configuration file `completor.bash`.
The configuration file is also written in Bash syntax. You only need to know the most basic Bash syntax.
output=dist/bash-completor.completion.bash
authors=('ADoyle (adoyle.h@gmail.com)')
cmd=bash-completor
cmd_opts=(
-c:@files
-h --help
--version
)
That's all. Then execute `bash-completor -c ./completor.bash` to generate the completion noscript. Done.
For complex examples, see below links.
* [zig.completor.bash](https://github.com/ziglang/shell-completions/blob/master/zig.completor.bash)
* [nvim-shell-completions/nvim.completor.bash](https://github.com/adoyle-h/nvim-shell-completions/blob/master/nvim.completor.bash)
* [Other examples](https://github.com/adoyle-h/bash-completor/tree/master/example)
Read [this document](https://github.com/adoyle-h/bash-completor/blob/master/docs/syntax.md) for the syntax.
## The completion noscript
The generated completion noscript follows below code style. No worry about naming conflict. And it's easy to debug at runtime.
* The main command completion function must be `_${cmd}_completions`
* All subcmd completion functions must be named with prefix `_${cmd}_completions_${subcmd}`
* All other variables and functions must be named with prefix `_${cmd}_comp_`
* The variable of main command options must be `_${cmd}_comp_cmd_opts`
* The variable of subcmd options must be named with prefix `_${cmd}_comp_subcmd_opts_${subcmd}`
* All reply functions must be named with prefix `_${cmd}_comp_reply_`
* All customized reply functions must be named with prefix `_${cmd}_comp_reply_custom_`
​
If you like it, please give a star to the repo. [https://github.com/adoyle-h/bash-completor](https://github.com/adoyle-h/bash-completor)
https://redd.it/116qbw9
@r_bash
Writing a [programmable completion](https://www.gnu.org/software/bash/manual/html_node/A-Programmable-Completion-Example.html) for Bash is difficult for novices. It may take much time on debugging.
Even though there is a library of completion noscripts like [scop/bash-completion](https://github.com/scop/bash-completion), it only includes common commands. For some commands that are not commonly used, we have to write completion noscripts by hand.
To reduce the painful time developers spend with developing, I created [bash-completor](https://github.com/adoyle-h/bash-completor).
It is a Bash completion noscript generator written in bash noscript. It provides a declarative way to help developer to implement bash completions quickly.
## Feature
* Declarative programming. You only need to know the most basic bash syntax.
* Only `bash` and `sed` are needed on at compile time. Only `bash` is needed on at runtime. No other dependencies.
* Support for command format looks like `<cmd> [options] [arguments]`.
* Support for sub-commands, which looks like \`<cmd> \[cmd-options\] <subcmd> \[subcmd-options\] \[arguments\]\`.
* Support for `-o`, `--option`, `--option <value>`, `--option=`, `+o`, `+option` format.
* Support for completing file or directory paths.
* Support for completing word lists.
* Support for custom completion functions.
* Friendly config typo checking and suggestions.
## Requirements
* For building noscript.
* Bash v4.3+
* cat, sed (GNU or BSD compatible)
* For runtime.
* Bash v4.0+
# [Installation](https://github.com/adoyle-h/bash-completor#installation)
## Usage
Take the example of creating bash-completor's own completion noscript.
First, create the configuration file `completor.bash`.
The configuration file is also written in Bash syntax. You only need to know the most basic Bash syntax.
output=dist/bash-completor.completion.bash
authors=('ADoyle (adoyle.h@gmail.com)')
cmd=bash-completor
cmd_opts=(
-c:@files
-h --help
--version
)
That's all. Then execute `bash-completor -c ./completor.bash` to generate the completion noscript. Done.
For complex examples, see below links.
* [zig.completor.bash](https://github.com/ziglang/shell-completions/blob/master/zig.completor.bash)
* [nvim-shell-completions/nvim.completor.bash](https://github.com/adoyle-h/nvim-shell-completions/blob/master/nvim.completor.bash)
* [Other examples](https://github.com/adoyle-h/bash-completor/tree/master/example)
Read [this document](https://github.com/adoyle-h/bash-completor/blob/master/docs/syntax.md) for the syntax.
## The completion noscript
The generated completion noscript follows below code style. No worry about naming conflict. And it's easy to debug at runtime.
* The main command completion function must be `_${cmd}_completions`
* All subcmd completion functions must be named with prefix `_${cmd}_completions_${subcmd}`
* All other variables and functions must be named with prefix `_${cmd}_comp_`
* The variable of main command options must be `_${cmd}_comp_cmd_opts`
* The variable of subcmd options must be named with prefix `_${cmd}_comp_subcmd_opts_${subcmd}`
* All reply functions must be named with prefix `_${cmd}_comp_reply_`
* All customized reply functions must be named with prefix `_${cmd}_comp_reply_custom_`
​
If you like it, please give a star to the repo. [https://github.com/adoyle-h/bash-completor](https://github.com/adoyle-h/bash-completor)
https://redd.it/116qbw9
@r_bash
www.gnu.org
A Programmable Completion Example (Bash Reference Manual)
Previous: Programmable Completion Builtins, Up: Command Line Editing [Contents][Index]
New subreddit dedicated only to POSIX-compliant shell noscripting (bashisms stay here)
https://www.reddit.com/r/posixshell
https://redd.it/1170u3l
@r_bash
https://www.reddit.com/r/posixshell
https://redd.it/1170u3l
@r_bash
reddit
r/posixshell
r/posixshell: Community for asking questions and discussing about the POSIX shell
How to add an input that is actually multiple hexadecimal elements
I have an input like this
“30 0A 0F” that is enter into the command line
I’m not sure how to loop through and add these numbers. I have tried using printf but I don’t have a decimal to hex conversion. I need these strings to individually be casted hexadecimal as is.
How can I do this?
https://redd.it/117gs0u
@r_bash
I have an input like this
“30 0A 0F” that is enter into the command line
I’m not sure how to loop through and add these numbers. I have tried using printf but I don’t have a decimal to hex conversion. I need these strings to individually be casted hexadecimal as is.
How can I do this?
https://redd.it/117gs0u
@r_bash
Reddit
r/bash on Reddit: How to add an input that is actually multiple hexadecimal elements
Posted by u/marathonEngineer - No votes and 1 comment
How to edit my git command to output requested data using string separator?
Using git I'm getting a list of all large files in a repo. The command looks scary but it's really just pulling data and then doing some data engineering.
git rev-list --objects --all |
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' %(id)' |
sed -n 's/^blob //p' |
sort --numeric-sort --key=2 |
gcut -c 1-12,41- |
$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
Here is an example output of what the noscript above pumps out:
I would like to use a semi-colon as a delimiter between each datapoint called in the command. So the expected output would be like this:
I can do so like this:
git rev-list --objects --all |git cat-file --batch-check='%(objectname);%(objecttype);'
Adding semi-colons in between each git object. But for some reason when I combine everything together, the noscript does not work?
How can I fix my noscript below to get it working and add semi-colon separators for my --batch-check param?
git rev-list --objects --all | git cat-file --batch-check='%(objecttype);%(objectname);%(objectsize);%(rest)' | sed -n 's/^blob //p' | awk '$2 >= 2^20' | sort --numeric-sort --key=2 | gcut -c 1-12,41- |$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=1 --round=nearest
https://redd.it/117li9u
@r_bash
Using git I'm getting a list of all large files in a repo. The command looks scary but it's really just pulling data and then doing some data engineering.
git rev-list --objects --all |
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' %(id)' |
sed -n 's/^blob //p' |
sort --numeric-sort --key=2 |
gcut -c 1-12,41- |
$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
Here is an example output of what the noscript above pumps out:
ne3ee2e43e12 1.0MiB path/to/large/files.png IDI would like to use a semi-colon as a delimiter between each datapoint called in the command. So the expected output would be like this:
ne3ee2e43e1x; 1.0MiB; path/to/large/files.png; ID I can do so like this:
git rev-list --objects --all |git cat-file --batch-check='%(objectname);%(objecttype);'
Adding semi-colons in between each git object. But for some reason when I combine everything together, the noscript does not work?
How can I fix my noscript below to get it working and add semi-colon separators for my --batch-check param?
git rev-list --objects --all | git cat-file --batch-check='%(objecttype);%(objectname);%(objectsize);%(rest)' | sed -n 's/^blob //p' | awk '$2 >= 2^20' | sort --numeric-sort --key=2 | gcut -c 1-12,41- |$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=1 --round=nearest
https://redd.it/117li9u
@r_bash
Reddit
r/bash on Reddit
How to edit my git command to output requested data using string separator?
Script cannot use text file given as command line arguments
Practicing some basic bash to prepare for a new job. I am using a cygwin terminal on windows 10.
I am trying to output the text from a file (numbers.txt in my cwd) which I am entering as parameter with this line.
​
cat $1
​
I keep getting this error
​
cat: 'numbers.txt'$'\\r': No such file or directory
​
What am I doing wrong?
https://redd.it/117mqzt
@r_bash
Practicing some basic bash to prepare for a new job. I am using a cygwin terminal on windows 10.
I am trying to output the text from a file (numbers.txt in my cwd) which I am entering as parameter with this line.
​
cat $1
​
I keep getting this error
​
cat: 'numbers.txt'$'\\r': No such file or directory
​
What am I doing wrong?
https://redd.it/117mqzt
@r_bash
Reddit
r/bash on Reddit
Script cannot use text file given as command line arguments
how do I use/save bash files on windows and execute?
i tried looking it up but i either see download extension for my code editor which hasnt worked or use linux which i can't rn. is there something im missing?
Edit: solved
I used vs code and ctrl + shift +p then selected default profile and chose bash which let me execute the bash file
https://redd.it/117mdtv
@r_bash
i tried looking it up but i either see download extension for my code editor which hasnt worked or use linux which i can't rn. is there something im missing?
Edit: solved
I used vs code and ctrl + shift +p then selected default profile and chose bash which let me execute the bash file
https://redd.it/117mdtv
@r_bash
Reddit
r/bash - how do I use/save bash files on windows and execute?
Posted in the bash community.