You are not logged in.

#1 2019-12-13 15:51:54

clusterF
Member
Registered: 2019-05-07
Posts: 450

quick shell (Bash) template from commandline.

name it something like shell_template.sh

invoke it using any naming argument.

./shell_template.sh NAME

NAME being whatever you want to name the outgoing file.

It will then create and enter that file for editing smile

#!/usr/bin/env bash
set -euo pipefail
set -x

export EDITOR=geany

set +u
FILE=$1
set -u

for FILE in "$@"
do
printf "#!/usr/bin/env bash\n" > $FILE
chmod 755 $FILE
done;

$EDITOR $FILE

some modifications needed.

set up defaults for local shell scripts, i keep mine in .local/bin
$EDITOR = your default editor (or export geany as per script).

Uses unofficial bash strict mode, http://redsymbol.net/articles/unofficia … rict-mode/

edited: when using bash strict mode the script failed, re wrote the script so should work ok now.On a bit of a steep learning curve here, not sure if im understanding this well enough.

edit: made it executable

Last edited by clusterF (2019-12-14 02:45:07)


"Common sense is like deodorant, those who need it the most never use it."

git: clusterF

Offline

#2 2019-12-14 21:50:59

ohnonot
...again
Registered: 2015-09-29
Posts: 4,222
Website

Re: quick shell (Bash) template from commandline.

Does the script have to remain after starting the editor?

Maybe

exec $EDITOR $FILE

would be better.

or use 'bl-text-editor' instead of 'EDITOR'?

exec bl-text-editor $FILE

Offline

#3 2019-12-15 04:29:53

clusterF
Member
Registered: 2019-05-07
Posts: 450

Re: quick shell (Bash) template from commandline.

ohnonot wrote:

Does the script have to remain after starting the editor?

Maybe

exec $EDITOR $FILE

would be better.

or use 'bl-text-editor' instead of 'EDITOR'?

exec bl-text-editor $FILE

Im not sure about that behavior, the script seems to save the file in place with no option to save it manually in geany. Probably something im missing/dont understand and my hacky scripting.

Im in voidlinux but one could use bl-text-editor instead for sure.

Last edited by clusterF (2019-12-15 04:31:31)


"Common sense is like deodorant, those who need it the most never use it."

git: clusterF

Offline

Board footer

Powered by FluxBB