On Tue, May 26, 2015 at 06:03:18AM -0400, Xu Wang wrote: > > I have taken your advice and have now set up mutt-kz. I have one > question. Suppose I have a message id. How can I have a command that > starts mutt and have it show that message (i.e. run the notmuch search > query and show results)?
You can take a look at the attached script (you will need to edit a bit, more later): $ mutt-search id:message-id will open the whole thread with that particular message id, $ mutt-search -m id:message-id will open just that single message. Instead of id:message-id, you could pass any valid notmuch search query (properly quoted, of course, to protect from shell expansion) to open those messages in mutt. If you do not pass any query, the script will prompt for one (no quoting necessary here). The prompt also has history, and supports editing with readline. Now to get it working in your setup, you should put the promphistory file some place where it can be sourced, and edit mutt-search appropriately. Alternately, you could also copy paste the contents of promphistory in mutt-search or exclude the whole thing for simplicity. > Thank you for your continuing guidance and encouragement, Suvayu. You are welcome. For notmuch questions, I recommend the notmuch list, the devs are very friendly. For mutt-kz questions, the mutt-kz list is good but since the community is small there are few people on it. (I'm on both) If you have questions that are off-topic on either of these lists, please feel free to contact me directly. However, I'm very busy these days, so you will have to be a bit patient :). Cheers, -- Suvayu Open source is the future. It sets us free.
#!/bin/bash # set -o xtrace # handle query_type options declare no_threads # parse options for opt in "$@"; do [[ $opt == -m ]] && no_threads=1 && shift 1 && break; done # query with history declare LIBDIR="${0%/*}/lib" source "$LIBDIR/prompthistory" _ph_histfile ~/.mutt_search_history declare query=$(_ph_save_inputp "$*" "Enter notmuch query: ") declare vfolder if [[ $query =~ ^=.* ]]; then vfolder="${query}" else vfolder="notmuch://?query=${query}" fi declare query_type # toggle b/w threads and messages if [[ no_threads -gt 0 ]]; then query_type="set nm_query_type=messages" else query_type=";set nm_query_type=threads" fi # call mutt-kz if [[ -n $query ]]; then mutt -e "set sidebar_visible=no" -e "${query_type}" -f "$vfolder" else echo "Empty query string! Quitting." && sleep 1 fi
# -*- mode: sh; -*- ## namespace: _ph_ ## Usage: # input w/ history # _ph_histfile ~/.myscript_history # # 1. save in single string # declare input=$(_ph_save_inputp "$*" "prompt string: ") # # 2. save in array, tokenised by spaces # declare input=($(_ph_save_inputp "$*" "prompt string: ")) # split input like this: # declare nth="${input[<n>]}" # nth argument # unset input[0] # erase element from input # declare rest="${input[@]}" # rest of the elements # setup history file function _ph_histfile() { export HISTFILE="$1" if [[ ! -e $HISTFILE ]]; then touch "$HISTFILE" fi } # read prompt function _ph_save_inputp() { local input="$1" prompt="${2:-: }" if [[ -z $input ]]; then # native readline, with bash history -c # Clear all current history. history -n # Read everything from history file. # read input with spaces IFS= read -ep "$prompt" input # # readline with rlwrap, hangs around with signalled QUIT (C-c) as # # it is waiting for EOF (C-d) # input=$(rlwrap -H $history_file -S "$prompt" -o cat) fi # save input to HISTFILE echo "$input" >> "$HISTFILE" echo "$input" }