From ed0dd292af46c0dbdde10cc25214fd7d2d93e45f Mon Sep 17 00:00:00 2001 From: fdev31 Date: Sun, 15 Dec 2024 18:09:50 +0100 Subject: [PATCH] rename gbar to menubar (command = bar) --- pyprland/plugins/{gbar.py => menubar.py} | 16 +- pyprland/version.py | 2 +- scripts/completions/pypr.bash | 178 +++++++++++------------ scripts/completions/pypr.zsh | 6 +- 4 files changed, 101 insertions(+), 101 deletions(-) rename pyprland/plugins/{gbar.py => menubar.py} (85%) diff --git a/pyprland/plugins/gbar.py b/pyprland/plugins/menubar.py similarity index 85% rename from pyprland/plugins/gbar.py rename to pyprland/plugins/menubar.py index 4e774ef3..1b7a3dbd 100644 --- a/pyprland/plugins/gbar.py +++ b/pyprland/plugins/menubar.py @@ -1,15 +1,15 @@ -"""Run gbar on the first available display from a list of displays.""" +"""Run a bar.""" import asyncio import contextlib from time import time -from ..common import state +from ..common import apply_variables, state from .interface import Plugin class Extension(Plugin): - """Manage gBar application.""" + """Manage desktop bars application.""" monitors: set[str] proc = None @@ -20,9 +20,9 @@ class Extension(Plugin): async def on_reload(self) -> None: """Start the process.""" self.kill() - self._run_gbar() + self._run_program() - def _run_gbar(self) -> None: + def _run_program(self) -> None: """Create ongoing task restarting gbar in case of crash.""" if self.ongoing_task: self.ongoing_task.cancel() @@ -31,12 +31,12 @@ async def _run_loop() -> None: prev_time = time() while True: await self.set_best_monitor() - cmd = f"gBar bar {self.cur_monitor}" + cmd = apply_variables(self.config.get("command", "gBar bar [monitor]"), {"monitor": self.cur_monitor}) now = time() self.proc = await asyncio.create_subprocess_shell(cmd) await self.proc.wait() delay = 60 - (now - prev_time) - text = f"gBar crashed, restarting in {delay // 2}s." if delay > 0 else "gBar crashed, restarting." + text = f"Menu Bar crashed, restarting in {delay // 2}s." if delay > 0 else "Menu Bar crashed, restarting." await self.notify_error(text) prev_time = now if delay > 0: @@ -44,7 +44,7 @@ async def _run_loop() -> None: self.ongoing_task = asyncio.create_task(_run_loop()) - async def run_gbar(self, args: str) -> None: + async def run_bar(self, args: str) -> None: """Start gBar on the first available monitor.""" if args.startswith("re"): self.kill() diff --git a/pyprland/version.py b/pyprland/version.py index b648c36a..c4d7003c 100644 --- a/pyprland/version.py +++ b/pyprland/version.py @@ -1,3 +1,3 @@ """Package version.""" -VERSION = "2.4.3-7" +VERSION = "2.4.3-8" diff --git a/scripts/completions/pypr.bash b/scripts/completions/pypr.bash index 89177f54..e7c551e8 100644 --- a/scripts/completions/pypr.bash +++ b/scripts/completions/pypr.bash @@ -1,15 +1,15 @@ # AUTOMATICALLY GENERATED by `shtab` -_shtab_pypr_subparsers=('dumpjson' 'edit' 'exit' 'help' 'version' 'reload' 'attach' 'show' 'hide' 'toggle' 'gbar' 'menu' 'toggle_special' 'layout_center' 'attract_lost' 'shift_monitors' 'toggle_dpms' 'zoom' 'expose' 'change_workspace' 'wall' 'fetch_client_menu' 'unfetch_client' 'relayout') +_shtab_pypr_subparsers=('dumpjson' 'edit' 'exit' 'help' 'version' 'reload' 'attach' 'show' 'hide' 'toggle' 'bar' 'menu' 'toggle_special' 'layout_center' 'attract_lost' 'shift_monitors' 'toggle_dpms' 'zoom' 'expose' 'change_workspace' 'wall' 'fetch_client_menu' 'unfetch_client' 'relayout') _shtab_pypr_option_strings=('--debug' '--config') _shtab_pypr___debug_COMPGEN=_shtab_compgen_files _shtab_pypr___config_COMPGEN=_shtab_greeter_compgen_TOMLFiles -_shtab_pypr_pos_0_choices=('dumpjson' 'edit' 'exit' 'help' 'version' 'reload' 'attach' 'show' 'hide' 'toggle' 'gbar' 'menu' 'toggle_special' 'layout_center' 'attract_lost' 'shift_monitors' 'toggle_dpms' 'zoom' 'expose' 'change_workspace' 'wall' 'fetch_client_menu' 'unfetch_client' 'relayout') +_shtab_pypr_pos_0_choices=('dumpjson' 'edit' 'exit' 'help' 'version' 'reload' 'attach' 'show' 'hide' 'toggle' 'bar' 'menu' 'toggle_special' 'layout_center' 'attract_lost' 'shift_monitors' 'toggle_dpms' 'zoom' 'expose' 'change_workspace' 'wall' 'fetch_client_menu' 'unfetch_client' 'relayout') _shtab_pypr___print_completion_choices=('bash' 'zsh' 'tcsh') -_shtab_pypr_gbar_pos_0_choices=('restart') +_shtab_pypr_bar_pos_0_choices=('restart') _shtab_pypr_layout_center_pos_0_choices=('toggle' 'next' 'prev') _shtab_pypr_change_workspace_pos_0_choices=('-1' '+1') _shtab_pypr_wall_pos_0_choices=('next' 'clear') @@ -18,54 +18,54 @@ _shtab_pypr_pos_0_nargs=A... # $1=COMP_WORDS[1] _shtab_compgen_files() { - compgen -f -- $1 # files + compgen -f -- $1 # files } # $1=COMP_WORDS[1] _shtab_compgen_dirs() { - compgen -d -- $1 # recurse into subdirs + compgen -d -- $1 # recurse into subdirs } # $1=COMP_WORDS[1] _shtab_replace_nonword() { - echo "${1//[^[:word:]]/_}" + echo "${1//[^[:word:]]/_}" } # set default values (called for the initial parser & any subparsers) _set_parser_defaults() { - local subparsers_var="${prefix}_subparsers[@]" - sub_parsers=${!subparsers_var-} + local subparsers_var="${prefix}_subparsers[@]" + sub_parsers=${!subparsers_var-} - local current_option_strings_var="${prefix}_option_strings[@]" - current_option_strings=${!current_option_strings_var} + local current_option_strings_var="${prefix}_option_strings[@]" + current_option_strings=${!current_option_strings_var} - completed_positional_actions=0 + completed_positional_actions=0 - _set_new_action "pos_${completed_positional_actions}" true + _set_new_action "pos_${completed_positional_actions}" true } # $1=action identifier # $2=positional action (bool) # set all identifiers for an action's parameters _set_new_action() { - current_action="${prefix}_$(_shtab_replace_nonword $1)" + current_action="${prefix}_$(_shtab_replace_nonword $1)" - local current_action_compgen_var=${current_action}_COMPGEN - current_action_compgen="${!current_action_compgen_var-}" + local current_action_compgen_var=${current_action}_COMPGEN + current_action_compgen="${!current_action_compgen_var-}" - local current_action_choices_var="${current_action}_choices[@]" - current_action_choices="${!current_action_choices_var-}" + local current_action_choices_var="${current_action}_choices[@]" + current_action_choices="${!current_action_choices_var-}" - local current_action_nargs_var="${current_action}_nargs" - if [ -n "${!current_action_nargs_var-}" ]; then - current_action_nargs="${!current_action_nargs_var}" - else - current_action_nargs=1 - fi + local current_action_nargs_var="${current_action}_nargs" + if [ -n "${!current_action_nargs_var-}" ]; then + current_action_nargs="${!current_action_nargs_var}" + else + current_action_nargs=1 + fi - current_action_args_start_index=$(( $word_index + 1 - $pos_only )) + current_action_args_start_index=$(( $word_index + 1 - $pos_only )) - current_action_is_positional=$2 + current_action_is_positional=$2 } # Notes: @@ -76,73 +76,73 @@ _set_new_action() { # x="hello" # ${!x} -> ${hello} -> "world" _shtab_pypr() { - local completing_word="${COMP_WORDS[COMP_CWORD]}" - local completed_positional_actions - local current_action - local current_action_args_start_index - local current_action_choices - local current_action_compgen - local current_action_is_positional - local current_action_nargs - local current_option_strings - local sub_parsers - COMPREPLY=() - - local prefix=_shtab_pypr - local word_index=0 - local pos_only=0 # "--" delimeter not encountered yet - _set_parser_defaults - word_index=1 - - # determine what arguments are appropriate for the current state - # of the arg parser - while [ $word_index -ne $COMP_CWORD ]; do - local this_word="${COMP_WORDS[$word_index]}" - - if [[ $pos_only = 1 || " $this_word " != " -- " ]]; then - if [[ -n $sub_parsers && " ${sub_parsers[@]} " == *" ${this_word} "* ]]; then - # valid subcommand: add it to the prefix & reset the current action - prefix="${prefix}_$(_shtab_replace_nonword $this_word)" - _set_parser_defaults - fi - - if [[ " ${current_option_strings[@]} " == *" ${this_word} "* ]]; then - # a new action should be acquired (due to recognised option string or - # no more input expected from current action); - # the next positional action can fill in here - _set_new_action $this_word false - fi - - if [[ "$current_action_nargs" != "*" ]] && \ - [[ "$current_action_nargs" != "+" ]] && \ - [[ "$current_action_nargs" != *"..." ]] && \ - (( $word_index + 1 - $current_action_args_start_index - $pos_only >= \ - $current_action_nargs )); then - $current_action_is_positional && let "completed_positional_actions += 1" - _set_new_action "pos_${completed_positional_actions}" true - fi + local completing_word="${COMP_WORDS[COMP_CWORD]}" + local completed_positional_actions + local current_action + local current_action_args_start_index + local current_action_choices + local current_action_compgen + local current_action_is_positional + local current_action_nargs + local current_option_strings + local sub_parsers + COMPREPLY=() + + local prefix=_shtab_pypr + local word_index=0 + local pos_only=0 # "--" delimeter not encountered yet + _set_parser_defaults + word_index=1 + + # determine what arguments are appropriate for the current state + # of the arg parser + while [ $word_index -ne $COMP_CWORD ]; do + local this_word="${COMP_WORDS[$word_index]}" + + if [[ $pos_only = 1 || " $this_word " != " -- " ]]; then + if [[ -n $sub_parsers && " ${sub_parsers[@]} " == *" ${this_word} "* ]]; then + # valid subcommand: add it to the prefix & reset the current action + prefix="${prefix}_$(_shtab_replace_nonword $this_word)" + _set_parser_defaults + fi + + if [[ " ${current_option_strings[@]} " == *" ${this_word} "* ]]; then + # a new action should be acquired (due to recognised option string or + # no more input expected from current action); + # the next positional action can fill in here + _set_new_action $this_word false + fi + + if [[ "$current_action_nargs" != "*" ]] && \ + [[ "$current_action_nargs" != "+" ]] && \ + [[ "$current_action_nargs" != *"..." ]] && \ + (( $word_index + 1 - $current_action_args_start_index - $pos_only >= \ + $current_action_nargs )); then + $current_action_is_positional && let "completed_positional_actions += 1" + _set_new_action "pos_${completed_positional_actions}" true + fi + else + pos_only=1 # "--" delimeter encountered + fi + + let "word_index+=1" + done + + # Generate the completions + + if [[ $pos_only = 0 && "${completing_word}" == -* ]]; then + # optional argument started: use option strings + COMPREPLY=( $(compgen -W "${current_option_strings[*]}" -- "${completing_word}") ) else - pos_only=1 # "--" delimeter encountered + # use choices & compgen + local IFS=$'\n' # items may contain spaces, so delimit using newline + COMPREPLY=( $([ -n "${current_action_compgen}" ] \ + && "${current_action_compgen}" "${completing_word}") ) + unset IFS + COMPREPLY+=( $(compgen -W "${current_action_choices[*]}" -- "${completing_word}") ) fi - let "word_index+=1" - done - - # Generate the completions - - if [[ $pos_only = 0 && "${completing_word}" == -* ]]; then - # optional argument started: use option strings - COMPREPLY=( $(compgen -W "${current_option_strings[*]}" -- "${completing_word}") ) - else - # use choices & compgen - local IFS=$'\n' # items may contain spaces, so delimit using newline - COMPREPLY=( $([ -n "${current_action_compgen}" ] \ - && "${current_action_compgen}" "${completing_word}") ) - unset IFS - COMPREPLY+=( $(compgen -W "${current_action_choices[*]}" -- "${completing_word}") ) - fi - - return 0 + return 0 } complete -o filenames -F _shtab_pypr pypr diff --git a/scripts/completions/pypr.zsh b/scripts/completions/pypr.zsh index 0955f4d7..0dd2176c 100644 --- a/scripts/completions/pypr.zsh +++ b/scripts/completions/pypr.zsh @@ -20,7 +20,7 @@ _shtab_pypr_commands() { "expose:Show all windows in the current workspace. [expose]" "fetch_client_menu:Fetch a client menu. [fetch_client_menu]" "unfetch_client:Unfetch a client. [fetch_client_menu]" - "gbar:restart gBar on the first available monitor. [gbar]" + "bar:restart MenuBar on the first available monitor. [menubar]" "layout_center:Change the active window. [layout_center]" "menu:Show a menu. [shortcuts_menu]" "relayout:Relayout the current workspace. [monitors]" @@ -63,7 +63,7 @@ _shtab_pypr_expose_options=( _shtab_pypr_fetch_client_menu_options=( ) -_shtab_pypr_gbar_options=( +_shtab_pypr_bar_options=( ":action:(restart)" ) @@ -144,7 +144,7 @@ _shtab_pypr() { exit) _arguments -C -s $_shtab_pypr_exit_options ;; expose) _arguments -C -s $_shtab_pypr_expose_options ;; fetch_client_menu) _arguments -C -s $_shtab_pypr_fetch_client_menu_options ;; - gbar) _arguments -C -s $_shtab_pypr_gbar_options ;; + bar) _arguments -C -s $_shtab_pypr_bar_options ;; help) _arguments -C -s $_shtab_pypr_help_options ;; hide) _arguments -C -s $_shtab_pypr_hide_options ;; layout_center) _arguments -C -s $_shtab_pypr_layout_center_options ;;