-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgrant-plugin-permissions.sh
More file actions
91 lines (82 loc) · 2.73 KB
/
Copy pathgrant-plugin-permissions.sh
File metadata and controls
91 lines (82 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
#
# Pre-grant Zellij permissions for the lince-dashboard plugin.
#
# Zellij stores granted permissions in ~/.cache/zellij/permissions.kdl.
# On a fresh install, the plugin shows a permission dialog that the user must
# accept. If the dialog is missed or doesn't appear, the plugin runs without
# permissions and panics on any privileged API call.
#
# This script creates the permissions.kdl cache file so the plugin starts
# with all required permissions already granted.
#
# Usage:
# bash grant-plugin-permissions.sh # grant permissions
# bash grant-plugin-permissions.sh --show # show current permissions
# bash grant-plugin-permissions.sh --reset # remove cached permissions
#
set -e
if [ "$(uname -s)" = "Darwin" ]; then
CACHE_DIR="$HOME/Library/Caches/org.Zellij-Contributors.Zellij"
else
CACHE_DIR="$HOME/.cache/zellij"
fi
PERMS_FILE="$CACHE_DIR/permissions.kdl"
PLUGIN_WASM="$HOME/.config/zellij/plugins/lince-dashboard.wasm"
show_permissions() {
if [ -f "$PERMS_FILE" ]; then
echo "Current permissions cache ($PERMS_FILE):"
echo ""
cat "$PERMS_FILE"
else
echo "No permissions cache found at $PERMS_FILE"
fi
}
reset_permissions() {
if [ -f "$PERMS_FILE" ]; then
rm "$PERMS_FILE"
echo "Removed $PERMS_FILE"
else
echo "No permissions cache to remove"
fi
}
grant_permissions() {
mkdir -p "$CACHE_DIR"
# If permissions.kdl already exists and contains our plugin, ask to update
if [ -f "$PERMS_FILE" ] && grep -q "lince-dashboard.wasm" "$PERMS_FILE" 2>/dev/null; then
echo "Permissions already cached for lince-dashboard plugin."
read -p "Update with latest permissions? (y/n): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Keeping existing permissions."
return 0
fi
# Remove old entry, keep other plugins' permissions
sed -i '/lince-dashboard\.wasm/,/^}/d' "$PERMS_FILE"
fi
# Append to existing file (preserve permissions for other plugins)
cat >> "$PERMS_FILE" << EOF
"${PLUGIN_WASM}" {
RunCommands
ReadApplicationState
ReadCliPipes
WriteToStdin
ChangeApplicationState
OpenTerminalsOrPlugins
MessageAndLaunchOtherPlugins
}
EOF
echo "Permissions granted for lince-dashboard plugin."
echo "Written to: $PERMS_FILE"
}
case "${1:-}" in
--show) show_permissions ;;
--reset) reset_permissions ;;
--help|-h)
echo "Usage: $0 [--show|--reset|--help]"
echo " (no args) Grant permissions for lince-dashboard plugin"
echo " --show Show current permissions cache"
echo " --reset Remove cached permissions"
;;
*) grant_permissions ;;
esac