Skip to content

Commit

Permalink
Update completions to use new method
Browse files Browse the repository at this point in the history
  • Loading branch information
zappolowski committed Apr 19, 2024
1 parent b852511 commit 30b83c4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ distro's repositories, don't worry, it's not hard to build it yourself.
- wayland-client (can build without, see [make parameters](#make-parameters))
- wayland-protocols (optional, for recompiling protocols)
- xdg-utils (optional, xdg-open is the default 'browser' for opening URLs)
- jq (optional, for installed completions and tools in contrib)

The names will be different depending on your [distribution](https://github.com/dunst-project/dunst/wiki/Dependencies).

Expand Down
5 changes: 2 additions & 3 deletions completions/_dunstctl.zshcomp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
local curcontext="$curcontext" ret=1
local -a state line subs

local DUNSTRC="${XDG_CONFIG_HOME:-$HOME/.config}/dunst/dunstrc"

_arguments -C \
'1:cmd:->cmds' \
'2:opt:->opts' \
Expand All @@ -30,6 +28,7 @@ case $state in
'get-pause-level:Get current dunst's pause level'
'set-pause-level:Set current dunst's pause level'
'rule:Enable or disable a rule by its name'
'rules:Displays configured rules'
'debug:Print debugging information'
'help:Show this help'
)
Expand Down Expand Up @@ -63,7 +62,7 @@ case $state in
rule)
local -a rules;
rules=(
`awk '/^\[.*\]/{ if ( match($0, /^\[global|urgency|experimental/) == 0 ) { print substr($0, 2, length($0)-2) } }' < "$DUNSTRC"`
`dunstctl rules --json | jq -r '.data[][].name.data'`
)
_describe rules_opts rules && ret=0
;;
Expand Down
9 changes: 5 additions & 4 deletions completions/dunstctl.bashcomp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
_dunstctl() {
local opts cur prev split=false
local DUNSTRC=${XDG_CONFIG_HOME:-$HOME/.config}/dunst/dunstrc
_get_comp_words_by_ref cur prev
COMPREPLY=()
opts='action close close-all context count debug help history history-clear history-pop history-rm is-paused rule set-paused'
opts='action close close-all context count debug help history history-clear history-pop history-rm is-paused rule rules set-paused'

case "$prev" in
count) COMPREPLY=('displayed' 'history' 'waiting')
Expand All @@ -15,8 +14,10 @@ _dunstctl() {
awk '/"data" :/{print $3}' | sort -u) )
return ;;
rule)
COMPREPLY=( $(awk \
'/^\[.*\]/{ if ( match($0, /^\[global|experimental/) == 0 ) print substr($0, 2, length($0)-2) }' "$DUNSTRC" ) )
COMPREPLY=( $( compgen -W "$(dunstctl rules --json | jq -r '.data[][].name.data')" -- $cur ) )
return ;;
rules)
COMPREPLY=( $( compgen -W "--json" ) )
return ;;
esac

Expand Down
10 changes: 2 additions & 8 deletions completions/dunstctl.fishcomp
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
if command -q jq
function __fish_dunstctl_info
dunstctl (string split ' ' $argv[1]) | jq -r ".data[][] | \"\(.$argv[2].data)\t\(.$argv[3].data)\""
end
else
function __fish_dunstctl_info
dunstctl (string split ' ' $argv[1]) | awk -vpattern="\"$argv[2]\" :" '$0 ~ pattern {getline; getline; gsub("\"", "", $3); print $3}'
end
function __fish_dunstctl_info
dunstctl (string split ' ' $argv[1]) | jq -r ".data[][] | \"\(.$argv[2].data)\t\(.$argv[3].data)\""
end

function __fish_dunstctl_rule_complete
Expand Down

0 comments on commit 30b83c4

Please sign in to comment.