-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-claudesettings
More file actions
executable file
·131 lines (107 loc) · 3.35 KB
/
get-claudesettings
File metadata and controls
executable file
·131 lines (107 loc) · 3.35 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
# Environment setup
# -----------------------------------------------------------------------------
set -o pipefail
[[ ${DEBUG-} ]] && set -o xtrace
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" || exit 1; pwd)"
source "${SCRIPT_DIR}/bash_modules/terminal.sh"
[[ -z ${BASH_MODULES_DIR-} ]] && echo "ERROR: terminal.sh module missing" && exit 1
function print_usage() {
cat <<EOF
Usage: $(basename "$0")
Read Claude Code settings and display a formatted summary of configuration
and permissions.
Dependencies:
jq JSON processor
Optional arguments:
-h, --help Show this help message and exit
EOF
}
if [[ $# -gt 0 ]]; then
print_usage
exit 0
fi
# Dependency Check
# -----------------------------------------------------------------------------
if ! command -v jq >/dev/null; then
log_error "ERROR: Missing dependency - 'jq'"
exit 1
fi
# Configuration
# -----------------------------------------------------------------------------
settings_file="${HOME}/.claude/settings.json"
if [[ ! -f "${settings_file}" ]]; then
log_error "ERROR: Settings file not found - '${settings_file}'"
exit 1
fi
settings=$(cat "${settings_file}")
# Helper function to extract and format permissions by type
function format_permissions() {
local -r permission_type="${1}"
local -r json_path="${2}"
local -r home_path="${HOME}"
local items
items=$(echo "${settings}" | jq -r "${json_path}[]? // empty" 2>/dev/null)
[[ -z "${items}" ]] && return
local bash_items=()
local read_items=()
local write_items=()
local other_items=()
while IFS= read -r item; do
if [[ "${item}" =~ ^Bash\((.+):\*\)$ ]]; then
bash_items+=("${BASH_REMATCH[1]}")
elif [[ "${item}" =~ ^Bash\((.+)\)$ ]]; then
bash_items+=("${BASH_REMATCH[1]}")
elif [[ "${item}" =~ ^Read\((.+)\)$ ]]; then
local path="${BASH_REMATCH[1]}"
path="${path/${home_path}/\~}"
read_items+=("${path}")
elif [[ "${item}" =~ ^Write\((.+)\)$ ]]; then
local path="${BASH_REMATCH[1]}"
path="${path/${home_path}/\~}"
write_items+=("${path}")
else
other_items+=("${item}")
fi
done <<< "${items}"
echo "## ${permission_type}"
echo
if [[ ${#bash_items[@]} -gt 0 ]]; then
echo "Bash:"
printf " %s\n" "$(printf '%s, ' "${bash_items[@]}" | sed 's/, $//')"
echo
fi
if [[ ${#read_items[@]} -gt 0 ]]; then
echo "Read:"
printf " %s\n" "$(printf '%s, ' "${read_items[@]}" | sed 's/, $//')"
echo
fi
if [[ ${#write_items[@]} -gt 0 ]]; then
echo "Write:"
printf " %s\n" "$(printf '%s, ' "${write_items[@]}" | sed 's/, $//')"
echo
fi
if [[ ${#other_items[@]} -gt 0 ]]; then
echo "Other:"
printf " %s\n" "$(printf '%s, ' "${other_items[@]}" | sed 's/, $//')"
echo
fi
}
# Output
# -----------------------------------------------------------------------------
echo "# Claude Settings"
echo
model=$(echo "${settings}" | jq -r '.model // "not set"')
echo "- model: ${model}"
plugins=$(echo "${settings}" | jq -r '.enabledPlugins | keys[]? // empty' 2>/dev/null | paste -sd ',' - | sed 's/,/, /g')
if [[ -n "${plugins}" ]]; then
echo "- enabledPlugins: ${plugins}"
else
echo "- enabledPlugins: none"
fi
echo
echo "# Permissions"
echo
format_permissions "Allowed" ".permissions.allow"
format_permissions "Ask" ".permissions.ask"
format_permissions "Denied" ".permissions.deny"