aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2022-11-17 10:56:25 -0800
committerclarkzjw <[email protected]>2022-11-17 10:56:25 -0800
commitd2d735742ca61b211c9b48a2209d36395daebcf4 (patch)
treebda27729a1bbac3ab354a1f10d4885899cdbf967 /dot_config/i3/scripts/executable_worldclock
parenta6d2e5e6fb9adc84c32e86630b4846b1765c7d77 (diff)
downloaddotfiles-d2d735742ca61b211c9b48a2209d36395daebcf4.tar.gz
+ add existing config
Diffstat (limited to 'dot_config/i3/scripts/executable_worldclock')
-rw-r--r--dot_config/i3/scripts/executable_worldclock122
1 files changed, 122 insertions, 0 deletions
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)
32FG_COLOR="#bbbbbb"
33BG_COLOR="#111111"
34HLFG_COLOR="#111111"
35HLBG_COLOR="#bbbbbb"
36BORDER_COLOR="#222222"
37
38# Options not related to colors (most rofi options do not work anymore)
39ROFI_OPTIONS=(-theme ~/.config/rofi/worldclock.rasi)
40
41#######################################################################
42# END CONFIG #
43#######################################################################
44
45# Preferred launcher if both are available
46preferred_launcher="rofi"
47
48# Check whether the user-defined launcher is valid
49launcher_list=(rofi)
50function 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
64while 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
72done
73
74# Check whether a command exists
75function command_exists() {
76 command -v "$1" &> /dev/null 2>&1
77}
78
79# menu defined as an associative array
80typeset -A menu
81
82menu=(
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
88menu_nrows=${#menu[@]}
89
90launcher_exe=""
91launcher_options=""
92rofi_colors=""
93
94function 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
108for l in "${launcher_list[@]}"; do
109 if command_exists "${l}" ; then
110 prepare_launcher "${l}"
111 break
112 fi
113done
114
115# No launcher available
116if [[ -z "${launcher_exe}" ]]; then
117 exit 1
118fi
119
120launcher=(${launcher_exe} "${launcher_options[@]}")
121printf '%s\n' "${!menu[@]}" | sort | "${launcher[@]}"
122
Powered by cgit v1.2.3 (git 2.41.0)