mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-13 22:02:34 +00:00
feat: Unifies webapp scripts into a single script with subcommands.
This commit is contained in:
2
env/.config/hypr/hyprkeybinds.conf
vendored
2
env/.config/hypr/hyprkeybinds.conf
vendored
@@ -16,7 +16,7 @@ $fileManager = $terminal -e yazi
|
||||
$fileBrowser = uwsm app -- nautilus
|
||||
$menu = hyprlauncher
|
||||
$scripts = ~/.local/scripts/hypr
|
||||
$pwa = $scripts/launch-webapp
|
||||
$pwa = $scripts/webapp launch
|
||||
$tmuxSessionator = ~/.local/scripts/tmux-sessionator
|
||||
$clipboardHistory = com.ghostty.clipse $terminal --class=com.ghostty.clipse -e clipse
|
||||
$uninstallDesktop = $terminal --class=com.ghostty.float -e $scripts/uninstall-desktop-app
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
# Adapted from https://github.com/basecamp/omarchy/tree/master?tab=readme-ov-file
|
||||
|
||||
THIS_FILE=${BASH_SOURCE[0]}
|
||||
THIS=$(basename "$THIS_FILE")
|
||||
THIS=${THIS:-$(basename "$THIS_FILE")}
|
||||
LOG_FILE=${LOG_FILE:-"$THIS.log"}
|
||||
LOG_LABEL=$(basename "$THIS_FILE")
|
||||
|
||||
function usage() {
|
||||
cat <<EOF
|
||||
@@ -237,7 +239,7 @@ EOF
|
||||
|
||||
# Setup logging file and label
|
||||
source "$SCRIPTS/hypr/logging"
|
||||
setup-logging "$THIS.log" "$THIS"
|
||||
setup-logging "$LOG_FILE" "$LOG_LABEL"
|
||||
export LOG_ENABLE_DRY_RUN="$dry_run"
|
||||
|
||||
if [[ -z "$XDG_DATA_HOME" ]]; then
|
||||
@@ -287,7 +289,7 @@ set_icon_ref
|
||||
|
||||
# Check that an exec command is set, or default to the 'launch-webapp' script.
|
||||
if [[ -z $exec_cmd ]]; then
|
||||
exec_cmd="$SCRIPTS/hypr/launch-webapp $app_url"
|
||||
exec_cmd="$SCRIPTS/hypr/webapp launch $app_url"
|
||||
fi
|
||||
|
||||
log "\e[032mCreating web app:\e[0m $desktop_file"
|
||||
@@ -4,7 +4,7 @@
|
||||
SCRIPTS="${SCRIPTS:-$HOME/.local/scripts}"
|
||||
THIS_FILE=${BASH_SOURCE[0]}
|
||||
LOG_LABEL=$(basename "$THIS_FILE")
|
||||
THIS=$(basename "$THIS_FILE")
|
||||
THIS=${THIS:-$(basename "$THIS_FILE")}
|
||||
LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"}
|
||||
|
||||
usage() {
|
||||
@@ -29,7 +29,7 @@ NOTES:
|
||||
|
||||
Any extra arguments after '--' get passed directly to the browser invocation.
|
||||
|
||||
$ launch-webapp https://example.com -- --some-random-flag-for-browser=1
|
||||
$ $THIS https://example.com -- --some-random-flag-for-browser=1
|
||||
|
||||
Any options passed in prior to the '--' get sent to the 'launch' script, so you can pass
|
||||
options that are not specifically shown here, but the ones shown would be the most commonly
|
||||
@@ -94,9 +94,9 @@ fi
|
||||
# Any left over args after "--"
|
||||
app_args="$@"
|
||||
|
||||
log "URL: $url"
|
||||
log "Launch args: ${launch_args[@]}"
|
||||
log "App args: ${app_args}"
|
||||
log "Launching URL: $url"
|
||||
log " Launch args: ${launch_args[@]}"
|
||||
log " App args: ${app_args}"
|
||||
|
||||
$SCRIPTS/hypr/launch "${launch_args[@]}" "$(pattern)" \
|
||||
setsid uwsm app -- $(sed -n 's/^Exec=\([^ ]*\).*/\1/p' {~/.local,~/.nix-profile,/usr}/share/applications/$browser 2>/dev/null | head -1) --app="$url" "$app_args"
|
||||
57
env/.local/scripts/hypr/webapp
vendored
Executable file
57
env/.local/scripts/hypr/webapp
vendored
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
||||
THIS_FILE=${BASH_SOURCE[0]}
|
||||
LOG_LABEL=$(basename "$THIS_FILE")
|
||||
THIS=${THIS:-$LOG_LABEL}
|
||||
LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Utility for launching or installing a progressive web app.
|
||||
|
||||
USAGE:
|
||||
$ $THIS <flags> <command>
|
||||
|
||||
FLAGS:
|
||||
-h | --help: Show this help page.
|
||||
|
||||
COMMANDS:
|
||||
install: Generate a '.desktop' file for a web app.
|
||||
launch: Launch a url as a web app.
|
||||
|
||||
RUN '$THIS <command> --help' for more information about a command.
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# Logging utility function, use in place of echo.
|
||||
log() {
|
||||
logging log --source "$THIS_FILE" "$@"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# MAIN
|
||||
################################################################################
|
||||
|
||||
# Setup logging file and label.
|
||||
source "$SCRIPTS/hypr/logging"
|
||||
setup-logging "$LOG_FILE" "$LOG_LABEL"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||
usage
|
||||
elif [[ $1 == "install" ]]; then
|
||||
shift
|
||||
THIS="$THIS install" "$SCRIPTS/hypr/utils/webapp/install" "$@"
|
||||
elif [[ $1 == "launch" ]]; then
|
||||
shift
|
||||
THIS="$THIS launch" "$SCRIPTS/hypr/utils/webapp/launch" "$@"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
4
webapp
4
webapp
@@ -51,7 +51,7 @@ log() {
|
||||
|
||||
install() {
|
||||
local file=$DEV_ENV/env/webapps/$(basename $1)
|
||||
local script="$DEV_ENV/env/.local/scripts/hypr/install-webapp"
|
||||
local script="$DEV_ENV/env/.local/scripts/hypr/webapp"
|
||||
|
||||
if [[ ! -x $script ]]; then
|
||||
log "Failed to find install web app script."
|
||||
@@ -69,7 +69,7 @@ install() {
|
||||
log "Installing webapp from spec: $file"
|
||||
|
||||
if [[ $dry_run == "0" ]]; then
|
||||
$script --file $file --no-interactive
|
||||
$script install --file $file --no-interactive
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user