mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12: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
|
||||
31
run
31
run
@@ -1,5 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Adapted from https://github.com/ThePrimeagen/dev/blob/master/run
|
||||
#
|
||||
# Runs scripts in the `./runs` directory, which will install or uninstall
|
||||
# packages. It either runs a single script given an argument (filename in runs)
|
||||
# or all scripts in the runs directory.
|
||||
#
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
||||
|
||||
if [ -z "$DEV_ENV" ]; then
|
||||
@@ -14,7 +21,6 @@ export DEV_ENV="$DEV_ENV"
|
||||
grep=""
|
||||
dry_run="0"
|
||||
uninstall="0"
|
||||
create="0"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
echo "ARG: \"$1\""
|
||||
@@ -25,9 +31,6 @@ while [[ $# -gt 0 ]]; do
|
||||
# Handle an --uninstall argument
|
||||
elif [[ "$1" =~ ^--u ]]; then
|
||||
uninstall="1"
|
||||
# Handle an --uninstall argument
|
||||
elif [[ "$1" =~ ^--c ]]; then
|
||||
create="1"
|
||||
# Handle an --install argument (default)
|
||||
elif [[ ! "$1" =~ ^--i ]]; then
|
||||
grep="$1"
|
||||
@@ -43,21 +46,6 @@ log() {
|
||||
fi
|
||||
}
|
||||
|
||||
generate-new-run() {
|
||||
local file="$script_dir/runs/$1"
|
||||
if [ -f "$file" ]; then
|
||||
log "File exists: $file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Creating new run: $file"
|
||||
|
||||
printf "#!/usr/bin/env bash\n\n" >$file
|
||||
printf "yay \${1:-\"-S --noconfirm\"} # packages\n" >>$file
|
||||
|
||||
chmod +x $file
|
||||
}
|
||||
|
||||
run() {
|
||||
local script=$1
|
||||
local flag=$2
|
||||
@@ -76,10 +64,7 @@ run() {
|
||||
|
||||
}
|
||||
|
||||
if [[ "$create" == "1" ]]; then
|
||||
generate-new-run "$grep"
|
||||
exit 0
|
||||
fi
|
||||
############################## MAIN ##############################
|
||||
|
||||
log "RUN: env: $env -- grep: $grep"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user