mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
95 lines
1.7 KiB
Bash
Executable File
95 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Generates a new run, webapp, or script file.
|
|
|
|
if [ -z "$DEV_ENV" ]; then
|
|
echo "env var DEV_ENV needs to be present"
|
|
exit 1
|
|
fi
|
|
|
|
file=""
|
|
run="0"
|
|
webapp="0"
|
|
script="0"
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
echo "Arg: \"$1\""
|
|
|
|
if [[ "$1" == "run" ]]; then
|
|
run="1"
|
|
elif [[ "$1" == "webapp" ]]; then
|
|
webapp="1"
|
|
elif [[ "$1" == "script" ]]; then
|
|
script="1"
|
|
else
|
|
file="$1"
|
|
fi
|
|
shift
|
|
done
|
|
|
|
log() { echo "$1"; }
|
|
|
|
fail_if_exists() {
|
|
if [[ -f $1 ]]; then
|
|
log "file exists: $dest"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
generate_run() {
|
|
local dest="$DEV_ENV/runs/$file"
|
|
fail_if_exists $dest
|
|
log "Creating new run: $dest"
|
|
printf "#!/usr/bin/env bash\n\n" >$dest
|
|
printf "yay \${1:-\"-S --noconfirm\"} # packages\n" >>$dest
|
|
|
|
chmod +x $dest
|
|
}
|
|
|
|
generate_webapp() {
|
|
|
|
local dest="$DEV_ENV/env/webapps/$file"
|
|
|
|
if [[ ! $dest =~ \.json$ ]]; then
|
|
dest="$dest.json"
|
|
fi
|
|
|
|
fail_if_exists $dest
|
|
|
|
log "Creating new webapp: $dest"
|
|
|
|
printf "{\n" >$dest
|
|
printf " \"name\": \"My App\",\n" >>$dest
|
|
printf " \"url\": \"https://example.com\",\n" >>$dest
|
|
printf " \"icon\": \"https://icon.com\"\n" >>$dest
|
|
printf "}" >>$dest
|
|
|
|
}
|
|
|
|
generate_script() {
|
|
local dest="$DEV_ENV/env/.local/scripts/$file"
|
|
fail_if_exists $dest
|
|
log "Creating new script: $dest"
|
|
printf "#!/usr/bin/env bash\n\n" >$dest
|
|
chmod +x $dest
|
|
echo $dest
|
|
}
|
|
|
|
############################## MAIN ##############################
|
|
|
|
if [[ -z "$file" ]]; then
|
|
log "No file name supplied."
|
|
exit 1
|
|
fi
|
|
|
|
if [[ $run == "1" ]]; then
|
|
generate_run
|
|
elif [[ $webapp == "1" ]]; then
|
|
generate_webapp
|
|
elif [[ $script == "1" ]]; then
|
|
generate_script
|
|
else
|
|
log "Must supply either \"run\", \"webapp\", or \"script\" option."
|
|
exit 1
|
|
fi
|