help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Input history when using read


From: Suvayu Ali
Subject: [Help-bash] Input history when using read
Date: Tue, 5 Feb 2013 13:00:27 +0100
User-agent: Mutt/1.5.21 (2011-07-01)

Hi,

I have a script that searches through emails for me.  I read in my
search query either as positional parameters or read.  Often I want to
repeat a variation of a complicated search.  I was wondering if it is
possible to have some sort of history when I get the query using read.
This is what I have so far:

  # search query history
  declare history_file=~/.mutt_search_history
  if [[ ! -e $history_file ]]; then
      touch $history_file
  fi

  declare query_hist=$(tail -n 1 $history_file)

  # save query
  declare query="$@"

  if [[ -z $query ]]; then
      IFS= read -e -i "$query_hist" -p "Enter notmuch query: " query
  fi

  # save history
  echo "$query" >> $history_file

Of course with the above I cannot get history browsing with up arrows to
work.  It would be even more awesome if I could use C-r or C-s to search
through it.

Any hints or ideas?

PS: I thought of populating an array from the history file, but could
    not figure out how I can browse through it in read.

--
Suvayu

Open source is the future. It sets us free.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]