forked from Kakiharu/screenprofiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreenprofilercmd.sh
More file actions
executable file
·217 lines (186 loc) · 8 KB
/
screenprofilercmd.sh
File metadata and controls
executable file
·217 lines (186 loc) · 8 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
#
# screenprofilercmd.sh - Main command-line interface for Screen Profiler
#
# Usage: screenprofilercmd <command> [arguments]
#
# ============================================================================
# Setup
# ============================================================================
# Get the directory where this script resides
script_dir="$(dirname "$(realpath "$0")")"
# Directory where profiles are stored
profiles_dir="$script_dir/profiles"
# Load common functions and variables (including version number)
if [ -f "$script_dir/common.sh" ]; then
source "$script_dir/common.sh"
else
SCREENPROFILER_VERSION="unknown"
fi
# ============================================================================
# Parse Command-Line Arguments
# ============================================================================
command="$1"
profile_name="$2"
flag="$3"
# ============================================================================
# Dependency Check
# ============================================================================
# Check dependencies for all commands except help and version
case $command in
""|help|--help|-h|version|-v|--version)
# Don't check dependencies for informational commands
;;
*)
check_dependencies
;;
esac
# ============================================================================
# Command Execution
# ============================================================================
case $command in
# ------------------------------------------------------------------------
# Save Profile
# ------------------------------------------------------------------------
save)
if [ -z "$profile_name" ]; then
print_error "Profile name required"
echo "Usage: $0 save <profile_name> [0|1]"
echo " 0 = Save display configuration only"
echo " 1 = Save display + KDE desktop settings (default)"
exit 1
fi
"$script_dir/save_profile.sh" "$profile_name" "$flag"
;;
# ------------------------------------------------------------------------
# Load Profile
# ------------------------------------------------------------------------
load)
if [ -z "$profile_name" ]; then
print_error "Profile name required"
echo "Usage: $0 load <profile_name>"
exit 1
fi
"$script_dir/load_profile.sh" "$profile_name"
;;
# ------------------------------------------------------------------------
# Remove Profile
# ------------------------------------------------------------------------
remove)
if [ -z "$profile_name" ]; then
print_error "Profile name required"
echo "Usage: $0 remove <profile_name>"
exit 1
fi
# Delete the profile directory
if [ -d "$profiles_dir/$profile_name" ]; then
rm -rf "$profiles_dir/$profile_name"
print_success "Profile '$profile_name' removed successfully"
else
print_error "Profile '$profile_name' not found"
exit 1
fi
;;
# ------------------------------------------------------------------------
# List Profiles
# ------------------------------------------------------------------------
list)
print_header "Available Profiles"
print_header "════════════════════════════════════════"
echo ""
# Check if profiles directory exists
if [ ! -d "$profiles_dir" ]; then
print_warning "No profiles directory found"
exit 0
fi
# Collect and sort profile names
profiles=$(for profile_dir in "$profiles_dir"/*; do
[ -d "$profile_dir" ] || continue
basename "$profile_dir"
done | sort)
if [ -n "$profiles" ]; then
echo "$profiles" | sed 's/^/ • /'
else
print_info "No profiles saved yet"
fi
echo
;;
# ------------------------------------------------------------------------
# Launch Tray Application
# ------------------------------------------------------------------------
tray)
# Change to script directory to ensure correct working directory
cd "$script_dir" || exit 1
# Launch the Python tray application in the background
# Redirect output to /dev/null to avoid cluttering terminal
nohup python3 "$script_dir/screenprofiler.py" >/dev/null 2>&1 &
print_success "Screen Profiler tray application launched"
;;
# ------------------------------------------------------------------------
# Uninstall
# ------------------------------------------------------------------------
uninstall)
uninstall_script="$script_dir/uninstall.sh"
if [ -x "$uninstall_script" ]; then
"$uninstall_script"
else
print_error "Uninstall script not found at $uninstall_script"
exit 1
fi
;;
# ------------------------------------------------------------------------
# Version Information
# ------------------------------------------------------------------------
version|-v|--version)
print_header "════════════════════════════════════════"
echo -e "\033[0;32mScreen Profiler version $SCREENPROFILER_VERSION\033[0m"
echo ""
print_header "Donations welcome: \033[0;32mhttps://linktr.ee/kakiharu\033"
print_header "════════════════════════════════════════"
;;
# ------------------------------------------------------------------------
# Help / Usage Information
# ------------------------------------------------------------------------
""|help|--help|-h)
print_header "════════════════════════════════════════"
echo -e "\033[0;32mScreen Profiler version $SCREENPROFILER_VERSION\033[0m"
echo ""
print_header "Easily save and restore display configurations on KDE Plasma"
echo ""
print_header "Usage: $0 <command> [arguments]"
echo ""
print_blue "Commands:"
print_blue " save <name> [0|1] Save current display configuration as a profile"
print_blue " 0 = monitors only, 1 = with KDE configs (default)"
echo ""
print_blue " load <name> Restore a saved profile"
echo ""
print_blue " remove <name> Delete a saved profile"
echo ""
print_blue " list List all saved profiles (alphabetically)"
echo ""
print_blue " tray Launch the system tray application"
echo ""
print_blue " uninstall Remove Screen Profiler from your system"
echo ""
print_blue " version Display version information"
echo ""
print_header "Examples:"
print_header " $0 save worksetup 1 # Save monitors + desktop settings"
print_header " $0 save gaming 0 # Save monitors only"
print_header " $0 load worksetup # Restore worksetup profile"
print_header " $0 list # Show all profiles"
echo ""
print_header "Donations welcome: \033[0;32mhttps://linktr.ee/kakiharu\033"
print_header "════════════════════════════════════════"
;;
# ------------------------------------------------------------------------
# Invalid Command
# ------------------------------------------------------------------------
*)
print_error "Invalid command: $command"
echo ""
echo "Run '$0 help' for usage information"
exit 1
;;
esac