-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.sh
More file actions
executable file
·1117 lines (1014 loc) · 34.7 KB
/
Copy pathcli.sh
File metadata and controls
executable file
·1117 lines (1014 loc) · 34.7 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# NothingLess CLI - Minimal NothingLess fork - It was needed, so here it is. lol
set -euo pipefail
# Resolve script dir with bash builtins only (no fork, avoids E2BIG on large envs)
_script_src="${BASH_SOURCE[0]}"
SCRIPT_DIR="${_script_src%/*}"
if [[ "$SCRIPT_DIR" == "$_script_src" ]] && [[ ! -f "$_script_src" ]]; then
SCRIPT_DIR="$PWD"
fi
if [[ "$SCRIPT_DIR" != /* ]]; then
SCRIPT_DIR="$PWD/$SCRIPT_DIR"
fi
unset _script_src
# Use environment variables if set by flake, otherwise fall back to PATH
QS_BIN="${NOTHINGLESS_QS:-qs}"
NIXGL_BIN="${NOTHINGLESS_NIXGL:-}"
if [ -z "${QML2_IMPORT_PATH:-}" ]; then
if command -v qs >/dev/null 2>&1; then
true
fi
fi
# If QML2_IMPORT_PATH is set (by wrapper or dev shell), ensure QML_IMPORT_PATH matches
if [ -n "${QML2_IMPORT_PATH:-}" ] && [ -z "${QML_IMPORT_PATH:-}" ]; then
export QML_IMPORT_PATH="$QML2_IMPORT_PATH"
fi
# Ensure config files exist - copy from preset if missing
ensure_config_files() {
local config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/nothingless/config"
local preset_dir="${SCRIPT_DIR}/assets/presets/NothingLess Default"
# Create config directory if it doesn't exist
mkdir -p "$config_dir"
# Copy preset files if they don't exist (cp -n = no-clobber)
for file in theme bar workspaces overview notch compositor performance desktop lockscreen dock ai; do
cp -n "${preset_dir}/${file}.json" "${config_dir}/${file}.json" 2>/dev/null || true
done
}
# Call it before launching
ensure_config_files
show_help() {
cat <<EOF
NothingLess CLI - Desktop Environment Control
Usage: nothingless [COMMAND]
Commands:
(none) Launch NothingLess
update Check for and apply commits from origin
update --check Check for updates without pulling
update --pull Pull and restart without prompt
refresh Refresh local/dev profile (for developers)
lock Activate lockscreen
reload Restart NothingLess
reload-binds Force re-apply Hyprland keybinds (fixes binds after restart)
quit Stop NothingLess
screen [on|off] Turn screen on/off
suspend Suspend the system
brightness <percent> [monitor] Set brightness (0-100)
brightness +/-<delta> [monitor] Adjust brightness relatively
brightness -s [monitor] Save current brightness
brightness -r [monitor] Restore saved brightness
brightness -l List monitors and their brightness
volume-up Increase volume
volume-down Decrease volume
volume-mute Toggle volume mute
mic-mute Toggle microphone mute
caffeine Toggle caffeine (idle inhibition)
gamemode Toggle game mode (snapshot/restore compositor)
focusmode Toggle focus mode (zero gaps + DND + caffeine)
profile [saver|balanced|performance] Set power-profiles-daemon profile
cycle-profile Cycle to the next power profile
charge-limit [on|off|<percent>] Toggle / set battery charge limit (50-100)
nightlight Toggle night light
run <command> Run any IPC command (launcher, dashboard, overview, etc.)
help Show this help message
version, -v, --version Show NothingLess version
goodbye Uninstall NothingLess :(
install <target> Install compositor config (hyprland)
install hyprland --lua Install with Lua config (Hyprland >= 0.48)
install hyprland --conf Install with config file (default, safe)
remove <target> Remove compositor config (hyprland)
screenshare scan Discover Miracast sinks (alias of 'mirai source-scan')
screenshare cast [sink] [display] Cast to a sink (uses first available if none given)
screenshare stop Disconnect the current cast
screenshare sink-start Start Mirai sink mode (this PC as a Miracast display)
screenshare sink-stop Stop Mirai sink mode
screenshare sink-mode <window|fullscreen> Set how the received stream is rendered
screenshare status Show the current mirai daemon state
Examples:
nothingless brightness 75 Set all monitors to 75%
nothingless brightness 50 HDMI-A-1 Set HDMI-A-1 to 50%
nothingless brightness +10 Increase brightness by 10%
nothingless brightness -5 HDMI-A-1 Decrease HDMI-A-1 brightness by 5%
nothingless brightness 10 -s Save current, then set all to 10%
nothingless brightness -s HDMI-A-1 Save current brightness of HDMI-A-1
nothingless brightness -r Restore saved brightness
EOF
}
NOTHINGLESS_HYPR_CONF_SOURCE="source = ~/.local/share/nothingless/hyprland.conf"
NOTHINGLESS_HYPR_LUA_SOURCE='local _f, _e = loadfile(os.getenv("HOME") .. "/.local/share/nothingless/hyprland.lua", "t", _ENV); if _f then _f() else error("NothingLess load failed: " .. tostring(_e)) end'
NOTHINGLESS_HYPR_CONF_BLOCK=$(
cat <<'EOF'
# NothingLess
source = ~/.local/share/nothingless/hyprland.conf
# OVERRIDES
# Down here you can write or source anything that you want to override from NothingLess's settings.
EOF
)
NOTHINGLESS_HYPR_LUA_BLOCK=$(
cat <<'EOF'
-- NothingLess
local _f, _e = loadfile(os.getenv("HOME") .. "/.local/share/nothingless/hyprland.lua", "t", _ENV); if _f then _f() else error("NothingLess load failed: " .. tostring(_e)) end
-- OVERRIDES
-- Down here you can write or source anything that you want to override from NothingLess's settings.
EOF
)
append_nothingless_hyprland_block() {
local conf="$1"
local source="$2"
local block="$3"
if [ -f "$conf" ] && grep -qF "$source" "$conf"; then
echo "NothingLess Hyprland block already present in $conf"
return 0
fi
if [ -f "$conf" ] && [ -s "$conf" ]; then
printf "\n%s\n" "$block" >>"$conf"
else
printf "%s\n" "$block" >"$conf"
fi
echo "Added NothingLess Hyprland block to $conf"
}
remove_nothingless_hyprland_block() {
local conf="$1"
local source="$2"
if [ ! -f "$conf" ]; then
echo "$conf does not exist"
return 0
fi
awk -v source="$source" '
function is_remove(line) {
return line == source \
|| line == "# NothingLess" \
|| line == "-- NothingLess" \
|| line == "# OVERRIDES" \
|| line == "-- OVERRIDES" \
|| line == "# Down here you can write or source anything that you want to override from NothingLess'\''s settings." \
|| line == "-- Down here you can write or source anything that you want to override from NothingLess'\''s settings." \
|| line == "exec-once = nothingless" \
|| line == "exec-once = axctl -c ~/.local/share/nothingless/axctl.toml daemon"
}
{
lines[NR] = $0
}
END {
for (i = 1; i <= NR; i++) {
line = lines[i]
nextline = (i < NR) ? lines[i + 1] : ""
if (is_remove(line)) {
continue
}
if (line == "" && (is_remove(lines[i - 1]) || is_remove(nextline))) {
continue
}
print line
}
}
' "$conf" >"${conf}.tmp" && mv "${conf}.tmp" "$conf"
echo "Removed NothingLess Hyprland block from $conf"
}
find_nothingless_pid() {
# Try to find QuickShell process running shell.qml
# QuickShell binary can be named 'qs' or 'quickshell'
local pid
# First try with full path (production/flake mode)
pid=$(pgrep -f "qs.*${SCRIPT_DIR}/shell.qml" 2>/dev/null | head -1)
if [ -z "$pid" ]; then
pid=$(pgrep -f "quickshell.*${SCRIPT_DIR}/shell.qml" 2>/dev/null | head -1)
fi
# If not found, try with relative path (development mode)
if [ -z "$pid" ]; then
pid=$(pgrep -f "qs.*shell.qml" 2>/dev/null | head -1)
fi
if [ -z "$pid" ]; then
pid=$(pgrep -f "quickshell.*shell.qml" 2>/dev/null | head -1)
fi
# Last resort: find any qs/quickshell process in this directory
if [ -z "$pid" ]; then
pid=$(pgrep -a "qs" 2>/dev/null | grep -F "$SCRIPT_DIR" | awk '{print $1}' | head -1)
fi
if [ -z "$pid" ]; then
pid=$(pgrep -a quickshell 2>/dev/null | grep -F "$SCRIPT_DIR" | awk '{print $1}' | head -1)
fi
echo "$pid"
}
find_nothingless_pid_cached() {
# Optimized PID lookup: check cache file first, then fall back to pgrep
local pid_file="/tmp/nothingless.pid"
local pid=""
# Check if cache file exists and process is alive
if [ -f "$pid_file" ]; then
pid=$(<"$pid_file" 2>/dev/null)
# Verify process still exists using kill -0 (no signal, just test)
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
echo "$pid"
return 0
fi
# PID is stale, remove cache file
rm -f "$pid_file"
fi
# Fallback: use expensive pgrep search
pid=$(find_nothingless_pid)
echo "$pid"
}
restart_nothingless() {
# Kill axctl processes first (they survive parent death when forked/detached)
pkill -f "axctl.*daemon" 2>/dev/null || true
pkill -f "axctl subscribe" 2>/dev/null || true
PID=$(find_nothingless_pid_cached)
if [ -n "$PID" ]; then
echo "Stopping NothingLess (PID $PID)..."
kill "$PID"
# Wait for process to exit
while kill -0 "$PID" 2>/dev/null; do
sleep 0.1
done
fi
echo "Starting NothingLess..."
# Relaunch the script in background
nohup "$0" >/dev/null 2>&1 &
}
PIPE="/tmp/nothingless_ipc.pipe"
case "${1:-}" in
update)
FLAG="${2:-}"
cd "$SCRIPT_DIR" || { echo "Error: cannot enter $SCRIPT_DIR"; exit 1; }
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
echo "Error: $SCRIPT_DIR is not a git repository"
exit 1
fi
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
LOCAL="$(git rev-parse HEAD)"
LOCAL_SHORT="${LOCAL:0:7}"
echo "Fetching updates from origin..."
git fetch origin "$BRANCH" 2>&1 || {
echo "Error: failed to fetch from remote"
exit 1
}
REMOTE="$(git rev-parse "origin/$BRANCH")"
REMOTE_SHORT="${REMOTE:0:7}"
if [ "$LOCAL" = "$REMOTE" ]; then
echo "NothingLess is up to date ($LOCAL_SHORT on $BRANCH)"
exit 0
fi
BEHIND=$(git rev-list --count "$LOCAL..$REMOTE")
AHEAD=$(git rev-list --count "$REMOTE..$LOCAL")
echo ""
echo "┌─ NothingLess Update ─────────────────────────────"
echo "│ branch : $BRANCH"
echo "│ local : $LOCAL_SHORT"
echo "│ remote : $REMOTE_SHORT"
if [ "$BEHIND" -gt 0 ]; then
echo "│ behind : $BEHIND commit(s)"
else
echo "│ ahead : $AHEAD commit(s) — local only"
fi
echo "├──────────────────────────────────────────────────"
echo "│ New commits:"
git log --oneline --no-decorate "$LOCAL..$REMOTE" 2>/dev/null | while read -r line; do
printf "│ %s\n" "$line"
done
echo "└──────────────────────────────────────────────────"
if [ "$FLAG" = "--check" ]; then
exit 0
fi
if [ "$FLAG" = "--pull" ]; then
echo "Pulling..."
git pull --ff-only origin "$BRANCH" || {
echo "Error: pull failed (fast-forward only)"
exit 1
}
restart_nothingless
exit 0
fi
if [ "$BEHIND" -gt 0 ]; then
read -p "Pull $BEHIND commit(s)? [Y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
git pull --ff-only origin "$BRANCH" || {
echo "Error: pull failed (fast-forward only)"
exit 1
}
restart_nothingless
fi
fi
;;
refresh)
echo "Refreshing NothingLess profile..."
exec nix profile upgrade NothingLess --refresh --impure
;;
screenshare)
# Drive the Mirai Miracast daemon (https://github.com/leriart/Mirai).
# This is a thin wrapper around `mirai <subcommand>`; all the actual
# discovery, streaming, and rendering is handled by the daemon.
if ! command -v mirai >/dev/null 2>&1; then
echo "Error: mirai is not installed."
echo " Install it with: curl -fsSL https://raw.githubusercontent.com/leriart/Mirai/main/install.sh | sh"
exit 1
fi
subcmd="${2:-status}"
shift 2 2>/dev/null || shift $#
case "$subcmd" in
scan)
echo "Scanning for Miracast sinks (10 s)…"
mirai source-scan --timeout 10
echo "---"
mirai source-list
;;
cast)
# Optional positional args: [sink_id] [display_name]
# If no sink_id is given, pick the first one from source-list.
if [ -n "${1:-}" ]; then
SINK="$1"
shift
else
SINK="$(mirai source-list 2>/dev/null | python3 -c "
import json, sys
try:
arr = json.load(sys.stdin)
if isinstance(arr, list) and arr:
print(arr[0].get('id') or arr[0].get('name') or '')
except Exception:
pass
" 2>/dev/null)"
if [ -z "$SINK" ]; then
echo "Error: no sink_id given and none discovered. Run 'nothingless screenshare scan' first."
exit 1
fi
fi
DISPLAY="${1:-default}"
echo "Casting to $SINK (display: $DISPLAY)…"
mirai source-connect "$SINK" --display "$DISPLAY"
;;
stop|disconnect)
mirai source-disconnect
;;
sink-start)
mirai sink-start
;;
sink-stop)
mirai sink-stop
;;
sink-mode)
MODE="${1:-window}"
case "$MODE" in
window|fullscreen) mirai sink-mode "$MODE" ;;
*) echo "Error: mode must be 'window' or 'fullscreen'"; exit 1 ;;
esac
;;
status)
mirai status
;;
displays)
mirai displays
;;
*)
echo "Usage: nothingless screenshare {scan|cast|stop|sink-start|sink-stop|sink-mode|status|displays} [args]"
exit 1
;;
esac
;;
run)
CMD="${2:-}"
if [ -z "$CMD" ]; then
echo "Error: No command specified for run"
exit 1
fi
# toggle-metrics: write directly to notch.json (no IPC needed)
if [ "$CMD" = "toggle-metrics" ]; then
# Debounce: prevent double-fire from Hyprland key repeat
LOCK_FILE="/tmp/nothingless_toggle_metrics.lock"
# Atomic lock via mkdir; if it already exists, check debounce timestamp.
# Clean up stale regular file left over from the old file-based lock.
if [ -f "$LOCK_FILE" ] && [ ! -d "$LOCK_FILE" ]; then
rm -f "$LOCK_FILE"
fi
if ! mkdir "$LOCK_FILE" 2>/dev/null; then
last_run=$(cat "$LOCK_FILE/timestamp" 2>/dev/null || echo 0)
now=$(date +%s%N)
elapsed=$(( (now - last_run) / 1000000 ))
if [ "$elapsed" -lt 500 ]; then
exit 0
fi
fi
date +%s%N > "$LOCK_FILE/timestamp"
NOTCH_JSON="${XDG_CONFIG_HOME:-$HOME/.config}/nothingless/config/notch.json"
if [ -f "$NOTCH_JSON" ]; then
# Toggle showMetrics in the JSON
python3 -c "
import json
with open('$NOTCH_JSON') as f:
cfg = json.load(f)
cfg['showMetrics'] = not cfg.get('showMetrics', False)
with open('$NOTCH_JSON', 'w') as f:
json.dump(cfg, f, indent=2)
print('Metrics toggled to', cfg['showMetrics'])
" 2>&1 || {
echo "Error: Failed to toggle metrics"
exit 1
}
exit 0
else
echo "Error: notch.json not found at $NOTCH_JSON"
exit 1
fi
fi
# share-scan: trigger a Miracast scan and show the screen-sharing panel.
# This is the Super+K / Win+K equivalent. We delegate to mirai for the
# actual network scan, then surface the result via the panel.
if [ "$CMD" = "share-scan" ]; then
if ! command -v mirai >/dev/null 2>&1; then
echo "Error: mirai is not installed."
echo " curl -fsSL https://raw.githubusercontent.com/leriart/Mirai/main/install.sh | sh"
exit 1
fi
# Send to the running shell first so the panel opens immediately.
if [ -p "$PIPE" ]; then
echo "share-scan" >"$PIPE" &
else
PID=$(find_nothingless_pid_cached)
if [ -n "$PID" ]; then
qs ipc --pid "$PID" call nothingless run share-scan 2>/dev/null &
fi
fi
# Run the actual scan in parallel so the panel has fresh data.
mirai source-scan --timeout 10 >/dev/null 2>&1 &
exit 0
fi
# Fast path: Write directly to pipe if it exists (Zero latency)
if [ -p "$PIPE" ]; then
echo "$CMD" >"$PIPE" &
exit 0
fi
# Fallback path: Use QS IPC with cached PID lookup
PID=$(find_nothingless_pid_cached)
if [ -z "$PID" ]; then
echo "Error: NothingLess is not running"
exit 1
fi
qs ipc --pid "$PID" call nothingless run "$CMD" 2>/dev/null || {
echo "Error: Could not run command '$CMD'"
exit 1
}
;;
lock)
# Fast path: Write directly to pipe if it exists (Zero latency)
if [ -p "$PIPE" ]; then
echo "lockscreen" >"$PIPE" &
exit 0
fi
# Fallback path: Use QS IPC with cached PID lookup
PID=$(find_nothingless_pid_cached)
if [ -n "$PID" ]; then
qs ipc --pid "$PID" call nothingless run lockscreen 2>/dev/null && exit 0
fi
# Ultimate fallback: systemd-logind lock session
if command -v loginctl &>/dev/null; then
loginctl lock-session
exit $?
fi
echo "Error: Could not activate lockscreen (nothingless not running, no loginctl)"
exit 1
;;
reload)
restart_nothingless
;;
reload-binds)
# Force the running shell to re-apply its Hyprland keybinds. Useful when
# binds silently disappear after a shell restart or hot-reload, which
# happens because the initial apply can fire before the axctl daemon is
# reachable, or because a previous shell left orphaned binds behind.
PIPE="/tmp/nothingless_ipc.pipe"
if [ -p "$PIPE" ]; then
echo "reload-binds" >"$PIPE" &
exit 0
fi
PID=$(find_nothingless_pid_cached)
if [ -z "$PID" ]; then
echo "Error: NothingLess is not running"
exit 1
fi
qs ipc --pid "$PID" call nothingless run reload-binds 2>/dev/null || {
echo "Error: Could not send reload-binds command"
exit 1
}
;;
quit)
# Kill axctl processes first
pkill -f "axctl.*daemon" 2>/dev/null || true
pkill -f "axctl subscribe" 2>/dev/null || true
PID=$(find_nothingless_pid_cached)
if [ -n "$PID" ]; then
echo "Stopping NothingLess (PID $PID)..."
kill "$PID"
else
echo "NothingLess is not running"
fi
;;
screen)
SUB="${2:-}"
if [ "$SUB" = "off" ]; then
if command -v hyprctl &>/dev/null; then
hyprctl dispatch dpms off
else
notify-send "Screen Off" "Not supported on this compositor yet"
fi
elif [ "$SUB" = "on" ]; then
if command -v hyprctl &>/dev/null; then
hyprctl dispatch dpms on
else
notify-send "Screen On" "Not supported on this compositor yet"
fi
else
echo "Usage: nothingless screen [on|off]"
exit 1
fi
;;
suspend)
if command -v systemctl &>/dev/null; then
systemctl suspend
elif command -v loginctl &>/dev/null; then
loginctl suspend
else
# Fallback to D-Bus
dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager.Suspend boolean:true
fi
;;
volume-up|volume-down|volume-mute|mic-mute|caffeine|gamemode|focusmode|dnd|nightlight)
PID=$(find_nothingless_pid_cached)
if [ -z "$PID" ]; then
echo "Error: NothingLess is not running"
exit 1
fi
qs ipc --pid "$PID" call nothingless run "$1" 2>/dev/null || {
echo "Error: Could not run command '$1'"
exit 1
}
;;
profile)
# nothingless profile [saver|balanced|performance]
PID=$(find_nothingless_pid_cached)
if [ -z "$PID" ]; then
echo "Error: NothingLess is not running"
exit 1
fi
NAME="${2:-}"
case "$NAME" in
saver|power-saver) IPC_CMD="powerprofile-saver" ;;
balanced) IPC_CMD="powerprofile-balanced" ;;
performance) IPC_CMD="powerprofile-performance" ;;
"")
echo "Usage: nothingless profile <saver|balanced|performance>" >&2
exit 1
;;
*)
echo "Error: unknown profile '$NAME' (use: saver, balanced, performance)" >&2
exit 1
;;
esac
qs ipc --pid "$PID" call nothingless run "$IPC_CMD" 2>/dev/null || {
echo "Error: Could not run profile command"
exit 1
}
;;
cycle-profile)
PID=$(find_nothingless_pid_cached)
if [ -z "$PID" ]; then
echo "Error: NothingLess is not running"
exit 1
fi
qs ipc --pid "$PID" call nothingless run "cycle-powerprofile" 2>/dev/null || {
echo "Error: Could not cycle power profile"
exit 1
}
;;
charge-limit)
# nothingless charge-limit [on|off|<percent>]
# With no args, prints the current state.
PID=$(find_nothingless_pid_cached)
if [ -z "$PID" ]; then
echo "Error: NothingLess is not running"
exit 1
fi
ARG="${2:-}"
if [ -z "$ARG" ]; then
qs ipc --pid "$PID" call nothingless run "charge-limit-status" 2>/dev/null || {
echo "Error: Could not query charge limit"
exit 1
}
elif [ "$ARG" = "on" ]; then
qs ipc --pid "$PID" call nothingless run "charge-limit-on" 2>/dev/null
elif [ "$ARG" = "off" ]; then
qs ipc --pid "$PID" call nothingless run "charge-limit-off" 2>/dev/null
elif [[ "$ARG" =~ ^[0-9]+$ ]] && [ "$ARG" -ge 50 ] && [ "$ARG" -le 100 ]; then
qs ipc --pid "$PID" call nothingless run "charge-limit-set $ARG" 2>/dev/null
else
echo "Usage: nothingless charge-limit [on|off|<50-100>]" >&2
exit 1
fi
;;
brightness)
PID=$(find_nothingless_pid_cached)
if [ -z "$PID" ]; then
echo "Error: NothingLess is not running"
exit 1
fi
BRIGHTNESS_SAVE_FILE="/tmp/nothingless_brightness_saved.txt"
# Parse arguments
ARG2="${2:-}"
ARG3="${3:-}"
ARG4="${4:-}"
# Handle list flag
if [ "$ARG2" = "-l" ] || [ "$ARG2" = "--list" ]; then
echo "Monitors:"
if command -v hyprctl &>/dev/null; then
hyprctl monitors -j 2>/dev/null | jq -r '.[] | " \(.name)"' || {
echo "Error: Could not list monitors"
exit 1
}
else
echo "Error: hyprctl not found"
exit 1
fi
exit 0
fi
# Handle restore flag
if [ "$ARG2" = "-r" ] || [ "$ARG2" = "--restore" ]; then
if [ ! -f "$BRIGHTNESS_SAVE_FILE" ]; then
echo "Error: No saved brightness found. Use -s to save first."
exit 1
fi
MONITOR="${ARG3:-}"
if [ -z "$MONITOR" ]; then
# Restore all monitors
while IFS=: read -r name value; do
if [ -n "$name" ] && [ -n "$value" ]; then
NORMALIZED=$(awk "BEGIN {printf \"%.2f\", $value / 100}")
qs ipc --pid "$PID" call brightness set "$NORMALIZED" "$name" 2>/dev/null || {
echo "Warning: Could not restore brightness for $name"
}
fi
done <"$BRIGHTNESS_SAVE_FILE"
echo "Restored brightness for all monitors"
else
# Restore specific monitor
VALUE=$(grep "^${MONITOR}:" "$BRIGHTNESS_SAVE_FILE" | cut -d: -f2)
if [ -z "$VALUE" ]; then
echo "Error: No saved brightness for monitor $MONITOR"
exit 1
fi
NORMALIZED=$(awk "BEGIN {printf \"%.2f\", $VALUE / 100}")
qs ipc --pid "$PID" call brightness set "$NORMALIZED" "$MONITOR" 2>/dev/null || {
echo "Error: Could not restore brightness for $MONITOR"
exit 1
}
echo "Restored brightness for $MONITOR to ${VALUE}%"
fi
exit 0
fi
# Parse value and monitor/flags
VALUE=""
MONITOR=""
SAVE_FLAG=false
RELATIVE_MODE=false
RELATIVE_DELTA=0
if [[ "$ARG2" =~ ^[0-9]+$ ]]; then
VALUE="$ARG2"
if [ "$ARG3" = "-s" ] || [ "$ARG3" = "--save" ]; then
SAVE_FLAG=true
elif [ -n "$ARG3" ] && [ "$ARG3" != "-s" ] && [ "$ARG3" != "--save" ]; then
MONITOR="$ARG3"
if [ "$ARG4" = "-s" ] || [ "$ARG4" = "--save" ]; then
SAVE_FLAG=true
fi
fi
elif [[ "$ARG2" =~ ^[+-][0-9]+$ ]]; then
# Relative mode: +10 or -5
RELATIVE_MODE=true
RELATIVE_DELTA="$ARG2"
if [ -n "$ARG3" ] && [ "$ARG3" != "-s" ] && [ "$ARG3" != "--save" ]; then
MONITOR="$ARG3"
if [ "$ARG4" = "-s" ] || [ "$ARG4" = "--save" ]; then
SAVE_FLAG=true
fi
elif [ "$ARG3" = "-s" ] || [ "$ARG3" = "--save" ]; then
SAVE_FLAG=true
fi
elif [ "$ARG2" = "-s" ] || [ "$ARG2" = "--save" ]; then
# Just save, no value change
MONITOR="${ARG3:-}"
if [ -z "$MONITOR" ]; then
# Save all monitors
bash "${SCRIPT_DIR}/scripts/brightness_list.sh" >"${BRIGHTNESS_SAVE_FILE}.tmp" 2>/dev/null || {
echo "Warning: Could not query current brightness"
}
if [ -f "${BRIGHTNESS_SAVE_FILE}.tmp" ]; then
while IFS=: read -r name bright method; do
if [ -n "$name" ] && [ -n "$bright" ]; then
echo "${name}:${bright}"
fi
done <"${BRIGHTNESS_SAVE_FILE}.tmp" >"$BRIGHTNESS_SAVE_FILE"
rm -f "${BRIGHTNESS_SAVE_FILE}.tmp"
echo "Saved current brightness for all monitors"
fi
else
# Save specific monitor
CURRENT_LINE=$(bash "${SCRIPT_DIR}/scripts/brightness_list.sh" 2>/dev/null | grep "^${MONITOR}:")
if [ -z "$CURRENT_LINE" ]; then
echo "Error: Monitor $MONITOR not found"
exit 1
fi
CURRENT=$(echo "$CURRENT_LINE" | cut -d: -f2)
if [ -f "$BRIGHTNESS_SAVE_FILE" ]; then
grep -v "^${MONITOR}:" "$BRIGHTNESS_SAVE_FILE" >"${BRIGHTNESS_SAVE_FILE}.tmp" 2>/dev/null || true
echo "${MONITOR}:${CURRENT}" >>"${BRIGHTNESS_SAVE_FILE}.tmp"
mv "${BRIGHTNESS_SAVE_FILE}.tmp" "$BRIGHTNESS_SAVE_FILE"
else
echo "${MONITOR}:${CURRENT}" >"$BRIGHTNESS_SAVE_FILE"
fi
echo "Saved current brightness for $MONITOR (${CURRENT}%)"
fi
exit 0
else
echo "Error: Invalid brightness value. Must be 0-100 or +/-delta."
echo "Run 'nothingless help' for usage information"
exit 1
fi
# Handle relative mode - use IPC adjust function directly
if [ "$RELATIVE_MODE" = true ]; then
# Convert delta to 0-1 range
NORMALIZED_DELTA=$(awk "BEGIN {printf \"%.2f\", $RELATIVE_DELTA / 100}")
if [ -z "$MONITOR" ]; then
qs ipc --pid "$PID" call brightness adjust "$NORMALIZED_DELTA" "" 2>/dev/null || {
echo "Error: Could not adjust brightness"
exit 1
}
echo "Adjusted brightness by ${RELATIVE_DELTA}% for all monitors"
else
qs ipc --pid "$PID" call brightness adjust "$NORMALIZED_DELTA" "$MONITOR" 2>/dev/null || {
echo "Error: Could not adjust brightness for $MONITOR"
exit 1
}
echo "Adjusted brightness by ${RELATIVE_DELTA}% for $MONITOR"
fi
exit 0
fi
# Validate brightness range
if [ "$VALUE" -lt 0 ] || [ "$VALUE" -gt 100 ]; then
echo "Error: Brightness must be between 0 and 100"
exit 1
fi
# Save current brightness if requested
if [ "$SAVE_FLAG" = true ]; then
if [ -z "$MONITOR" ]; then
# Save all monitors - we need to get current brightness
# For simplicity, we'll use a helper script to query current brightness
bash "${SCRIPT_DIR}/scripts/brightness_list.sh" >"${BRIGHTNESS_SAVE_FILE}.tmp" 2>/dev/null || {
echo "Warning: Could not query current brightness"
}
# Convert format from name:brightness:method to name:brightness
if [ -f "${BRIGHTNESS_SAVE_FILE}.tmp" ]; then
while IFS=: read -r name bright method; do
if [ -n "$name" ] && [ -n "$bright" ]; then
echo "${name}:${bright}"
fi
done <"${BRIGHTNESS_SAVE_FILE}.tmp" >"$BRIGHTNESS_SAVE_FILE"
rm -f "${BRIGHTNESS_SAVE_FILE}.tmp"
echo "Saved current brightness for all monitors"
fi
else
# Save specific monitor
CURRENT_LINE=$(bash "${SCRIPT_DIR}/scripts/brightness_list.sh" 2>/dev/null | grep "^${MONITOR}:")
if [ -z "$CURRENT_LINE" ]; then
echo "Error: Monitor $MONITOR not found"
exit 1
fi
CURRENT=$(echo "$CURRENT_LINE" | cut -d: -f2)
# Update or append to save file
if [ -f "$BRIGHTNESS_SAVE_FILE" ]; then
grep -v "^${MONITOR}:" "$BRIGHTNESS_SAVE_FILE" >"${BRIGHTNESS_SAVE_FILE}.tmp" 2>/dev/null || true
echo "${MONITOR}:${CURRENT}" >>"${BRIGHTNESS_SAVE_FILE}.tmp"
mv "${BRIGHTNESS_SAVE_FILE}.tmp" "$BRIGHTNESS_SAVE_FILE"
else
echo "${MONITOR}:${CURRENT}" >"$BRIGHTNESS_SAVE_FILE"
fi
echo "Saved current brightness for $MONITOR (${CURRENT}%)"
fi
fi
# Set brightness
NORMALIZED=$(awk "BEGIN {printf \"%.2f\", $VALUE / 100}")
if [ -z "$MONITOR" ]; then
# Set all monitors
qs ipc --pid "$PID" call brightness set "$NORMALIZED" "" 2>/dev/null || {
echo "Error: Could not set brightness"
exit 1
}
echo "Set brightness to ${VALUE}% for all monitors"
else
# Set specific monitor
qs ipc --pid "$PID" call brightness set "$NORMALIZED" "$MONITOR" 2>/dev/null || {
echo "Error: Could not set brightness for $MONITOR"
exit 1
}
echo "Set brightness to ${VALUE}% for $MONITOR"
fi
;;
version | -v | --version)
echo "NothingLess $(cat "${SCRIPT_DIR}/version")"
;;
install)
TARGET="${2:-}"
MODE="auto"
# Parse optional flags
if [ "$TARGET" = "hyprland" ]; then
shift 2 2>/dev/null || true
for arg in "$@"; do
case "$arg" in
--lua) MODE="lua" ;;
--conf) MODE="conf" ;;
*) echo "Warning: Unknown option '$arg'. Use --lua or --conf." ;;
esac
done
elif [ "$TARGET" != "hyprland" ]; then
echo "Error: Unknown target '$TARGET'. Supported: hyprland"
exit 1
fi
HYPR_DIR="$HOME/.config/hypr"
HYPR_LUA="$HYPR_DIR/hyprland.lua"
HYPR_CONF="$HYPR_DIR/hyprland.conf"
SHARE_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/nothingless"
# Create directories if needed
mkdir -p "$HYPR_DIR"
mkdir -p "$SHARE_DIR"
# ---- Resolve full path to nothingless binary ----
# On NixOS, Hyprland's exec-once runs before full user PATH is available,
# so we need the absolute path. Resolve it once at install time.
NL_BIN="nothingless"
if command -v nothingless >/dev/null 2>&1; then
NL_BIN="$(command -v nothingless)"
elif [ -x /run/current-system/sw/bin/nothingless ]; then
NL_BIN="/run/current-system/sw/bin/nothingless"
fi
# ---- Base config content - always valid conf syntax ----
BASE_CONF=$(cat <<-ENDCONF
exec-once = sh -c '[ -f /tmp/.nl_booted ] || { touch /tmp/.nl_booted && ${NL_BIN}; }'
# Keybinds are generated by sync-hyprland.py
ENDCONF
)
# ---- Detect mode if auto ----
if [ "$MODE" = "auto" ]; then
if [ -f "$HYPR_LUA" ]; then
MODE="lua"
elif [ -f "$HYPR_CONF" ]; then
MODE="conf"
else
# No existing config — create one in conf mode
echo "No hyprland config found. Creating one..." >&2
MODE="conf"
fi
fi
# ---- Generate config files ----
if [ "$MODE" = "lua" ]; then
# Hyprland >= 0.55 uses pure Lua. Write a header with the
# autostart via hl.on("hyprland.start") — the official API.
# sync-hyprland.py injects hl.config() + hl.bind() below.
{
printf -- "-- NothingLess Hyprland config\n"
printf -- "-- Generated by NothingLess\n"
printf "\n"
printf "hl.on(\"hyprland.start\", function ()\n"
printf " hl.exec_cmd(\"sh -c '%s'\")\n" "[ -f /tmp/.nl_booted ] || { touch /tmp/.nl_booted && ${NL_BIN}; }"
printf " hl.exec_cmd(\"axctl -c %s/axctl.toml daemon\")\n" "$SHARE_DIR"
printf "end)\n"
printf "\n"
printf -- "-- Compositor and keybinds injected by sync-hyprland.py below\n"
} > "$SHARE_DIR/hyprland.lua"
echo "Created compositor Lua config at $SHARE_DIR/hyprland.lua"
append_nothingless_hyprland_block "$HYPR_LUA" "$NOTHINGLESS_HYPR_LUA_SOURCE" "$NOTHINGLESS_HYPR_LUA_BLOCK"
remove_nothingless_hyprland_block "$HYPR_CONF" "$NOTHINGLESS_HYPR_CONF_SOURCE" 2>/dev/null || true
else
printf "%s\n" "$BASE_CONF" > "$SHARE_DIR/hyprland.conf"
echo "Created compositor config at $SHARE_DIR/hyprland.conf"
append_nothingless_hyprland_block "$HYPR_CONF" "$NOTHINGLESS_HYPR_CONF_SOURCE" "$NOTHINGLESS_HYPR_CONF_BLOCK"
remove_nothingless_hyprland_block "$HYPR_LUA" "$NOTHINGLESS_HYPR_LUA_SOURCE" 2>/dev/null || true
fi
# Run sync script to generate full configs (keybinds, compositor, axctl.toml)
# and apply live via axctl
SYNC_SCRIPT="${SCRIPT_DIR}/scripts/sync-hyprland.py"
if [ -f "$SYNC_SCRIPT" ]; then
echo "Generating full config with sync-hyprland.py..."
python3 "$SYNC_SCRIPT" --apply 2>&1 || echo "Warning: sync-hyprland.py failed"
elif [ -f "${SCRIPT_DIR}/scripts/sync-hyprland-conf.py" ]; then
# Legacy fallback
echo "Generating full config with sync-hyprland-conf.py..."
python3 "${SCRIPT_DIR}/scripts/sync-hyprland-conf.py" 2>&1 || echo "Warning: sync-hyprland-conf.py failed"
else
echo "Warning: sync-hyprland.py not found at $SYNC_SCRIPT" >&2
fi
# Clean up stale binds.json (Ambxs migration artifacts)
if [ -f "$HOME/.config/nothingless/binds.json" ]; then
if grep -q 'defaultAmbxstBinds\|"system.lock"' "$HOME/.config/nothingless/binds.json" 2>/dev/null; then
echo "Cleaning stale binds.json (Ambxs migration artifacts)..."
rm -f "$HOME/.config/nothingless/binds.json"
echo "binds.json will be regenerated with correct defaults on next NothingLess startup."
fi