mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-13 22:02:34 +00:00
feat: Adds gen script to generate new runs or webapps.
This commit is contained in:
83
gen
Executable file
83
gen
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Generates a new run file or webapp file.
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
||||
|
||||
if [ -z "$DEV_ENV" ]; then
|
||||
echo "env var DEV_ENV needs to be present"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
file=""
|
||||
run="0"
|
||||
webapp="0"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
echo "Arg: \"$1\""
|
||||
|
||||
if [[ "$1" == "run" ]]; then
|
||||
run="1"
|
||||
elif [[ "$1" == "webapp" ]]; then
|
||||
webapp="1"
|
||||
else
|
||||
file="$1"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
log() { echo "$1"; }
|
||||
|
||||
generate-new-run() {
|
||||
local dest="$script_dir/runs/$file"
|
||||
if [ -f "$dest" ]; then
|
||||
log "file exists: $dest"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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-new-webapp() {
|
||||
|
||||
local dest="$script_dir/webapps/$file"
|
||||
|
||||
if [[ ! $dest =~ \.json$ ]]; then
|
||||
dest="$dest.json"
|
||||
fi
|
||||
|
||||
if [ -f "$dest" ]; then
|
||||
log "dest exists: $dest"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
############################## MAIN ##############################
|
||||
|
||||
if [[ -z "$file" ]]; then
|
||||
log "No file name supplied."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $run == "1" ]]; then
|
||||
generate-new-run
|
||||
elif [[ $webapp == "1" ]]; then
|
||||
generate-new-webapp
|
||||
else
|
||||
log "Must supply either \"run\" or \"webapp\" option."
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user