From 70abde6d16965bcf922789846dd0655584a4bfe5 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Tue, 4 Apr 2023 12:19:56 +0200 Subject: bin/menu: update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- .config/bemenu.conf | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ bin/menu | 55 ++++++++++++++++++++++++++++++++++------------------- bin/mkmenu | 17 +++++++++++++++++ 3 files changed, 102 insertions(+), 20 deletions(-) create mode 100644 .config/bemenu.conf create mode 100755 bin/mkmenu diff --git a/.config/bemenu.conf b/.config/bemenu.conf new file mode 100644 index 0000000..17654f1 --- /dev/null +++ b/.config/bemenu.conf @@ -0,0 +1,50 @@ +# vim: ft=bash +bemenu_opts=( +--ignorecase +--no-overlap +--monitor focused +--binding vim +--scrollbar autohide +--fn \"Iosevka 9\" + +# popup menu +--center +--width-factor 0.5 +--border 3 +--list 8 +--fixed-height +--wrap + +# start flavours +# normal +--nb "#0c0c0c" +--nf "#fffffb" +# alternate +--ab "#0c0c0c" +# --ab "#1c1c1c" +--af "#fffffb" +# title +--tb "#8a6bbe" +--tf "#fffffb" +# filter +--fb "#0c0c0c" +--ff "#fffffb" +# selection +--sb "#fad689" +--sf "#0c0c0c" +# highlighted +--hb "#8a6bbe" +--hf "#fffffb" +# scrollbar +--scb "#0c0c0c" +--scf "#1c1c1c" +# border +--bdr "#8a6bbe" +# feedback +--fbb "#cb1b45" +--fbf "#8a6bbe" +# end flavours +) +export BEMENU_OPTS=${bemenu_opts[*]} +export BEMENU_BACKEND=wayland +unset bemenu_opts diff --git a/bin/menu b/bin/menu index f40e762..23e7801 100755 --- a/bin/menu +++ b/bin/menu @@ -2,10 +2,14 @@ set -e [ -n "$DEBUG" ] && set -x +# make sure there we are the only running menu +pgrep -x bemenu >/dev/null && killall -INT bemenu + +# always source the config to make sure +. "$HOME"/.config/bemenu.conf + arg0=bemenu -# prompt=${MENU_PROMPT:-󰈶 :} prompt=${MENU_PROMPT:-󰈶󰩤} -main_color="#4E4371" args= idx=0 @@ -13,15 +17,37 @@ while test $# -gt $idx; do case "$1" in -run) arg0=bemenu-run - prompt=" 󰏌 " + prompt="󰏌" shift ;; -drun) - # arg0=$HOME/devel/upstream/github.com/Cloudef/bemenu/bemenu-drun; prompt=bin - arg0=bemenu-drun - prompt=" 󱂬 " - main_color="#e03c8a" + # arg0=bemenu-drun + # prompt="󱂬" shift + desktopfiles() { + fd -e desktop . \ + /usr/share/applications/ \ + /usr/local/share/applications/ \ + /var/lib/flatpak/app/*/current/active/export/share/applications/ \ + "$XDG_DATA_HOME"/applications/ 2>/dev/null || true + } + list_apps() { + desktopfiles | + xargs -I{} awk -F= '/^Name=/{ print $2;exit; }' {} | + sort -u + } + get_desktopfile() { + desktopfiles | + xargs -I{} awk -v name="$1" -F= '/^Name=/{ if($2==name) print FILENAME }' {} | + sort -u | + head -n1 + } + app=$(list_apps | MENU_PROMPT="󱂬" "$0") + [ -z "$app" ] && exit 0 + desktopfile=$(get_desktopfile "$app") + [ -z "$desktopfile" ] && exit 0 + nohup xdg-exec "$desktopfile" "$@" >/dev/null 2>&1 & + exit 0 ;; -p) shift @@ -36,17 +62,6 @@ while test $# -gt $idx; do idx=$((idx + 1)) done -# HACK: https://github.com/Cloudef/bemenu/issues/5 -args= [ -n "${MENU_PASSWORD}" ] && args="${args} --password" - -# make sure there we are the only running menu -pgrep "${arg0}" && pkill "${arg0}" - -exec "${arg0}" \ - --tb "$main_color" --tf '#fffffb' \ - --hb "$main_color" --hf '#fffffb' \ - --scb '#1c1c1c' --scf "$main_color" \ - --prompt="${prompt}" \ - ${args} \ - "$@" +[ -n "${MENU_POPUP}" ] && args="${args} --center --width-factor 0.5 --border 2 --list 8" # --fixed-height +exec "${arg0}" --prompt "${prompt}" ${args} "$@" diff --git a/bin/mkmenu b/bin/mkmenu new file mode 100755 index 0000000..614f512 --- /dev/null +++ b/bin/mkmenu @@ -0,0 +1,17 @@ +#!/bin/bash +set -e +[ "$DEBUG" ] && set -x +[ "$TEST" ] && { + jq -cn '{p:"test...",o:[{l:"option a",x:"notify-send a"},{l:"option b",x:"notify-send b"}]}' | env -u TEST $0 + exit 0 +} + +read -r IN + +MENU_PROMPT=$(jq -cr '.p' <<<"$IN") +export MENU_PROMPT + +sel=$(jq -cr '.o[].l' <<<"$IN" | menu) +run=$(jq -cr --arg sel "$sel" '.o[] | select(.l == $sel) | .x' <<<"$IN") + +exec sh -c "$run" -- cgit 1.4.1