Skip to content

Commit 5e5f06f

Browse files
author
Waylon S. Walker
committed
feat(bin): add webapps installer inspired by DHH/omacom
1 parent 0d0cfe8 commit 5e5f06f

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* feat(container): add /usr/local/bin/aws for aws cli v2
1111
* feat(zsh): add gi git ignore tool
1212
* feat(templates): add daily and glossary templates
13+
* feat(bin): add webapps installer inspired by DHH/omacom
1314

1415
## 0.1.3
1516

bin/.local/bin/webapps

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
if [[ -z "$BROWSER" ]]; then
3+
DEFAULT_BROWSER_DESKTOP=$(xdg-settings get default-web-browser 2>/dev/null)
4+
5+
if [[ -n "$DEFAULT_BROWSER_DESKTOP" ]]; then
6+
# Extract the Exec line from the .desktop file
7+
if [[ -f "/usr/share/applications/$DEFAULT_BROWSER_DESKTOP" ]]; then
8+
BROWSER_EXEC=$(grep -m1 '^Exec=' "/usr/share/applications/$DEFAULT_BROWSER_DESKTOP")
9+
elif [[ -f "$HOME/.local/share/applications/$DEFAULT_BROWSER_DESKTOP" ]]; then
10+
BROWSER_EXEC=$(grep -m1 '^Exec=' "$HOME/.local/share/applications/$DEFAULT_BROWSER_DESKTOP")
11+
fi
12+
13+
# Clean up the Exec command (strip placeholders like %u, %U)
14+
BROWSER=$(echo "$BROWSER_EXEC" | sed -E 's/^Exec=//' | sed -E 's/ ?%[a-zA-Z]//g')
15+
fi
16+
17+
# If we couldn't detect it from .desktop, try common fallbacks
18+
for candidate in brave chromium google-chrome firefox; do
19+
if command -v $candidate >/dev/null && [[ -z "$BROWSER" ]]; then
20+
BROWSER=$candidate
21+
fi
22+
done
23+
24+
# Final fallback
25+
export BROWSER="${BROWSER:-xdg-open}"
26+
fi
27+
28+
# Create a desktop launcher for a web app
29+
web2app() {
30+
if [ "$#" -ne 3 ]; then
31+
echo "Usage: web2app <AppName> <AppURL> <IconURL> (IconURL must be in PNG -- use https://dashboardicons.com)"
32+
return 1
33+
fi
34+
35+
local APP_NAME="$1"
36+
local APP_URL="$2"
37+
local ICON_URL="$3"
38+
local ICON_DIR="$HOME/.local/share/applications/icons"
39+
local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop"
40+
local ICON_PATH="${ICON_DIR}/${APP_NAME}.png"
41+
42+
mkdir -p "$ICON_DIR"
43+
44+
if ! curl -sL -o "$ICON_PATH" "$ICON_URL"; then
45+
echo "Error: Failed to download icon."
46+
return 1
47+
fi
48+
49+
cat >"$DESKTOP_FILE" <<EOF
50+
[Desktop Entry]
51+
Version=1.0
52+
Name=$APP_NAME
53+
Comment=$APP_NAME
54+
Exec=$BROWSER --new-window --ozone-platform=wayland --app="$APP_URL" --name="$APP_NAME" --class="$APP_NAME"
55+
Terminal=false
56+
Type=Application
57+
Icon=$ICON_PATH
58+
StartupNotify=true
59+
EOF
60+
61+
chmod +x "$DESKTOP_FILE"
62+
}
63+
64+
web2app-remove() {
65+
if [ "$#" -ne 1 ]; then
66+
echo "Usage: web2app-remove <AppName>"
67+
return 1
68+
fi
69+
70+
local APP_NAME="$1"
71+
local ICON_DIR="$HOME/.local/share/applications/icons"
72+
local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop"
73+
local ICON_PATH="${ICON_DIR}/${APP_NAME}.png"
74+
75+
rm "$DESKTOP_FILE"
76+
rm "$ICON_PATH"
77+
}
78+
79+
web2app "Twitter" https://x.com/ https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/x-light.png
80+
web2app "ChatGPT" https://chatgpt.com/ https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/chatgpt.png
81+
web2app "Google Messages" https://messages.google.com/web/conversations https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/google-messages.png
82+
web2app "Frigate" https://frigate.wayl.one/ https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/frigate.png
83+
web2app "reader" https://reader.waylonwalker.com/ https://waylonwalker.com/8bitcc.png

