From 4afaff42233fa1db51a807827600480d97510a60 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 30 May 2018 08:31:01 +1000 Subject: [PATCH] general: Started working on completion. --- completions/neofetch-completion.bash | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 completions/neofetch-completion.bash diff --git a/completions/neofetch-completion.bash b/completions/neofetch-completion.bash new file mode 100644 index 00000000..e2fec76c --- /dev/null +++ b/completions/neofetch-completion.bash @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# +# Shell completion for neofetch. + +_neofetch_completions() { + local flags cur prev + + # User input. + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + # Generate a list of flags. + IFS=$'\n' read -d "" -ra flags \ + < <(neofetch --help | awk '/^ --/{print $1}') + + # Complete partial matches. + IFS=$'\n' read -d "" -ra COMPREPLY \ + < <(compgen -W "${flags[*]}" -- "$cur") + + + case "$prev" in + "--disable") + conf="${HOME}/.config/neofetch/config.conf" + + [[ -f "$conf" ]] && + IFS=$'\n' read -d "" -ra COMPREPLY \ + < <(awk '/ info /&&!a[$0]++{print $NF}' "$conf") + ;; + + "--backend") + IFS=$'\n' read -d "" -ra COMPREPLY \ + < <(neofetch --help | awk -F\' '/ Shortcut/ {print $2}') + ;; + esac +} + +complete -F _neofetch_completions neofetch