-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdef_system.nu
More file actions
126 lines (112 loc) · 2.95 KB
/
def_system.nu
File metadata and controls
126 lines (112 loc) · 2.95 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
#copy text to clipboard
export def copy [
] {
if $env.XDG_CURRENT_DESKTOP == "gnome" {
xsel --input --clipboard
} else if $env.XDG_CURRENT_DESKTOP == "Hyprland" {
wl-copy
}
}
#copy pwd
export def cpwd [] {
$env.PWD | copy
}
#check if drive is mounted
export def is-mounted [drive:string] {
(ls ~/media | find $"($drive)" | length) > 0
}
#countdown alarm
export def countdown [
n: int #time in seconds
] {
let BEEP = [$env.MY_ENV_VARS.linux_backup "alarm-clock-elapsed.oga"] | path join
let muted = if (which wpctl | is-not-empty) {
# PipeWire/WirePlumber method
let status = wpctl get-volume @DEFAULT_AUDIO_SINK@
if ($status | str contains "[MUTED]") {
"yes"
} else {
"no"
}
} else {
# PulseAudio method
pacmd list-sinks
| lines
| find muted
| parse "{state}: {value}"
| get value
| get 0
}
if $muted == 'no' {
termdown $n
^mpv --no-terminal $BEEP
return
}
termdown $n
unmute
^mpv --no-terminal $BEEP
mute
}
#reset alpine authentification
export def reset-alpine-auth [] {
rm ~/.pine-passfile
touch ~/.pine-passfile
alpine-notify -i
}
#enable ssh without password
export def ssh-sin-pass [
user:string
ip:string
--port(-p):int = 22
] {
if not ("~/.ssh/id_rsa.pub" | path expand | path exists) {
ssh-keygen -t rsa
}
ssh-copy-id -i ~/.ssh/id_rsa.pub -p $port $"($user)@($ip)"
}
#clean nerd-fonts repo
export def nerd-fonts-clean [] {
cd ~/software/nerd-fonts/
rm -rf .git
rm -rf patched-fonts
}
# Performs logical operations on multiple predicates.
# User has to specify exactly one of the following flags: `--all`, `--any` or `--one-of`.
export def verify [
clausules?
--not(-n) # Negate the test result
--false(-f) # The default behavior is to test truthiness of the predicates. Use this flag to test falsiness instead.
--and(-a) # All of the given predicates should test positive
--or(-o) # At least one of the given predicates should test positive
--xor(-x) # Exactly one of the given predicates should test positive
]: [
list<bool> -> bool
list<closure> -> bool
] {
let inputs = if ($clausules | is-empty) {$in} else {$clausules}
let test_value = not $false
let op = {|item|
match ($item | describe) {
"bool" => $item
"closure" => {do $item}
$x => {error make {msg: $"inputs of type ($x) is not supported. Please check."}}
}
}
let res = match [$and $or $xor] {
[true false false] => { $inputs | all {|item| (do $op $item) == $test_value} }
[false true false] => { $inputs | any {|item| (do $op $item) == $test_value} }
[false false true] => {
mut res = false
mut first_true = false
for $item in $inputs {
match [((do $op $item) == $test_value) $first_true] {
[false _] => {}
[true false] => {$first_true = true; $res = true;}
[true true] => {$res = false;}
}
}
$res
}
}
$not xor $res
}