Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mutt: handle neomutt -Q var correctly #463

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions completions/mutt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ _muttconffiles()
printf '%s\n' $sofar
}

# Query the value of a mutt configuration variable
# @param $1 Name of the variable
# @output Value of the variable
_muttconfvar()
{
local varname=$1 muttrc

muttrc=$(_muttrc)
$muttcmd -F "$muttrc" -Q $varname 2>/dev/null | command sed -e 's|^\(set[[:space:]]\{1,\}\)\{0,1\}'"$varname"'[[:space:]]*=[[:space:]]*\"\(.*\)\"$|\2|'
}

# @param $1 (cur) Current word to complete
_muttaliases()
{
Expand All @@ -87,7 +98,7 @@ _muttquery()
local cur=$1 querycmd muttcmd=${words[0]}
local -a queryresults

querycmd="$($muttcmd -Q query_command 2>/dev/null | command sed -e 's|^query_command=\"\(.*\)\"$|\1|' -e 's|%s|'$cur'|')"
querycmd="$(_muttconfvar query_command | command sed -e 's|%s|'$cur'|')"
if [[ -z $cur || -z $querycmd ]]; then
queryresults=()
else
Expand All @@ -104,9 +115,8 @@ _muttfiledir()
{
local cur=$1 folder muttrc spoolfile muttcmd=${words[0]}

muttrc=$(_muttrc)
if [[ $cur == [=+]* ]]; then
folder="$($muttcmd -F "$muttrc" -Q folder 2>/dev/null | command sed -e 's|^folder=\"\(.*\)\"$|\1|')"
folder="$(_muttconfvar folder)"
: folder:=~/Mail

# Match any file in $folder beginning with $cur
Expand All @@ -116,8 +126,7 @@ _muttfiledir()
COMPREPLY=(${COMPREPLY[@]#$folder/})
return
elif [[ $cur == !* ]]; then
spoolfile="$($muttcmd -F "$muttrc" -Q spoolfile 2>/dev/null |
command sed -e 's|^spoolfile=\"\(.*\)\"$|\1|')"
spoolfile="$(_muttconfvar spoolfile)"
[[ -n $spoolfile ]] && eval cur="${cur/^!/$spoolfile}"
fi
_filedir
Expand Down