diff options
Diffstat (limited to 'dot_config/i3/scripts')
22 files changed, 1433 insertions, 0 deletions
diff --git a/dot_config/i3/scripts/executable_bandwidth2 b/dot_config/i3/scripts/executable_bandwidth2 new file mode 100644 index 0000000..ebd398a --- /dev/null +++ b/dot_config/i3/scripts/executable_bandwidth2 | |||
@@ -0,0 +1,105 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | # | ||
3 | # Copyright (C) 2015 James Murphy | ||
4 | # Licensed under the terms of the GNU GPL v2 only. | ||
5 | # | ||
6 | # i3blocks blocklet script to monitor bandwidth usage | ||
7 | |||
8 | iface="${BLOCK_INSTANCE}" | ||
9 | iface="${IFACE:-$iface}" | ||
10 | dt="${DT:-3}" | ||
11 | unit="${UNIT:-KB}" | ||
12 | LABEL="${LABEL:-: }" # down arrow up arrow | ||
13 | #LABEL="${LABEL:-<span font='FontAwesome'> </span>}" # down arrow up arrow | ||
14 | printf_command="${PRINTF_COMMAND:-"printf \"${LABEL}%1.0f/%1.0f %s/s\\n\", rx, wx, unit;"}" | ||
15 | |||
16 | function default_interface { | ||
17 | ip route | awk '/^default via/ {print $5; exit}' | ||
18 | } | ||
19 | |||
20 | function check_proc_net_dev { | ||
21 | if [ ! -f "/proc/net/dev" ]; then | ||
22 | echo "/proc/net/dev not found" | ||
23 | exit 1 | ||
24 | fi | ||
25 | } | ||
26 | |||
27 | function list_interfaces { | ||
28 | check_proc_net_dev | ||
29 | echo "Interfaces in /proc/net/dev:" | ||
30 | grep -o "^[^:]\\+:" /proc/net/dev | tr -d " :" | ||
31 | } | ||
32 | |||
33 | while getopts i:t:u:p:lh opt; do | ||
34 | case "$opt" in | ||
35 | i) iface="$OPTARG" ;; | ||
36 | t) dt="$OPTARG" ;; | ||
37 | u) unit="$OPTARG" ;; | ||
38 | p) printf_command="$OPTARG" ;; | ||
39 | l) list_interfaces && exit 0 ;; | ||
40 | h) printf \ | ||
41 | "Usage: bandwidth3 [-i interface] [-t time] [-u unit] [-p printf_command] [-l] [-h] | ||
42 | Options: | ||
43 | -i\tNetwork interface to measure. Default determined using \`ip route\`. | ||
44 | -t\tTime interval in seconds between measurements. Default: 3 | ||
45 | -u\tUnits to measure bytes in. Default: Mb | ||
46 | \tAllowed units: Kb, KB, Mb, MB, Gb, GB, Tb, TB | ||
47 | \tUnits may have optional it/its/yte/ytes on the end, e.g. Mbits, KByte | ||
48 | -p\tAwk command to be called after a measurement is made. | ||
49 | \tDefault: printf \"<span font='FontAwesome'> </span>%%-5.1f/%%5.1f %%s/s\\\\n\", rx, wx, unit; | ||
50 | \tExposed variables: rx, wx, tx, unit, iface | ||
51 | -l\tList available interfaces in /proc/net/dev | ||
52 | -h\tShow this help text | ||
53 | " && exit 0;; | ||
54 | esac | ||
55 | done | ||
56 | |||
57 | check_proc_net_dev | ||
58 | |||
59 | iface="${iface:-$(default_interface)}" | ||
60 | while [ -z "$iface" ]; do | ||
61 | echo No default interface | ||
62 | sleep "$dt" | ||
63 | iface=$(default_interface) | ||
64 | done | ||
65 | |||
66 | case "$unit" in | ||
67 | Kb|Kbit|Kbits) bytes_per_unit=$((1024 / 8));; | ||
68 | KB|KByte|KBytes) bytes_per_unit=$((1024));; | ||
69 | Mb|Mbit|Mbits) bytes_per_unit=$((1024 * 1024 / 8));; | ||
70 | MB|MByte|MBytes) bytes_per_unit=$((1024 * 1024));; | ||
71 | Gb|Gbit|Gbits) bytes_per_unit=$((1024 * 1024 * 1024 / 8));; | ||
72 | GB|GByte|GBytes) bytes_per_unit=$((1024 * 1024 * 1024));; | ||
73 | Tb|Tbit|Tbits) bytes_per_unit=$((1024 * 1024 * 1024 * 1024 / 8));; | ||
74 | TB|TByte|TBytes) bytes_per_unit=$((1024 * 1024 * 1024 * 1024));; | ||
75 | *) echo Bad unit "$unit" && exit 1;; | ||
76 | esac | ||
77 | |||
78 | scalar=$((bytes_per_unit * dt)) | ||
79 | init_line=$(cat /proc/net/dev | grep "^[ ]*$iface:") | ||
80 | if [ -z "$init_line" ]; then | ||
81 | echo Interface not found in /proc/net/dev: "$iface" | ||
82 | exit 1 | ||
83 | fi | ||
84 | |||
85 | init_received=$(awk '{print $2}' <<< $init_line) | ||
86 | init_sent=$(awk '{print $10}' <<< $init_line) | ||
87 | |||
88 | (while true; do cat /proc/net/dev; sleep "$dt"; done) |\ | ||
89 | stdbuf -oL grep "^[ ]*$iface:" |\ | ||
90 | awk -v scalar="$scalar" -v unit="$unit" -v iface="$iface" ' | ||
91 | BEGIN{old_received='"$init_received"';old_sent='"$init_sent"'} | ||
92 | { | ||
93 | received=$2 | ||
94 | sent=$10 | ||
95 | rx=(received-old_received)/scalar; | ||
96 | wx=(sent-old_sent)/scalar; | ||
97 | tx=rx+wr; | ||
98 | old_received=received; | ||
99 | old_sent=sent; | ||
100 | if(rx >= 0 && wx >= 0){ | ||
101 | '"$printf_command"'; | ||
102 | fflush(stdout); | ||
103 | } | ||
104 | } | ||
105 | ' | ||
diff --git a/dot_config/i3/scripts/executable_battery-pinebook-pro b/dot_config/i3/scripts/executable_battery-pinebook-pro new file mode 100644 index 0000000..fd97370 --- /dev/null +++ b/dot_config/i3/scripts/executable_battery-pinebook-pro | |||
@@ -0,0 +1,18 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | #simple Shellscript for i3blocks on Pinebook pro | ||
3 | #05012020 [email protected] Gerhard S. | ||
4 | #battery-symbols: on Manjaro you need the awesome-terminal-fonts package installed! | ||
5 | PERCENT=$(cat /sys/class/power_supply/cw2015-battery/capacity) | ||
6 | STATUS=$(cat /sys/class/power_supply/cw2015-battery/status) | ||
7 | case $(( | ||
8 | $PERCENT >= 0 && $PERCENT <= 20 ? 1 : | ||
9 | $PERCENT > 20 && $PERCENT <= 40 ? 2 : | ||
10 | $PERCENT > 40 && $PERCENT <= 60 ? 3 : | ||
11 | $PERCENT > 60 && $PERCENT <= 80 ? 4 : 5)) in | ||
12 | # | ||
13 | (1) echo $STATUS:"" :$PERCENT%;; | ||
14 | (2) echo $STATUS:"" :$PERCENT%;; | ||
15 | (3) echo $STATUS:"" :$PERCENT%;; | ||
16 | (4) echo $STATUS:"" :$PERCENT%;; | ||
17 | (5) echo $STATUS:"" :$PERCENT%;; | ||
18 | esac | ||
diff --git a/dot_config/i3/scripts/executable_battery1 b/dot_config/i3/scripts/executable_battery1 new file mode 100644 index 0000000..3b9d5a7 --- /dev/null +++ b/dot_config/i3/scripts/executable_battery1 | |||
@@ -0,0 +1,114 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # Copyright 2014 Pierre Mavro <[email protected]> | ||
4 | # Copyright 2014 Vivien Didelot <[email protected]> | ||
5 | # | ||
6 | # Licensed under the terms of the GNU GPL v3, or any later version. | ||
7 | # | ||
8 | # This script is meant to use with i3blocks. It parses the output of the "acpi" | ||
9 | # command (often provided by a package of the same name) to read the status of | ||
10 | # the battery, and eventually its remaining time (to full charge or discharge). | ||
11 | # | ||
12 | # The color will gradually change for a percentage below 85%, and the urgency | ||
13 | # (exit code 33) is set if there is less that 5% remaining. | ||
14 | |||
15 | # Edited by Andreas Lindlbauer <[email protected]> | ||
16 | |||
17 | use strict; | ||
18 | use warnings; | ||
19 | use utf8; | ||
20 | |||
21 | # otherwise we get in console "Wide character in print at" | ||
22 | binmode(STDOUT, ':utf8'); | ||
23 | |||
24 | # my $acpi; | ||
25 | my $upower; | ||
26 | my $percent; | ||
27 | my $bat_state; | ||
28 | my $status; | ||
29 | my $ac_adapt; | ||
30 | my $full_text; | ||
31 | my $short_text; | ||
32 | my $label = '😅'; | ||
33 | my $bat_number = $ENV{BLOCK_INSTANCE} || 0; | ||
34 | |||
35 | open (UPOWER, "upower -i /org/freedesktop/UPower/devices/battery_BAT$bat_number | grep 'percentage' |") or die; | ||
36 | $upower = <UPOWER>; | ||
37 | close(UPOWER); | ||
38 | |||
39 | # fail on unexpected output | ||
40 | if ($upower !~ /: (\d+)%/) { | ||
41 | die "$upower\n"; | ||
42 | } | ||
43 | |||
44 | $percent = $1; | ||
45 | $full_text = "$percent%"; | ||
46 | |||
47 | open (BAT_STATE, "upower -i /org/freedesktop/UPower/devices/battery_BAT$bat_number | grep 'state' |") or die; | ||
48 | $bat_state = <BAT_STATE>; | ||
49 | close(BAT_STATE); | ||
50 | |||
51 | if ($bat_state !~ /: (\w+)/) { | ||
52 | die "$bat_state\n"; | ||
53 | } | ||
54 | $status = $1; | ||
55 | |||
56 | if ($status eq 'discharging') { | ||
57 | $full_text .= ' '; | ||
58 | } elsif ($status eq 'charging') { | ||
59 | $full_text .= ' '; | ||
60 | } elsif ($status eq 'Unknown') { | ||
61 | open (AC_ADAPTER, "acpi -a |") or die; | ||
62 | $ac_adapt = <AC_ADAPTER>; | ||
63 | close(AC_ADAPTER); | ||
64 | |||
65 | if ($ac_adapt =~ /: ([\w-]+)/) { | ||
66 | $ac_adapt = $1; | ||
67 | |||
68 | if ($ac_adapt eq 'on-line') { | ||
69 | $full_text .= ' CHR'; | ||
70 | } elsif ($ac_adapt eq 'off-line') { | ||
71 | $full_text .= ' DIS'; | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | |||
76 | $short_text = $full_text; | ||
77 | |||
78 | if ($percent < 20) { | ||
79 | $label = ''; | ||
80 | } elsif ($percent < 45) { | ||
81 | $label = ''; | ||
82 | } elsif ($percent < 70) { | ||
83 | $label = ''; | ||
84 | } elsif ($percent < 95) { | ||
85 | $label = ''; | ||
86 | } else { | ||
87 | $label = ''; | ||
88 | } | ||
89 | |||
90 | # print text | ||
91 | print " ${label}"; | ||
92 | print " $full_text\n"; | ||
93 | print " ${label}"; | ||
94 | print " $short_text\n"; | ||
95 | |||
96 | # consider color and urgent flag only on discharge | ||
97 | if ($status eq 'discharging') { | ||
98 | |||
99 | if ($percent < 20) { | ||
100 | print "#FF0000\n"; | ||
101 | } elsif ($percent < 40) { | ||
102 | print "#FFAE00\n"; | ||
103 | } elsif ($percent < 60) { | ||
104 | print "#FFF600\n"; | ||
105 | } elsif ($percent < 85) { | ||
106 | print "#A8FF00\n"; | ||
107 | } | ||
108 | |||
109 | if ($percent < 5) { | ||
110 | exit(33); | ||
111 | } | ||
112 | } | ||
113 | |||
114 | exit(0); | ||
diff --git a/dot_config/i3/scripts/executable_battery2 b/dot_config/i3/scripts/executable_battery2 new file mode 100644 index 0000000..2d55dab --- /dev/null +++ b/dot_config/i3/scripts/executable_battery2 | |||
@@ -0,0 +1,106 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | # | ||
3 | # Copyright (C) 2016 James Murphy | ||
4 | # Licensed under the GPL version 2 only | ||
5 | # | ||
6 | # A battery indicator blocklet script for i3blocks | ||
7 | |||
8 | from subprocess import check_output | ||
9 | import os | ||
10 | import re | ||
11 | |||
12 | config = dict(os.environ) | ||
13 | status = check_output(['acpi'], universal_newlines=True) | ||
14 | |||
15 | if not status: | ||
16 | # stands for no battery found | ||
17 | color = config.get("color_10", "red") | ||
18 | fulltext = "<span color='{}'><span font='FontAwesome'>\uf00d \uf240</span></span>".format(color) | ||
19 | percentleft = 100 | ||
20 | else: | ||
21 | # if there is more than one battery in one laptop, the percentage left is | ||
22 | # available for each battery separately, although state and remaining | ||
23 | # time for overall block is shown in the status of the first battery | ||
24 | batteries = status.split("\n") | ||
25 | state_batteries=[] | ||
26 | commasplitstatus_batteries=[] | ||
27 | percentleft_batteries=[] | ||
28 | time = "" | ||
29 | for battery in batteries: | ||
30 | if battery!='': | ||
31 | state_batteries.append(battery.split(": ")[1].split(", ")[0]) | ||
32 | commasplitstatus = battery.split(", ") | ||
33 | if not time: | ||
34 | time = commasplitstatus[-1].strip() | ||
35 | # check if it matches a time | ||
36 | time = re.match(r"(\d+):(\d+)", time) | ||
37 | if time: | ||
38 | time = ":".join(time.groups()) | ||
39 | timeleft = " ({})".format(time) | ||
40 | else: | ||
41 | timeleft = "" | ||
42 | |||
43 | p = int(commasplitstatus[1].rstrip("%\n")) | ||
44 | if p>0: | ||
45 | percentleft_batteries.append(p) | ||
46 | commasplitstatus_batteries.append(commasplitstatus) | ||
47 | state = state_batteries[0] | ||
48 | commasplitstatus = commasplitstatus_batteries[0] | ||
49 | if percentleft_batteries: | ||
50 | percentleft = int(sum(percentleft_batteries)/len(percentleft_batteries)) | ||
51 | else: | ||
52 | percentleft = 0 | ||
53 | |||
54 | # stands for charging | ||
55 | color = config.get("color_charging", "yellow") | ||
56 | FA_LIGHTNING = "<span color='{}'><span font='FontAwesome'>\uf0e7</span></span>".format(color) | ||
57 | |||
58 | # stands for plugged in | ||
59 | FA_PLUG = "<span font='FontAwesome'>\uf1e6</span>" | ||
60 | |||
61 | # stands for using battery | ||
62 | FA_BATTERY = "<span font='FontAwesome'>\uf240</span>" | ||
63 | |||
64 | # stands for unknown status of battery | ||
65 | FA_QUESTION = "<span font='FontAwesome'>\uf128</span>" | ||
66 | |||
67 | |||
68 | if state == "Discharging": | ||
69 | fulltext = FA_BATTERY + " " | ||
70 | elif state == "Full": | ||
71 | fulltext = FA_PLUG + " " | ||
72 | timeleft = "" | ||
73 | elif state == "Unknown": | ||
74 | fulltext = FA_QUESTION + " " + FA_BATTERY + " " | ||
75 | timeleft = "" | ||
76 | else: | ||
77 | fulltext = FA_LIGHTNING + " " + FA_PLUG + " " | ||
78 | |||
79 | def color(percent): | ||
80 | if percent < 10: | ||
81 | # exit code 33 will turn background red | ||
82 | return config.get("color_10", "#FFFFFF") | ||
83 | if percent < 20: | ||
84 | return config.get("color_20", "#FF3300") | ||
85 | if percent < 30: | ||
86 | return config.get("color_30", "#FF6600") | ||
87 | if percent < 40: | ||
88 | return config.get("color_40", "#FF9900") | ||
89 | if percent < 50: | ||
90 | return config.get("color_50", "#FFCC00") | ||
91 | if percent < 60: | ||
92 | return config.get("color_60", "#FFFF00") | ||
93 | if percent < 70: | ||
94 | return config.get("color_70", "#FFFF33") | ||
95 | if percent < 80: | ||
96 | return config.get("color_80", "#FFFF66") | ||
97 | return config.get("color_full", "#FFFFFF") | ||
98 | |||
99 | form = '<span color="{}">{}%</span>' | ||
100 | fulltext += form.format(color(percentleft), percentleft) | ||
101 | #fulltext += timeleft | ||
102 | |||
103 | print(fulltext) | ||
104 | print(fulltext) | ||
105 | if percentleft < 10: | ||
106 | exit(33) | ||
diff --git a/dot_config/i3/scripts/executable_blur-lock b/dot_config/i3/scripts/executable_blur-lock new file mode 100644 index 0000000..4ff7ed6 --- /dev/null +++ b/dot_config/i3/scripts/executable_blur-lock | |||
@@ -0,0 +1,11 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | PICTURE=/tmp/i3lock.png | ||
4 | SCREENSHOT="scrot -z $PICTURE" | ||
5 | |||
6 | BLUR="5x4" | ||
7 | |||
8 | $SCREENSHOT | ||
9 | convert $PICTURE -blur $BLUR $PICTURE | ||
10 | i3lock -i $PICTURE | ||
11 | rm $PICTURE | ||
diff --git a/dot_config/i3/scripts/executable_cpu_usage b/dot_config/i3/scripts/executable_cpu_usage new file mode 100644 index 0000000..8d8a267 --- /dev/null +++ b/dot_config/i3/scripts/executable_cpu_usage | |||
@@ -0,0 +1,62 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # | ||
3 | # Copyright 2014 Pierre Mavro <[email protected]> | ||
4 | # Copyright 2014 Vivien Didelot <[email protected]> | ||
5 | # Copyright 2014 Andreas Guldstrand <[email protected]> | ||
6 | # | ||
7 | # Licensed under the terms of the GNU GPL v3, or any later version. | ||
8 | |||
9 | use strict; | ||
10 | use warnings; | ||
11 | use utf8; | ||
12 | use Getopt::Long; | ||
13 | |||
14 | # default values | ||
15 | my $t_warn = $ENV{T_WARN} // 50; | ||
16 | my $t_crit = $ENV{T_CRIT} // 80; | ||
17 | my $cpu_usage = -1; | ||
18 | my $decimals = $ENV{DECIMALS} // 0; | ||
19 | my $label = $ENV{LABEL} // ""; | ||
20 | |||
21 | sub help { | ||
22 | print "Usage: cpu_usage [-w <warning>] [-c <critical>] [-d <decimals>]\n"; | ||
23 | print "-w <percent>: warning threshold to become yellow\n"; | ||
24 | print "-c <percent>: critical threshold to become red\n"; | ||
25 | print "-d <decimals>: Use <decimals> decimals for percentage (default is $decimals) \n"; | ||
26 | exit 0; | ||
27 | } | ||
28 | |||
29 | GetOptions("help|h" => \&help, | ||
30 | "w=i" => \$t_warn, | ||
31 | "c=i" => \$t_crit, | ||
32 | "d=i" => \$decimals, | ||
33 | ); | ||
34 | |||
35 | # Get CPU usage | ||
36 | $ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is | ||
37 | open (MPSTAT, 'mpstat 1 1 |') or die; | ||
38 | while (<MPSTAT>) { | ||
39 | if (/^.*\s+(\d+\.\d+)[\s\x00]?$/) { | ||
40 | $cpu_usage = 100 - $1; # 100% - %idle | ||
41 | last; | ||
42 | } | ||
43 | } | ||
44 | close(MPSTAT); | ||
45 | |||
46 | $cpu_usage eq -1 and die 'Can\'t find CPU information'; | ||
47 | |||
48 | # Print short_text, full_text | ||
49 | print "${label}"; | ||
50 | printf "%02.${decimals}f%%\n", $cpu_usage; | ||
51 | print "${label}"; | ||
52 | printf "%02.${decimals}f%%\n", $cpu_usage; | ||
53 | |||
54 | # Print color, if needed | ||
55 | if ($cpu_usage >= $t_crit) { | ||
56 | print "#FF0000\n"; | ||
57 | exit 33; | ||
58 | } elsif ($cpu_usage >= $t_warn) { | ||
59 | print "#FFFC00\n"; | ||
60 | } | ||
61 | |||
62 | exit 0; | ||
diff --git a/dot_config/i3/scripts/executable_disk b/dot_config/i3/scripts/executable_disk new file mode 100644 index 0000000..e18c7aa --- /dev/null +++ b/dot_config/i3/scripts/executable_disk | |||
@@ -0,0 +1,48 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | # Copyright (C) 2014 Julien Bonjean <[email protected]> | ||
3 | |||
4 | # This program is free software: you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU General Public License as published by | ||
6 | # the Free Software Foundation, either version 3 of the License, or | ||
7 | # (at your option) any later version. | ||
8 | |||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | |||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | DIR="${DIR:-$BLOCK_INSTANCE}" | ||
18 | DIR="${DIR:-$HOME}" | ||
19 | ALERT_LOW="${ALERT_LOW:-$1}" | ||
20 | ALERT_LOW="${ALERT_LOW:-10}" # color will turn red under this value (default: 10%) | ||
21 | |||
22 | LOCAL_FLAG="-l" | ||
23 | if [ "$1" = "-n" ] || [ "$2" = "-n" ]; then | ||
24 | LOCAL_FLAG="" | ||
25 | fi | ||
26 | |||
27 | df -h -P $LOCAL_FLAG "$DIR" | awk -v label="$LABEL" -v alert_low=$ALERT_LOW ' | ||
28 | /\/.*/ { | ||
29 | # full text | ||
30 | print label $4 | ||
31 | |||
32 | # short text | ||
33 | print label $4 | ||
34 | |||
35 | use=$5 | ||
36 | |||
37 | # no need to continue parsing | ||
38 | exit 0 | ||
39 | } | ||
40 | |||
41 | END { | ||
42 | gsub(/%$/,"",use) | ||
43 | if (100 - use < alert_low) { | ||
44 | # color | ||
45 | print "#FF0000" | ||
46 | } | ||
47 | } | ||
48 | ' | ||
diff --git a/dot_config/i3/scripts/executable_keyboard-layout b/dot_config/i3/scripts/executable_keyboard-layout new file mode 100644 index 0000000..9a3e314 --- /dev/null +++ b/dot_config/i3/scripts/executable_keyboard-layout | |||
@@ -0,0 +1,5 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | KBD=$(/usr/bin/xkblayout-state print '%s') | ||
4 | echo $KBD | ||
5 | |||
diff --git a/dot_config/i3/scripts/executable_keyhint b/dot_config/i3/scripts/executable_keyhint new file mode 100644 index 0000000..8b8c3e3 --- /dev/null +++ b/dot_config/i3/scripts/executable_keyhint | |||
@@ -0,0 +1,25 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | Main() { | ||
4 | source /usr/share/endeavouros/scripts/eos-script-lib-yad || return 1 | ||
5 | |||
6 | local command=( | ||
7 | eos_yad --title="EndeavourOS i3-wm keybindings:" --no-buttons --geometry=400x345-15-400 --list | ||
8 | --column=key: --column=description: --column=command: | ||
9 | "ESC" "close this app" "" | ||
10 | "=" "modkey" "(set mod Mod4)" | ||
11 | "+enter" "open a terminal" "" | ||
12 | "+Shift+n" "new empty workspace" "" | ||
13 | "+w" "open Browser" "" | ||
14 | "+n" "open Filebrowser" "" | ||
15 | "+d" "app menu" "" | ||
16 | "+q" "close focused app" "" | ||
17 | "Print-key" "screenshot" "" | ||
18 | "+Shift+e" "logout menu" "" | ||
19 | "F1" "open keybinding helper" "" | ||
20 | ) | ||
21 | |||
22 | "${command[@]}" | ||
23 | } | ||
24 | |||
25 | Main "$@" | ||
diff --git a/dot_config/i3/scripts/executable_keyhint-2 b/dot_config/i3/scripts/executable_keyhint-2 new file mode 100644 index 0000000..2e86d12 --- /dev/null +++ b/dot_config/i3/scripts/executable_keyhint-2 | |||
@@ -0,0 +1,6 @@ | |||
1 | I3_CONFIG=$HOME/.config/i3/config | ||
2 | mod_key=$(sed -nre 's/^set \$mod (.*)/\1/p' ${I3_CONFIG}) | ||
3 | grep "^bindsym" ${I3_CONFIG} \ | ||
4 | | sed "s/-\(-\w\+\)\+//g;s/\$mod/${mod_key}/g;s/Mod1/Alt/g;s/exec //;s/bindsym //;s/^\s\+//;s/^\([^ ]\+\) \(.\+\)$/\2: \1/;s/^\s\+//" \ | ||
5 | | tr -s ' ' \ | ||
6 | | rofi -dmenu -theme ~/.config/rofi/rofikeyhint.rasi | ||
diff --git a/dot_config/i3/scripts/executable_literal_empty_workspace b/dot_config/i3/scripts/executable_literal_empty_workspace new file mode 100644 index 0000000..b962cde --- /dev/null +++ b/dot_config/i3/scripts/executable_literal_empty_workspace | |||
@@ -0,0 +1,10 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | MAX_DESKTOPS=20 | ||
4 | |||
5 | WORKSPACES=$(seq -s '\n' 1 1 ${MAX_DESKTOPS}) | ||
6 | |||
7 | EMPTY_WORKSPACE=$( (i3-msg -t get_workspaces | tr ',' '\n' | grep num | awk -F: '{print int($2)}' ; \ | ||
8 | echo -e ${WORKSPACES} ) | sort -n | uniq -u | head -n 1) | ||
9 | |||
10 | i3-msg workspace ${EMPTY_WORKSPACE} | ||
diff --git a/dot_config/i3/scripts/executable_memory b/dot_config/i3/scripts/executable_memory new file mode 100644 index 0000000..6a69a6f --- /dev/null +++ b/dot_config/i3/scripts/executable_memory | |||
@@ -0,0 +1,69 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | # Copyright (C) 2014 Julien Bonjean <[email protected]> | ||
3 | |||
4 | # This program is free software: you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU General Public License as published by | ||
6 | # the Free Software Foundation, either version 3 of the License, or | ||
7 | # (at your option) any later version. | ||
8 | |||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | |||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | TYPE="${BLOCK_INSTANCE:-mem}" | ||
18 | |||
19 | awk -v type=$TYPE ' | ||
20 | /^MemTotal:/ { | ||
21 | mem_total=$2 | ||
22 | } | ||
23 | /^MemFree:/ { | ||
24 | mem_free=$2 | ||
25 | } | ||
26 | /^Buffers:/ { | ||
27 | mem_free+=$2 | ||
28 | } | ||
29 | /^Cached:/ { | ||
30 | mem_free+=$2 | ||
31 | } | ||
32 | /^SwapTotal:/ { | ||
33 | swap_total=$2 | ||
34 | } | ||
35 | /^SwapFree:/ { | ||
36 | swap_free=$2 | ||
37 | } | ||
38 | END { | ||
39 | if (type == "swap") { | ||
40 | free=swap_free/1024/1024 | ||
41 | used=(swap_total-swap_free)/1024/1024 | ||
42 | total=swap_total/1024/1024 | ||
43 | } else { | ||
44 | free=mem_free/1024/1024 | ||
45 | used=(mem_total-mem_free)/1024/1024 | ||
46 | total=mem_total/1024/1024 | ||
47 | } | ||
48 | |||
49 | pct=0 | ||
50 | if (total > 0) { | ||
51 | pct=used/total*100 | ||
52 | } | ||
53 | |||
54 | # full text | ||
55 | # printf("%.1fG/%.1fG (%.f%%)\n", used, total, pct) | ||
56 | |||
57 | # short text | ||
58 | printf("%.f%%\n", pct) | ||
59 | |||
60 | # color | ||
61 | if (pct > 90) { | ||
62 | print("#FF0000") | ||
63 | } else if (pct > 80) { | ||
64 | print("#FFAE00") | ||
65 | } else if (pct > 70) { | ||
66 | print("#FFF600") | ||
67 | } | ||
68 | } | ||
69 | ' /proc/meminfo | ||
diff --git a/dot_config/i3/scripts/executable_openweather b/dot_config/i3/scripts/executable_openweather new file mode 100644 index 0000000..c51f9d3 --- /dev/null +++ b/dot_config/i3/scripts/executable_openweather | |||
@@ -0,0 +1,93 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | # Edited by Andreas Lindlbauer <[email protected]> | ||
3 | |||
4 | temps=("#0600FF" "#0500FF" "#0400FF" "#0300FF" "#0200FF" "#0100FF" "#0000FF" "#0002FF" "#0012FF" "#0022FF" "#0032FF" "#0044FF" "#0054FF" "#0064FF" "#0074FF" "#0084FF" "#0094FF" "#00A4FF" "#00B4FF" "#00C4FF" "#00D4FF" "#00E4FF" "#00FFF4" "#00FFD0" "#00FFA8" "#00FF83" "#00FF5C" "#00FF36" "#00FF10" "#17FF00" "#3EFF00" "#65FF00" "#B0FF00" "#FDFF00" "#FFF000" "#FFDC00" "#FFC800" "#FFB400" "#FFA000" "#FF8C00" "#FF7800" "#FF6400" "#FF5000" "#FF3C00" "#FF2800" "#FF1400" "#FF0000") | ||
5 | |||
6 | command -v jq >/dev/null 2>&1 || { echo >&2 "Program 'jq' required but it is not installed. | ||
7 | Aborting."; exit 1; } | ||
8 | command -v wget >/dev/null 2>&1 || { echo >&2 "Program 'wget' required but is not installed. | ||
9 | Aborting."; exit 1; } | ||
10 | |||
11 | # To use this script you need to create an API key here https://home.openweathermap.org | ||
12 | # You need to put your Open Weather APIKEY here: | ||
13 | APIKEY="keykeykey" | ||
14 | # And get your Latitute and Longitudes to put in here: | ||
15 | LAT="XX.XXXX" | ||
16 | LON="XX.XXXX" | ||
17 | URL="http://api.openweathermap.org/data/2.5/onecall?lat=${LAT}&lon=${LON}&units=metric&exclude=minutely,hourly,daily&APPID=${APIKEY}" | ||
18 | WEATHER_RESPONSE=$(wget -qO- "${URL}") | ||
19 | |||
20 | WEATHER_CONDITION=$(echo "$WEATHER_RESPONSE" | jq '.current.weather[0].main' | sed 's/"//g') | ||
21 | WEATHER_TEMP=$(echo "$WEATHER_RESPONSE" | jq '.current.feels_like') | ||
22 | WEATHER_INT=${WEATHER_TEMP%.*} | ||
23 | |||
24 | TIME_NOW=$( echo "$WEATHER_RESPONSE" | jq '.current.dt') | ||
25 | SUNRISE=$( echo "$WEATHER_RESPONSE" | jq '.current.sunrise') | ||
26 | SUNSET=$( echo "$WEATHER_RESPONSE" | jq '.current.sunset') | ||
27 | DESCRIPTION=$( echo "$WEATHER_RESPONSE" | jq '.current.weather[0].description' | sed 's/"//g') | ||
28 | WEATHER_ALERT=$( echo "$WEATHER_RESPONSE" | jq '.alerts[0].event' | sed 's/"//g') | ||
29 | DAYTIME="n" | ||
30 | |||
31 | if [[ "$TIME_NOW" > "$SUNRISE" ]] && [[ "$TIME_NOW" < "$SUNSET" ]]; then | ||
32 | DAYTIME="d" | ||
33 | fi | ||
34 | |||
35 | case $WEATHER_CONDITION in | ||
36 | 'Clouds') | ||
37 | if [ "$DAYTIME" == "d" ]; then | ||
38 | WEATHER_ICON="" | ||
39 | else | ||
40 | WEATHER_ICON="" | ||
41 | fi | ||
42 | ;; | ||
43 | 'Rain') | ||
44 | WEATHER_ICON="" | ||
45 | ;; | ||
46 | 'Drizzle') | ||
47 | if [ "$DAYTIME" == "d" ]; then | ||
48 | WEATHER_ICON="" | ||
49 | else | ||
50 | WEATHER_ICON="" | ||
51 | fi | ||
52 | ;; | ||
53 | 'Thunderstorm') | ||
54 | WEATHER_ICON="" | ||
55 | ;; | ||
56 | 'Snow') | ||
57 | WEATHER_ICON="" | ||
58 | ;; | ||
59 | 'Clear') | ||
60 | if [ "$DAYTIME" == "d" ]; then | ||
61 | WEATHER_ICON="" | ||
62 | else | ||
63 | WEATHER_ICON="" | ||
64 | fi | ||
65 | ;; | ||
66 | *) | ||
67 | WEATHER_ICON="🌫" | ||
68 | ;; | ||
69 | esac | ||
70 | |||
71 | WEATHER_COLOR="#FFFFFF" | ||
72 | if [ "$WEATHER_INT" -lt "-11" ]; then | ||
73 | WEATHER_COLOR="#0000FF" | ||
74 | elif [ "$WEATHER_INT" -gt 35 ]; then | ||
75 | WEATHER_COLOR="#FF0000" | ||
76 | else | ||
77 | WEATHER_INT=$(( WEATHER_INT + 11 )) | ||
78 | WEATHER_COLOR="${temps[$WEATHER_INT]}" | ||
79 | fi | ||
80 | |||
81 | full_text="${WEATHER_ICON} ${WEATHER_TEMP}°C: ${DESCRIPTION} " | ||
82 | if [ "$WEATHER_ALERT" != "null" ]; then | ||
83 | WARN_START=$(echo "$WEATHER_RESPONSE" | jq '.alerts[0].start') | ||
84 | WARN_END=$(echo "$WEATHER_RESPONSE" | jq '.alerts[0].end') | ||
85 | WARN_START=$(date -d @"$WARN_START" +%a_%k:%M) | ||
86 | WARN_END=$(date -d @"$WARN_END" +%a_%k:%M) | ||
87 | full_text="${WEATHER_ICON} ${WEATHER_TEMP}°C: ${DESCRIPTION} ${WEATHER_ALERT} from ${WARN_START} to ${WARN_END} " | ||
88 | fi | ||
89 | |||
90 | |||
91 | echo "${full_text}" | ||
92 | echo "${WEATHER_TEMP}°C " | ||
93 | echo "${WEATHER_COLOR}" | ||
diff --git a/dot_config/i3/scripts/executable_openweather-city b/dot_config/i3/scripts/executable_openweather-city new file mode 100644 index 0000000..6ea051c --- /dev/null +++ b/dot_config/i3/scripts/executable_openweather-city | |||
@@ -0,0 +1,43 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | command -v jq >/dev/null 2>&1 || { echo >&2 "Program 'jq' required but it is not installed. | ||
4 | Aborting."; exit 1; } | ||
5 | command -v wget >/dev/null 2>&1 || { echo >&2 "Program 'wget' required but is not installed. | ||
6 | Aborting."; exit 1; } | ||
7 | |||
8 | # To use this script you need to create an API key here https://home.openweathermap.org | ||
9 | # You need to put your Open Weather APIKEY here: | ||
10 | APIKEY="keykey" | ||
11 | # find your City ID here: https://openweathermap.org/ | ||
12 | # search for your city and copy the ID from the URL inside the browser. | ||
13 | CITY_ID="idid" | ||
14 | URL="http://api.openweathermap.org/data/2.5/weather?id=${CITY_ID}&units=metric&APPID=${APIKEY}" | ||
15 | |||
16 | WEATHER_RESPONSE=$(wget -qO- "${URL}") | ||
17 | |||
18 | WEATHER_CONDITION=$(echo $WEATHER_RESPONSE | jq '.weather[0].main' | sed 's/"//g') | ||
19 | WEATHER_TEMP=$(echo $WEATHER_RESPONSE | jq '.main.temp') | ||
20 | WIND_DIR=$( echo "$WEATHER_RESPONSE" | jq '.wind.deg') | ||
21 | WIND_SPEED=$( echo "$WEATHER_RESPONSE" | jq '.wind.speed') | ||
22 | |||
23 | WIND_SPEED=$(awk "BEGIN {print 60*60*$WIND_SPEED/1000}") | ||
24 | WIND_DIR=$(awk "BEGIN {print int(($WIND_DIR % 360)/22.5)}") | ||
25 | DIR_ARRAY=( N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW N ) | ||
26 | WIND_DIR=${DIR_ARRAY[WIND_DIR]} | ||
27 | |||
28 | case $WEATHER_CONDITION in | ||
29 | 'Clouds') | ||
30 | WEATHER_ICON="" | ||
31 | ;; | ||
32 | 'Rain') | ||
33 | WEATHER_ICON="" | ||
34 | ;; | ||
35 | 'Snow') | ||
36 | WEATHER_ICON="" | ||
37 | ;; | ||
38 | *) | ||
39 | WEATHER_ICON="" | ||
40 | ;; | ||
41 | esac | ||
42 | |||
43 | echo "${WEATHER_ICON} ${WEATHER_TEMP}°C: ${WIND_SPEED} km/h ${WIND_DIR}" | ||
diff --git a/dot_config/i3/scripts/executable_openweather.conf b/dot_config/i3/scripts/executable_openweather.conf new file mode 100644 index 0000000..f11aa86 --- /dev/null +++ b/dot_config/i3/scripts/executable_openweather.conf | |||
@@ -0,0 +1,5 @@ | |||
1 | # Weather | ||
2 | [Weather] | ||
3 | command=~/.config/i3/scripts/openweather | ||
4 | interval=1800 | ||
5 | color=#7275b3 | ||
diff --git a/dot_config/i3/scripts/executable_power-profiles b/dot_config/i3/scripts/executable_power-profiles new file mode 100644 index 0000000..feb63dc --- /dev/null +++ b/dot_config/i3/scripts/executable_power-profiles | |||
@@ -0,0 +1,190 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | # | ||
3 | # Use rofi/zenity to change system runstate thanks to systemd. | ||
4 | # | ||
5 | # Note: this currently relies on associative array support in the shell. | ||
6 | # | ||
7 | # Inspired from i3pystatus wiki: | ||
8 | # https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu | ||
9 | # | ||
10 | # Copyright 2015 Benjamin Chrétien <chretien at lirmm dot fr> | ||
11 | # | ||
12 | # This program is free software: you can redistribute it and/or modify | ||
13 | # it under the terms of the GNU General Public License as published by | ||
14 | # the Free Software Foundation, either version 3 of the License, or | ||
15 | # (at your option) any later version. | ||
16 | |||
17 | # This program is distributed in the hope that it will be useful, | ||
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | # GNU General Public License for more details. | ||
21 | |||
22 | # You should have received a copy of the GNU General Public License | ||
23 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
24 | |||
25 | # power-profiles-daemon implementation: | ||
26 | # needs package power-profiles-daemon installed and the service running see here: | ||
27 | # https://wiki.archlinux.org/title/CPU_frequency_scaling#power-profiles-daemon | ||
28 | # used in i3-blocks: ~/.config/i3/i3blocks.conf together with: ~/.config/i3/scripts/ppd-status | ||
29 | |||
30 | |||
31 | ####################################################################### | ||
32 | # BEGIN CONFIG # | ||
33 | ####################################################################### | ||
34 | |||
35 | # Use a custom lock script | ||
36 | #LOCKSCRIPT="i3lock-extra -m pixelize" | ||
37 | |||
38 | # Colors: FG (foreground), BG (background), HL (highlighted) | ||
39 | FG_COLOR="#bbbbbb" | ||
40 | BG_COLOR="#111111" | ||
41 | HLFG_COLOR="#111111" | ||
42 | HLBG_COLOR="#bbbbbb" | ||
43 | BORDER_COLOR="#222222" | ||
44 | |||
45 | # Options not related to colors | ||
46 | #ROFI_TEXT=":" | ||
47 | #ROFI_OPTIONS=(-width -11 -location 0 -hide-scrollbar -bw 30 -color-window "#dd310027,#dd0310027,#dd310027" -padding 5) | ||
48 | #ROFI_OPTIONS=(-width -18 -location 4 -hide-scrollbar -color-window "#cc310027,#00a0009a,#cc310027" -padding 5 -font "Sourcecode Pro Regular 10, FontAwesome 9") | ||
49 | ROFI_OPTIONS=(-theme ~/.config/rofi/power-profiles.rasi) | ||
50 | # Zenity options | ||
51 | ZENITY_TITLE="Power Profiles" | ||
52 | ZENITY_TEXT="Set Profiles:" | ||
53 | ZENITY_OPTIONS=(--column= --hide-header) | ||
54 | |||
55 | ####################################################################### | ||
56 | # END CONFIG # | ||
57 | ####################################################################### | ||
58 | |||
59 | # Whether to ask for user's confirmation | ||
60 | enable_confirmation=false | ||
61 | |||
62 | # Preferred launcher if both are available | ||
63 | preferred_launcher="rofi" | ||
64 | |||
65 | usage="$(basename "$0") [-h] [-c] [-p name] -- display a menu for shutdown, reboot, lock etc. | ||
66 | |||
67 | where: | ||
68 | -h show this help text | ||
69 | -c ask for user confirmation | ||
70 | -p preferred launcher (rofi or zenity) | ||
71 | |||
72 | This script depends on: | ||
73 | - systemd, | ||
74 | - i3, | ||
75 | - rofi or zenity." | ||
76 | |||
77 | # Check whether the user-defined launcher is valid | ||
78 | launcher_list=(rofi zenity) | ||
79 | function check_launcher() { | ||
80 | if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then | ||
81 | echo "Supported launchers: ${launcher_list[*]}" | ||
82 | exit 1 | ||
83 | else | ||
84 | # Get array with unique elements and preferred launcher first | ||
85 | # Note: uniq expects a sorted list, so we cannot use it | ||
86 | i=1 | ||
87 | launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \ | ||
88 | | sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' ')) | ||
89 | fi | ||
90 | } | ||
91 | |||
92 | # Parse CLI arguments | ||
93 | while getopts "hcp:" option; do | ||
94 | case "${option}" in | ||
95 | h) echo "${usage}" | ||
96 | exit 0 | ||
97 | ;; | ||
98 | c) enable_confirmation=true | ||
99 | ;; | ||
100 | p) preferred_launcher="${OPTARG}" | ||
101 | check_launcher "${preferred_launcher}" | ||
102 | ;; | ||
103 | *) exit 1 | ||
104 | ;; | ||
105 | esac | ||
106 | done | ||
107 | |||
108 | # Check whether a command exists | ||
109 | function command_exists() { | ||
110 | command -v "$1" &> /dev/null 2>&1 | ||
111 | } | ||
112 | |||
113 | # systemctl required | ||
114 | if ! command_exists systemctl ; then | ||
115 | exit 1 | ||
116 | fi | ||
117 | |||
118 | # menu defined as an associative array | ||
119 | typeset -A menu | ||
120 | |||
121 | # Menu with keys/commands | ||
122 | |||
123 | menu=( | ||
124 | [ Performance]="powerprofilesctl set performance" | ||
125 | [ Balanced]="powerprofilesctl set balanced" | ||
126 | [ Power Saver]="powerprofilesctl set power-saver" | ||
127 | [ Cancel]="" | ||
128 | ) | ||
129 | |||
130 | menu_nrows=${#menu[@]} | ||
131 | |||
132 | # Menu entries that may trigger a confirmation message | ||
133 | menu_confirm="Shutdown Reboot Hibernate Suspend Halt Logout" | ||
134 | |||
135 | launcher_exe="" | ||
136 | launcher_options="" | ||
137 | rofi_colors="" | ||
138 | |||
139 | function prepare_launcher() { | ||
140 | if [[ "$1" == "rofi" ]]; then | ||
141 | rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \ | ||
142 | -hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}") | ||
143 | launcher_exe="rofi" | ||
144 | launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \ | ||
145 | "${rofi_colors}" "${ROFI_OPTIONS[@]}") | ||
146 | elif [[ "$1" == "zenity" ]]; then | ||
147 | launcher_exe="zenity" | ||
148 | launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \ | ||
149 | "${ZENITY_OPTIONS[@]}") | ||
150 | fi | ||
151 | } | ||
152 | |||
153 | for l in "${launcher_list[@]}"; do | ||
154 | if command_exists "${l}" ; then | ||
155 | prepare_launcher "${l}" | ||
156 | break | ||
157 | fi | ||
158 | done | ||
159 | |||
160 | # No launcher available | ||
161 | if [[ -z "${launcher_exe}" ]]; then | ||
162 | exit 1 | ||
163 | fi | ||
164 | |||
165 | launcher=(${launcher_exe} "${launcher_options[@]}") | ||
166 | selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")" | ||
167 | |||
168 | function ask_confirmation() { | ||
169 | if [ "${launcher_exe}" == "rofi" ]; then | ||
170 | confirmed=$(echo -e "Yes\nNo" | rofi -dmenu -i -lines 2 -p "${selection}?" \ | ||
171 | "${rofi_colors}" "${ROFI_OPTIONS[@]}") | ||
172 | [ "${confirmed}" == "Yes" ] && confirmed=0 | ||
173 | elif [ "${launcher_exe}" == "zenity" ]; then | ||
174 | zenity --question --text "Are you sure you want to ${selection,,}?" | ||
175 | confirmed=$? | ||
176 | fi | ||
177 | |||
178 | if [ "${confirmed}" == 0 ]; then | ||
179 | i3-msg -q "exec --no-startup-id ${menu[${selection}]}" | ||
180 | fi | ||
181 | } | ||
182 | |||
183 | if [[ $? -eq 0 && ! -z ${selection} ]]; then | ||
184 | if [[ "${enable_confirmation}" = true && \ | ||
185 | ${menu_confirm} =~ (^|[[:space:]])"${selection}"($|[[:space:]]) ]]; then | ||
186 | ask_confirmation | ||
187 | else | ||
188 | i3-msg -q "exec --no-startup-id ${menu[${selection}]}" | ||
189 | fi | ||
190 | fi | ||
diff --git a/dot_config/i3/scripts/executable_powermenu b/dot_config/i3/scripts/executable_powermenu new file mode 100644 index 0000000..e72f0a2 --- /dev/null +++ b/dot_config/i3/scripts/executable_powermenu | |||
@@ -0,0 +1,186 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | # | ||
3 | # Use rofi/zenity to change system runstate thanks to systemd. | ||
4 | # | ||
5 | # Note: this currently relies on associative array support in the shell. | ||
6 | # | ||
7 | # Inspired from i3pystatus wiki: | ||
8 | # https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu | ||
9 | # | ||
10 | # Copyright 2015 Benjamin Chrétien <chretien at lirmm dot fr> | ||
11 | # | ||
12 | # This program is free software: you can redistribute it and/or modify | ||
13 | # it under the terms of the GNU General Public License as published by | ||
14 | # the Free Software Foundation, either version 3 of the License, or | ||
15 | # (at your option) any later version. | ||
16 | |||
17 | # This program is distributed in the hope that it will be useful, | ||
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | # GNU General Public License for more details. | ||
21 | |||
22 | # You should have received a copy of the GNU General Public License | ||
23 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
24 | |||
25 | # modified to work with latest rofi update by joekamprad <[email protected]> | ||
26 | |||
27 | ####################################################################### | ||
28 | # BEGIN CONFIG # | ||
29 | ####################################################################### | ||
30 | |||
31 | # Use a custom lock script | ||
32 | #LOCKSCRIPT="i3lock-extra -m pixelize" | ||
33 | |||
34 | # Colors: FG (foreground), BG (background), HL (highlighted) | ||
35 | FG_COLOR="#bbbbbb" | ||
36 | BG_COLOR="#111111" | ||
37 | HLFG_COLOR="#111111" | ||
38 | HLBG_COLOR="#bbbbbb" | ||
39 | BORDER_COLOR="#222222" | ||
40 | |||
41 | # Options not related to colors (most rofi options do not work anymore) | ||
42 | ROFI_OPTIONS=(-theme ~/.config/rofi/powermenu.rasi) | ||
43 | # Zenity options | ||
44 | ZENITY_TITLE="Power Menu" | ||
45 | ZENITY_TEXT="Action:" | ||
46 | ZENITY_OPTIONS=(--column= --hide-header) | ||
47 | |||
48 | ####################################################################### | ||
49 | # END CONFIG # | ||
50 | ####################################################################### | ||
51 | |||
52 | # Whether to ask for user's confirmation | ||
53 | enable_confirmation=false | ||
54 | |||
55 | # Preferred launcher if both are available | ||
56 | preferred_launcher="rofi" | ||
57 | |||
58 | usage="$(basename "$0") [-h] [-c] [-p name] -- display a menu for shutdown, reboot, lock etc. | ||
59 | |||
60 | where: | ||
61 | -h show this help text | ||
62 | -c ask for user confirmation | ||
63 | -p preferred launcher (rofi or zenity) | ||
64 | |||
65 | This script depends on: | ||
66 | - systemd, | ||
67 | - i3, | ||
68 | - rofi or zenity." | ||
69 | |||
70 | # Check whether the user-defined launcher is valid | ||
71 | launcher_list=(rofi zenity) | ||
72 | function check_launcher() { | ||
73 | if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then | ||
74 | echo "Supported launchers: ${launcher_list[*]}" | ||
75 | exit 1 | ||
76 | else | ||
77 | # Get array with unique elements and preferred launcher first | ||
78 | # Note: uniq expects a sorted list, so we cannot use it | ||
79 | i=1 | ||
80 | launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \ | ||
81 | | sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' ')) | ||
82 | fi | ||
83 | } | ||
84 | |||
85 | # Parse CLI arguments | ||
86 | while getopts "hcp:" option; do | ||
87 | case "${option}" in | ||
88 | h) echo "${usage}" | ||
89 | exit 0 | ||
90 | ;; | ||
91 | c) enable_confirmation=true | ||
92 | ;; | ||
93 | p) preferred_launcher="${OPTARG}" | ||
94 | check_launcher "${preferred_launcher}" | ||
95 | ;; | ||
96 | *) exit 1 | ||
97 | ;; | ||
98 | esac | ||
99 | done | ||
100 | |||
101 | # Check whether a command exists | ||
102 | function command_exists() { | ||
103 | command -v "$1" &> /dev/null 2>&1 | ||
104 | } | ||
105 | |||
106 | # systemctl required | ||
107 | if ! command_exists systemctl ; then | ||
108 | exit 1 | ||
109 | fi | ||
110 | |||
111 | # menu defined as an associative array | ||
112 | typeset -A menu | ||
113 | |||
114 | # Menu with keys/commands | ||
115 | |||
116 | menu=( | ||
117 | [ Shutdown]="systemctl poweroff" | ||
118 | [ Reboot]="systemctl reboot" | ||
119 | [ Suspend]="systemctl suspend" | ||
120 | [ Hibernate]="systemctl hibernate" | ||
121 | [ Lock]="~/.config/i3/scripts/blur-lock" | ||
122 | [ Logout]="i3-msg exit" | ||
123 | [ Cancel]="" | ||
124 | ) | ||
125 | |||
126 | menu_nrows=${#menu[@]} | ||
127 | |||
128 | # Menu entries that may trigger a confirmation message | ||
129 | menu_confirm="Shutdown Reboot Hibernate Suspend Halt Logout" | ||
130 | |||
131 | launcher_exe="" | ||
132 | launcher_options="" | ||
133 | rofi_colors="" | ||
134 | |||
135 | function prepare_launcher() { | ||
136 | if [[ "$1" == "rofi" ]]; then | ||
137 | rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \ | ||
138 | -hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}") | ||
139 | launcher_exe="rofi" | ||
140 | launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \ | ||
141 | "${rofi_colors}" "${ROFI_OPTIONS[@]}") | ||
142 | elif [[ "$1" == "zenity" ]]; then | ||
143 | launcher_exe="zenity" | ||
144 | launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \ | ||
145 | "${ZENITY_OPTIONS[@]}") | ||
146 | fi | ||
147 | } | ||
148 | |||
149 | for l in "${launcher_list[@]}"; do | ||
150 | if command_exists "${l}" ; then | ||
151 | prepare_launcher "${l}" | ||
152 | break | ||
153 | fi | ||
154 | done | ||
155 | |||
156 | # No launcher available | ||
157 | if [[ -z "${launcher_exe}" ]]; then | ||
158 | exit 1 | ||
159 | fi | ||
160 | |||
161 | launcher=(${launcher_exe} "${launcher_options[@]}") | ||
162 | selection="$(printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}")" | ||
163 | |||
164 | function ask_confirmation() { | ||
165 | if [ "${launcher_exe}" == "rofi" ]; then | ||
166 | confirmed=$(echo -e "Yes\nNo" | rofi -dmenu -i -lines 2 -p "${selection}?" \ | ||
167 | "${rofi_colors}" "${ROFI_OPTIONS[@]}") | ||
168 | [ "${confirmed}" == "Yes" ] && confirmed=0 | ||
169 | elif [ "${launcher_exe}" == "zenity" ]; then | ||
170 | zenity --question --text "Are you sure you want to ${selection,,}?" | ||
171 | confirmed=$? | ||
172 | fi | ||
173 | |||
174 | if [ "${confirmed}" == 0 ]; then | ||
175 | i3-msg -q "exec ${menu[${selection}]}" | ||
176 | fi | ||
177 | } | ||
178 | |||
179 | if [[ $? -eq 0 && ! -z ${selection} ]]; then | ||
180 | if [[ "${enable_confirmation}" = true && \ | ||
181 | ${menu_confirm} =~ (^|[[:space:]])"${selection}"($|[[:space:]]) ]]; then | ||
182 | ask_confirmation | ||
183 | else | ||
184 | i3-msg -q "exec ${menu[${selection}]}" | ||
185 | fi | ||
186 | fi | ||
diff --git a/dot_config/i3/scripts/executable_ppd-status b/dot_config/i3/scripts/executable_ppd-status new file mode 100644 index 0000000..8e6eb7b --- /dev/null +++ b/dot_config/i3/scripts/executable_ppd-status | |||
@@ -0,0 +1,11 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | # | ||
3 | # power-profiles-daemon implementation: | ||
4 | # needs package power-profiles-daemon installed and the service running see here: | ||
5 | # https://wiki.archlinux.org/title/CPU_frequency_scaling#power-profiles-daemon | ||
6 | # used in i3-blocks: ~/.config/i3/i3blocks.conf together with: ~/.config/i3/scripts/power-profiles | ||
7 | |||
8 | # script to show current power profile | ||
9 | |||
10 | current_profile=$(/usr/bin/powerprofilesctl get) | ||
11 | echo "$current_profile" | ||
diff --git a/dot_config/i3/scripts/executable_temperature b/dot_config/i3/scripts/executable_temperature new file mode 100644 index 0000000..4e31610 --- /dev/null +++ b/dot_config/i3/scripts/executable_temperature | |||
@@ -0,0 +1,86 @@ | |||
1 | #!/usr/bin/env perl | ||
2 | # Copyright 2014 Pierre Mavro <[email protected]> | ||
3 | # Copyright 2014 Vivien Didelot <[email protected]> | ||
4 | # Copyright 2014 Andreas Guldstrand <[email protected]> | ||
5 | # Copyright 2014 Benjamin Chretien <chretien at lirmm dot fr> | ||
6 | |||
7 | # This program is free software: you can redistribute it and/or modify | ||
8 | # it under the terms of the GNU General Public License as published by | ||
9 | # the Free Software Foundation, either version 3 of the License, or | ||
10 | # (at your option) any later version. | ||
11 | |||
12 | # This program is distributed in the hope that it will be useful, | ||
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | # GNU General Public License for more details. | ||
16 | |||
17 | # You should have received a copy of the GNU General Public License | ||
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | # | ||
20 | # Edited by Andreas Lindlbauer <[email protected]> | ||
21 | |||
22 | use strict; | ||
23 | use warnings; | ||
24 | use utf8; | ||
25 | use Getopt::Long; | ||
26 | |||
27 | binmode(STDOUT, ":utf8"); | ||
28 | |||
29 | # default values | ||
30 | my $t_warn = $ENV{T_WARN} || 70; | ||
31 | my $t_crit = $ENV{T_CRIT} || 90; | ||
32 | my $chip = $ENV{SENSOR_CHIP} || ""; | ||
33 | my $temperature = -9999; | ||
34 | my $label = "😀 "; | ||
35 | |||
36 | sub help { | ||
37 | print "Usage: temperature [-w <warning>] [-c <critical>] [--chip <chip>]\n"; | ||
38 | print "-w <percent>: warning threshold to become yellow\n"; | ||
39 | print "-c <percent>: critical threshold to become red\n"; | ||
40 | print "--chip <chip>: sensor chip\n"; | ||
41 | exit 0; | ||
42 | } | ||
43 | |||
44 | GetOptions("help|h" => \&help, | ||
45 | "w=i" => \$t_warn, | ||
46 | "c=i" => \$t_crit, | ||
47 | "chip=s" => \$chip); | ||
48 | |||
49 | # Get chip temperature | ||
50 | open (SENSORS, "sensors -u $chip |") or die; | ||
51 | while (<SENSORS>) { | ||
52 | if (/^\s+temp1_input:\s+[\+]*([\-]*\d+\.\d)/) { | ||
53 | $temperature = $1; | ||
54 | last; | ||
55 | } | ||
56 | } | ||
57 | close(SENSORS); | ||
58 | |||
59 | $temperature eq -9999 and die 'Cannot find temperature'; | ||
60 | |||
61 | if ($temperature < 45) { | ||
62 | $label = ''; | ||
63 | } elsif ($temperature < 55) { | ||
64 | $label = ''; | ||
65 | } elsif ($temperature < 65) { | ||
66 | $label = ''; | ||
67 | } elsif ($temperature < 75) { | ||
68 | $label = ''; | ||
69 | } else { | ||
70 | $label = ''; | ||
71 | } | ||
72 | # Print short_text, full_text | ||
73 | print "${label}"; | ||
74 | print " $temperature°C\n"; | ||
75 | print "${label}"; | ||
76 | print " $temperature°C\n"; | ||
77 | |||
78 | # Print color, if needed | ||
79 | if ($temperature >= $t_crit) { | ||
80 | print "#FF0000\n"; | ||
81 | exit 33; | ||
82 | } elsif ($temperature >= $t_warn) { | ||
83 | print "#FFFC00\n"; | ||
84 | } | ||
85 | |||
86 | exit 0; | ||
diff --git a/dot_config/i3/scripts/executable_volume b/dot_config/i3/scripts/executable_volume new file mode 100644 index 0000000..39618e1 --- /dev/null +++ b/dot_config/i3/scripts/executable_volume | |||
@@ -0,0 +1,93 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | # Copyright (C) 2014 Julien Bonjean <[email protected]> | ||
3 | # Copyright (C) 2014 Alexander Keller <[email protected]> | ||
4 | |||
5 | # This program is free software: you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published by | ||
7 | # the Free Software Foundation, either version 3 of the License, or | ||
8 | # (at your option) any later version. | ||
9 | |||
10 | # This program is distributed in the hope that it will be useful, | ||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | # GNU General Public License for more details. | ||
14 | |||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | # original source: https://github.com/vivien/i3blocks-contrib/tree/master/volume | ||
19 | # check the readme: https://github.com/vivien/i3blocks-contrib/blob/master/volume/README.md | ||
20 | #------------------------------------------------------------------------ | ||
21 | |||
22 | # The second parameter overrides the mixer selection | ||
23 | # For PulseAudio users, eventually use "pulse" | ||
24 | # For Jack/Jack2 users, use "jackplug" | ||
25 | # For ALSA users, you may use "default" for your primary card | ||
26 | # or you may use hw:# where # is the number of the card desired | ||
27 | if [[ -z "$MIXER" ]] ; then | ||
28 | MIXER="default" | ||
29 | if command -v pulseaudio >/dev/null 2>&1 && pulseaudio --check ; then | ||
30 | # pulseaudio is running, but not all installations use "pulse" | ||
31 | if amixer -D pulse info >/dev/null 2>&1 ; then | ||
32 | MIXER="pulse" | ||
33 | fi | ||
34 | fi | ||
35 | [ -n "$(lsmod | grep jack)" ] && MIXER="jackplug" | ||
36 | MIXER="${2:-$MIXER}" | ||
37 | fi | ||
38 | |||
39 | # The instance option sets the control to report and configure | ||
40 | # This defaults to the first control of your selected mixer | ||
41 | # For a list of the available, use `amixer -D $Your_Mixer scontrols` | ||
42 | if [[ -z "$SCONTROL" ]] ; then | ||
43 | SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols | | ||
44 | sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" | | ||
45 | head -n1 | ||
46 | )}" | ||
47 | fi | ||
48 | |||
49 | # The first parameter sets the step to change the volume by (and units to display) | ||
50 | # This may be in in % or dB (eg. 5% or 3dB) | ||
51 | if [[ -z "$STEP" ]] ; then | ||
52 | STEP="${1:-5%}" | ||
53 | fi | ||
54 | |||
55 | # AMIXER(1): | ||
56 | # "Use the mapped volume for evaluating the percentage representation like alsamixer, to be | ||
57 | # more natural for human ear." | ||
58 | NATURAL_MAPPING=${NATURAL_MAPPING:-0} | ||
59 | if [[ "$NATURAL_MAPPING" != "0" ]] ; then | ||
60 | AMIXER_PARAMS="-M" | ||
61 | fi | ||
62 | |||
63 | #------------------------------------------------------------------------ | ||
64 | |||
65 | capability() { # Return "Capture" if the device is a capture device | ||
66 | amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL | | ||
67 | sed -n "s/ Capabilities:.*cvolume.*/Capture/p" | ||
68 | } | ||
69 | |||
70 | volume() { | ||
71 | amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL $(capability) | ||
72 | } | ||
73 | |||
74 | format() { | ||
75 | |||
76 | perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)' | ||
77 | perl_filter+='{CORE::say $4 eq "off" ? "MUTE" : "' | ||
78 | # If dB was selected, print that instead | ||
79 | perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo '$1') | ||
80 | perl_filter+='"; exit}' | ||
81 | output=$(perl -ne "$perl_filter") | ||
82 | echo "$LABEL$output" | ||
83 | } | ||
84 | |||
85 | #------------------------------------------------------------------------ | ||
86 | |||
87 | case $BLOCK_BUTTON in | ||
88 | 3) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) toggle ;; # right click, mute/unmute | ||
89 | 4) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}+ unmute ;; # scroll up, increase | ||
90 | 5) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}- unmute ;; # scroll down, decrease | ||
91 | esac | ||
92 | |||
93 | volume | format | ||
diff --git a/dot_config/i3/scripts/executable_vpn b/dot_config/i3/scripts/executable_vpn new file mode 100644 index 0000000..a348f96 --- /dev/null +++ b/dot_config/i3/scripts/executable_vpn | |||
@@ -0,0 +1,25 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | # | ||
3 | # Copyright (C) 2021 Andreas Lindlbauer | ||
4 | # Licensed under the terms of EUPLv1.2. | ||
5 | # | ||
6 | # i3blocks blocklet script to monitor the (nord)vpn connection | ||
7 | |||
8 | vpnstatus="📢" | ||
9 | nordvpn_output=$(nordvpn status | cat -v | head -1 | sed -e 's/\^M-^M ^M//g' ) | ||
10 | if [ "${nordvpn_output}" = "Status: Connected" ]; then | ||
11 | vpnstatus="🥸" | ||
12 | elif [ "${nordvpn_output}" = "A new version of NordVPN is available! Please update the application." ]; then | ||
13 | nordvpn_output=$(nordvpn status | cat -v | head -2 | tail -1 | sed -e 's/\^M-^M ^M//g' ) | ||
14 | if [ "${nordvpn_output}" = "Status: Connected" ]; then | ||
15 | vpnstatus="🥴" | ||
16 | elif [ "${nordvpn_output}" = "Status: Disconnected" ]; then | ||
17 | vpnstatus="📢" | ||
18 | fi | ||
19 | elif [ "${nordvpn_output}" = "Status: Disconnected" ]; then | ||
20 | vpnstatus="📢" | ||
21 | elif [[ "$nordvpn_output" == *\/* ]] || [[ "$nordvpn_output" == *\\* ]]; then | ||
22 | vpnstatus="Something's very wrong" | ||
23 | fi | ||
24 | |||
25 | echo "$vpnstatus" | ||
diff --git a/dot_config/i3/scripts/executable_worldclock b/dot_config/i3/scripts/executable_worldclock new file mode 100644 index 0000000..573800e --- /dev/null +++ b/dot_config/i3/scripts/executable_worldclock | |||
@@ -0,0 +1,122 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | # | ||
3 | # Use rofi/zenity to display world clock. | ||
4 | # | ||
5 | # Note: this currently relies on associative array support in the shell. | ||
6 | # | ||
7 | # Inspired from i3pystatus wiki: | ||
8 | # https://github.com/enkore/i3pystatus/wiki/Shutdown-Menu | ||
9 | # | ||
10 | # Copyright 2022 Jinwei Zhao <i at jinwei dot me> | ||
11 | # | ||
12 | # This program is free software: you can redistribute it and/or modify | ||
13 | # it under the terms of the GNU General Public License as published by | ||
14 | # the Free Software Foundation, either version 3 of the License, or | ||
15 | # (at your option) any later version. | ||
16 | |||
17 | # This program is distributed in the hope that it will be useful, | ||
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | # GNU General Public License for more details. | ||
21 | |||
22 | # You should have received a copy of the GNU General Public License | ||
23 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
24 | |||
25 | # modified to work with latest rofi update by joekamprad <[email protected]> | ||
26 | |||
27 | ####################################################################### | ||
28 | # BEGIN CONFIG # | ||
29 | ####################################################################### | ||
30 | |||
31 | # Colors: FG (foreground), BG (background), HL (highlighted) | ||
32 | FG_COLOR="#bbbbbb" | ||
33 | BG_COLOR="#111111" | ||
34 | HLFG_COLOR="#111111" | ||
35 | HLBG_COLOR="#bbbbbb" | ||
36 | BORDER_COLOR="#222222" | ||
37 | |||
38 | # Options not related to colors (most rofi options do not work anymore) | ||
39 | ROFI_OPTIONS=(-theme ~/.config/rofi/worldclock.rasi) | ||
40 | |||
41 | ####################################################################### | ||
42 | # END CONFIG # | ||
43 | ####################################################################### | ||
44 | |||
45 | # Preferred launcher if both are available | ||
46 | preferred_launcher="rofi" | ||
47 | |||
48 | # Check whether the user-defined launcher is valid | ||
49 | launcher_list=(rofi) | ||
50 | function check_launcher() { | ||
51 | if [[ ! "${launcher_list[@]}" =~ (^|[[:space:]])"$1"($|[[:space:]]) ]]; then | ||
52 | echo "Supported launchers: ${launcher_list[*]}" | ||
53 | exit 1 | ||
54 | else | ||
55 | # Get array with unique elements and preferred launcher first | ||
56 | # Note: uniq expects a sorted list, so we cannot use it | ||
57 | i=1 | ||
58 | launcher_list=($(for l in "$1" "${launcher_list[@]}"; do printf "%i %s\n" "$i" "$l"; let i+=1; done \ | ||
59 | | sort -uk2 | sort -nk1 | cut -d' ' -f2- | tr '\n' ' ')) | ||
60 | fi | ||
61 | } | ||
62 | |||
63 | # Parse CLI arguments | ||
64 | while getopts "hcp:" option; do | ||
65 | case "${option}" in | ||
66 | p) preferred_launcher="${OPTARG}" | ||
67 | check_launcher "${preferred_launcher}" | ||
68 | ;; | ||
69 | *) exit 1 | ||
70 | ;; | ||
71 | esac | ||
72 | done | ||
73 | |||
74 | # Check whether a command exists | ||
75 | function command_exists() { | ||
76 | command -v "$1" &> /dev/null 2>&1 | ||
77 | } | ||
78 | |||
79 | # menu defined as an associative array | ||
80 | typeset -A menu | ||
81 | |||
82 | menu=( | ||
83 | [🇨🇦: `date '+%b %d %H:%M'`]="" | ||
84 | [🇬🇧: `TZ=Europe/London date '+%b %d %H:%M'`]="" | ||
85 | [🇨🇳: `TZ=Asia/Shanghai date '+%b %d %H:%M'`]="" | ||
86 | ) | ||
87 | |||
88 | menu_nrows=${#menu[@]} | ||
89 | |||
90 | launcher_exe="" | ||
91 | launcher_options="" | ||
92 | rofi_colors="" | ||
93 | |||
94 | function prepare_launcher() { | ||
95 | if [[ "$1" == "rofi" ]]; then | ||
96 | rofi_colors=(-bc "${BORDER_COLOR}" -bg "${BG_COLOR}" -fg "${FG_COLOR}" \ | ||
97 | -hlfg "${HLFG_COLOR}" -hlbg "${HLBG_COLOR}") | ||
98 | launcher_exe="rofi" | ||
99 | launcher_options=(-dmenu -i -lines "${menu_nrows}" -p "${ROFI_TEXT}" \ | ||
100 | "${rofi_colors}" "${ROFI_OPTIONS[@]}") | ||
101 | elif [[ "$1" == "zenity" ]]; then | ||
102 | launcher_exe="zenity" | ||
103 | launcher_options=(--list --title="${ZENITY_TITLE}" --text="${ZENITY_TEXT}" \ | ||
104 | "${ZENITY_OPTIONS[@]}") | ||
105 | fi | ||
106 | } | ||
107 | |||
108 | for l in "${launcher_list[@]}"; do | ||
109 | if command_exists "${l}" ; then | ||
110 | prepare_launcher "${l}" | ||
111 | break | ||
112 | fi | ||
113 | done | ||
114 | |||
115 | # No launcher available | ||
116 | if [[ -z "${launcher_exe}" ]]; then | ||
117 | exit 1 | ||
118 | fi | ||
119 | |||
120 | launcher=(${launcher_exe} "${launcher_options[@]}") | ||
121 | printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}" | ||
122 | |||