X-Git-Url: https://projects.mako.cc/source/muttjump/blobdiff_plain/87eb08b936de875795694d6f773fc40ad9eed0c3..a2cab25a1101edc120297360f5a2d3b173018fb4:/muttjump diff --git a/muttjump b/muttjump index b5736d5..60da940 100755 --- a/muttjump +++ b/muttjump @@ -80,6 +80,15 @@ END exit 1 } +function reopen_tty () { + # Close message-stdin and open terminal-stdin instead. + # mutt behaves different if STDIN is no terminal + # TODO: Find cleaner solution (e.g. mutt command-line argument?) + exec 0<&- + term="/dev/$(ps -p$$ -otty=)" + exec < $term +} + # Check command-line arguments and STDIN search_header="Message-ID" @@ -177,31 +186,29 @@ if [ ! -d "$orig_maildir/cur" ] ; then fi jump_expr="~i'$msgid'" +jump_cmd="$jump_expr" +if [ "$MUTTJUMP_MODE" = search ] ; then + jump_cmd="$jump_cmdall" +fi if [ "$MUTTJUMP_MULTI_SCREEN_MODE" = no ] ; then - jump_cmd="$jump_expr" - if [ "$MUTTJUMP_MODE" = search ] ; then - jump_cmd="$jump_cmdall" - fi - if [ "$MUTTJUMP_USE_SCREEN" = auto -a -n "$STY" ] ; then MUTTJUMP_USE_SCREEN=yes fi screen_opts=() if [ "$MUTTJUMP_USE_SCREEN" = yes ] ; then - [ -n "$STY" ] && screen_opts=("-X" "screen") + if [ -n "$STY" ] ; then + screen_opts=("-X" "screen") + else + reopen_tty + fi screen_window_name=$(MUTTJUMP_SCREEN_WINDOW_NAME_MANGLE "$orig_maildir") screen_opts=("${screen_opts[@]}" "-t" "$screen_window_name") else SCREEN="" - # Close message-stdin and open terminal-stdin instead. - # mutt behaves different if STDIN is no terminal - # TODO: Find cleaner solution (e.g. mutt command-line argument?) - exec 0<&- - term="/dev/$(ps -p$$ -otty=)" - exec < $term + reopen_tty fi # start mutt, open original folder and jump to the original message @@ -209,12 +216,22 @@ if [ "$MUTTJUMP_MULTI_SCREEN_MODE" = no ] ; then else - jump_cmd="l$jump_expr " + jump_cmd_short="l$jump_expr " if [ "$MUTTJUMP_MODE" = search ] ; then - jump_cmd="${jump_cmd}lall " + jump_cmd_short="${jump_cmd_short}lall " fi screen_window_name=$(MUTTJUMP_SCREEN_WINDOW_NAME_MANGLE "$orig_maildir") - $SCREEN -p "$screen_window_name" -X eval "select '$screen_window_name'" "stuff \"$jump_cmd\"" + if [ -z "$STY" ] ; then + reopen_tty + $SCREEN -t "$screen_window_name" $MUTT -f "$orig_maildir" -e "push \"$jump_cmd\"" + else + $SCREEN -X -p "$screen_window_name" -Q select "$screen_window_name" >/dev/null + if [ $? != 0 ] ; then + $SCREEN -X screen -t "$screen_window_name" $MUTT -f "$orig_maildir" -e "push \"$jump_cmd\"" + else + $SCREEN -X -p "$screen_window_name" stuff "$jump_cmd_short" + fi + fi fi