Add basic scripts from my linux machine
This commit is contained in:
60
autoscript
Executable file
60
autoscript
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
oldIFS=$IFS
|
||||
|
||||
help() {
|
||||
echo "Usage: ${0##*/} [-l lang][-h] FILENAME"
|
||||
echo "Supported languages: python, crystal, bash (default)"
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ];then
|
||||
help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
read -d '' bashShebang << 'EOF' || true
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
IFS=$'\\n\\t'
|
||||
EOF
|
||||
|
||||
read -d '' pythonShebang << EOF || true
|
||||
#!/usr/bin/env python
|
||||
EOF
|
||||
|
||||
read -d '' crystalShebang << EOF || true
|
||||
#!/usr/bin/env crystal
|
||||
EOF
|
||||
|
||||
shebang=$bashShebang
|
||||
|
||||
while getopts ":hl:" opt;do
|
||||
if [ $opt == "h" ];then
|
||||
help
|
||||
exit 0
|
||||
else
|
||||
case $OPTARG in
|
||||
py | python)shebang=$pythonShebang ;;
|
||||
cr | crystal)shebang=$crystalShebang ;;
|
||||
sh | bash | shell | *)shebang=$bashShebang ;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
SCRIPT_FOLDER=$HOME/.local/bin
|
||||
SCRIPT_FILE=$SCRIPT_FOLDER/$1
|
||||
|
||||
if [[ -f $SCRIPT_FILE ]]; then
|
||||
$EDITOR $SCRIPT_FILE
|
||||
else
|
||||
touch $SCRIPT_FILE
|
||||
chmod +x $SCRIPT_FILE
|
||||
echo "$shebang" >> $SCRIPT_FILE
|
||||
$EDITOR $SCRIPT_FILE
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user