zsh/.zshrc

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,82 @@ wfetch
222222

223223
eval "$(atuin init zsh)"
224224

225+
if [[ -z "$BROWSER" ]]; then
226+
DEFAULT_BROWSER_DESKTOP=$(xdg-settings get default-web-browser 2>/dev/null)
227+
228+
if [[ -n "$DEFAULT_BROWSER_DESKTOP" ]]; then
229+
# Extract the Exec line from the .desktop file
230+
if [[ -f "/usr/share/applications/$DEFAULT_BROWSER_DESKTOP" ]]; then
231+
BROWSER_EXEC=$(grep -m1 '^Exec=' "/usr/share/applications/$DEFAULT_BROWSER_DESKTOP")
232+
elif [[ -f "$HOME/.local/share/applications/$DEFAULT_BROWSER_DESKTOP" ]]; then
233+
BROWSER_EXEC=$(grep -m1 '^Exec=' "$HOME/.local/share/applications/$DEFAULT_BROWSER_DESKTOP")
234+
fi
235+
236+
# Clean up the Exec command (strip placeholders like %u, %U)
237+
BROWSER=$(echo "$BROWSER_EXEC" | sed -E 's/^Exec=//' | sed -E 's/ ?%[a-zA-Z]//g')
238+
fi
239+
240+
# If we couldn't detect it from .desktop, try common fallbacks
241+
for candidate in brave chromium google-chrome firefox; do
242+
if command -v $candidate >/dev/null && [[ -z "$BROWSER" ]]; then
243+
BROWSER=$candidate
244+
fi
245+
done
246+
247+
# Final fallback
248+
export BROWSER="${BROWSER:-xdg-open}"
249+
fi
250+
251+
# Create a desktop launcher for a web app
252+
web2app() {
253+
if [ "$#" -ne 3 ]; then
254+
echo "Usage: web2app <AppName> <AppURL> <IconURL> (IconURL must be in PNG -- use https://dashboardicons.com)"
255+
return 1
256+
fi
257+
258+
local APP_NAME="$1"
259+
local APP_URL="$2"
260+
local ICON_URL="$3"
261+
local ICON_DIR="$HOME/.local/share/applications/icons"
262+
local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop"
263+
local ICON_PATH="${ICON_DIR}/${APP_NAME}.png"
264+
265+
mkdir -p "$ICON_DIR"
266+
267+
if ! curl -sL -o "$ICON_PATH" "$ICON_URL"; then
268+
echo "Error: Failed to download icon."
269+
return 1
270+
fi
271+
272+
cat >"$DESKTOP_FILE" <<EOF
273+
[Desktop Entry]
274+
Version=1.0
275+
Name=$APP_NAME
276+
Comment=$APP_NAME
277+
Exec=$BROWSER --new-window --ozone-platform=wayland --app="$APP_URL" --name="$APP_NAME" --class="$APP_NAME"
278+
Terminal=false
279+
Type=Application
280+
Icon=$ICON_PATH
281+
StartupNotify=true
282+
EOF
283+
284+
chmod +x "$DESKTOP_FILE"
285+
}
286+
287+
web2app-remove() {
288+
if [ "$#" -ne 1 ]; then
289+
echo "Usage: web2app-remove <AppName>"
290+
return 1
291+
fi
292+
293+
local APP_NAME="$1"
294+
local ICON_DIR="$HOME/.local/share/applications/icons"
295+
local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop"
296+
local ICON_PATH="${ICON_DIR}/${APP_NAME}.png"
297+
298+
rm "$DESKTOP_FILE"
299+
rm "$ICON_PATH"
300+
}
301+
225302
# start_tmux
226303
[ -f ~/.local/bin/ta ] && ~/.local/bin/ta

0 commit comments

Comments
 (0)