mirror of
https://github.com/ksyasuda/dotfiles.git
synced 2025-12-10 10:48:00 -08:00
update
This commit is contained in:
@@ -139,3 +139,5 @@ bind = $mainMod, code:112, submap, reset
|
||||
submap = reset
|
||||
|
||||
bind = SUPER, l, exec, hyprlock
|
||||
|
||||
bind = $mainMod SHIFT, a, exec, ~/.config/rofi/scripts/rofi-anki-script.sh
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/rofi-menu-helpers.sh"
|
||||
|
||||
BROWSER=/usr/bin/zen-browser
|
||||
OPTIONS=(
|
||||
"Arch Linux (btw)"
|
||||
"Hyprland"
|
||||
DOC_GROUPS=(
|
||||
"Arch Linux (btw)|ARCH"
|
||||
"Hyprland|HYPRLAND"
|
||||
)
|
||||
ARCH=(
|
||||
"Archlinux Wiki|https://wiki.archlinux.org/title/Main_page"
|
||||
@@ -13,56 +16,37 @@ HYPRLAND=(
|
||||
"Hyprland Window Rules|https://wiki.hypr.land/Configuring/Window-Rules/"
|
||||
)
|
||||
|
||||
get_url() {
|
||||
urls=("$@")
|
||||
display_urls=()
|
||||
declare -A url_map
|
||||
for url in "${urls[@]}"; do
|
||||
display_urls+=("${url%%|*}")
|
||||
label="${url%%|*}"
|
||||
url_map["$label"]="${url##*|}"
|
||||
done
|
||||
display_urls+=("Back")
|
||||
url_map["Back"]="Back"
|
||||
|
||||
selection="$(printf "%s\n" "${display_urls[@]}" | rofi -theme-str 'window {width: 25%;} listview {columns: 1; lines: 10;}' -theme ~/.config/rofi/launchers/type-2/style-2.rasi -dmenu -l 5 -i -p "Select Documentation")"
|
||||
url="${url_map[$selection]}"
|
||||
|
||||
if [ -z "$url" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf "%s\n" "$url"
|
||||
select_group() {
|
||||
rofi_select_label_value "Select Documentation Group" DOC_GROUPS
|
||||
}
|
||||
|
||||
get_docs_list() {
|
||||
selection="$(printf "%s\n" "${OPTIONS[@]}" | rofi -theme-str 'window {width: 25%;} listview {columns: 1; lines: 10;}' -theme ~/.config/rofi/launchers/type-2/style-2.rasi -dmenu -l 5 -i -p "Select Documentation Group")"
|
||||
case "$selection" in
|
||||
"Arch Linux (btw)")
|
||||
urls=("${ARCH[@]}")
|
||||
;;
|
||||
"Hyprland")
|
||||
urls=("${HYPRLAND[@]}")
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
printf "%s\n" "${urls[@]}"
|
||||
select_url() {
|
||||
local urls_array="$1"
|
||||
rofi_select_label_value "Select Documentation" "$urls_array" "Back"
|
||||
}
|
||||
|
||||
main() {
|
||||
mapfile -t urls < <(get_docs_list)
|
||||
url="$(get_url "${urls[@]}")"
|
||||
if [ -z "$url" ]; then
|
||||
printf "No URL selected.\n"
|
||||
while true; do
|
||||
group_key="$(select_group)" || exit 0
|
||||
case "$group_key" in
|
||||
ARCH)
|
||||
urls_ref=ARCH
|
||||
;;
|
||||
HYPRLAND)
|
||||
urls_ref=HYPRLAND
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
selection="$(select_url "$urls_ref")" || exit 0
|
||||
if [[ "$selection" == "Back" ]]; then
|
||||
continue
|
||||
fi
|
||||
$BROWSER "$selection" &>/dev/null &
|
||||
exit 0
|
||||
elif [ "$url" == "Back" ]; then
|
||||
main
|
||||
exit 0
|
||||
fi
|
||||
$BROWSER "$url" &>/dev/null &
|
||||
done
|
||||
}
|
||||
|
||||
main
|
||||
|
||||
68
.config/rofi/scripts/rofi-menu-helpers.sh
Normal file
68
.config/rofi/scripts/rofi-menu-helpers.sh
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Lightweight helpers to build rofi menus with label/value pairs.
|
||||
# Intended to be sourced from other scripts.
|
||||
|
||||
# Allow callers to override theme/args without touching code.
|
||||
: "${ROFI_THEME:=$HOME/.config/rofi/launchers/type-2/style-2.rasi}"
|
||||
: "${ROFI_THEME_STR:="window {width: 25%;} listview {columns: 1; lines: 10;}"}"
|
||||
: "${ROFI_DMENU_ARGS:=-i -l 5}"
|
||||
|
||||
# rofi_menu prompt option...
|
||||
# Prints the selected option to stdout and propagates the rofi exit code
|
||||
# (1 when the user cancels).
|
||||
rofi_menu() {
|
||||
local prompt="$1"
|
||||
shift
|
||||
local -a options=("$@")
|
||||
|
||||
local selection
|
||||
selection="$(printf "%s\n" "${options[@]}" | rofi -dmenu $ROFI_DMENU_ARGS \
|
||||
${ROFI_THEME:+-theme "$ROFI_THEME"} \
|
||||
${ROFI_THEME_STR:+-theme-str "$ROFI_THEME_STR"} \
|
||||
-p "$prompt")"
|
||||
local status=$?
|
||||
[[ $status -ne 0 ]] && return "$status"
|
||||
printf "%s\n" "$selection"
|
||||
}
|
||||
|
||||
# rofi_select_label_value prompt array_name [back_label]
|
||||
# array_name should contain entries shaped as "Label|Value".
|
||||
# Prints the mapped value (or the back label when chosen). Returns 1 on cancel.
|
||||
rofi_select_label_value() {
|
||||
local prompt="$1"
|
||||
local array_name="$2"
|
||||
local back_label="${3:-}"
|
||||
|
||||
# Access caller's array by name
|
||||
local -n kv_source="$array_name"
|
||||
local -A kv_map=()
|
||||
local -a display=()
|
||||
|
||||
for entry in "${kv_source[@]}"; do
|
||||
local label="${entry%%|*}"
|
||||
local value="${entry#*|}"
|
||||
kv_map["$label"]="$value"
|
||||
display+=("$label")
|
||||
done
|
||||
|
||||
if [[ -n "$back_label" ]]; then
|
||||
kv_map["$back_label"]="$back_label"
|
||||
display+=("$back_label")
|
||||
fi
|
||||
|
||||
local selection
|
||||
selection="$(rofi_menu "$prompt" "${display[@]}")" || return "$?"
|
||||
[[ -z "$selection" ]] && return 1
|
||||
printf "%s\n" "${kv_map[$selection]}"
|
||||
}
|
||||
|
||||
# rofi_select_list prompt array_name
|
||||
# Convenience wrapper for plain lists (no label/value mapping).
|
||||
rofi_select_list() {
|
||||
local prompt="$1"
|
||||
local array_name="$2"
|
||||
local -n list_source="$array_name"
|
||||
rofi_menu "$prompt" "${list_source[@]}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user