Skip to content

Instantly share code, notes, and snippets.

@DBX12
Created July 5, 2023 10:29
Show Gist options
  • Save DBX12/2caecbe3b5ff4b0af46124939968eab2 to your computer and use it in GitHub Desktop.
Save DBX12/2caecbe3b5ff4b0af46124939968eab2 to your computer and use it in GitHub Desktop.
bash completion for dunstctl

Bash completion for dunst

The dunst project has a command line utility called dunstctl but no bash completion yet.

Installation

Drop the dunstctl file into the folder for bash completions on your machine, usually found in these places:

  • /usr/share/bash-completion/bash_completion/completions/
  • /etc/bash_completion.d/
  • ~/.bash_completion.d/ (might not be loaded on your setup)

Final notes

I'm planning to submit this as PR during hacktoberfest to the dunst project, so please be cool and don't steal that PR :)

# shellcheck shell=bash
_dunstctl () {
local cur prev words
cur="$2"
prev="$3"
# what words to suggest
words=()
# are we completing the first word?
if [[ "$COMP_CWORD" -eq 1 ]]; then
words=(action close close-all context history-pop is-paused set-paused debug help)
# are we completing for "set-paused"?
elif [[ "$COMP_CWORD" -eq 2 ]] && [[ "$prev" == "set-paused" ]]; then
words=(true false)
fi
# call compgen with $words and return only words which match the currently typed word
mapfile -t COMPREPLY < <(compgen -W "${words[*]}" -- "$cur")
}
complete -F _dunstctl dunstctl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment