help-bash
[Top][All Lists]
Advanced

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

redirection back to tty problem


From: Alex fxmbsw7 Ratchev
Subject: redirection back to tty problem
Date: Sun, 27 Feb 2022 11:31:30 +0100

i made by request of an user a script that intercepts whenever a --help cmd
is given, to open that output in vim ( nvim ) i guess to study, good thing

but the redirection back on line 23 ( to >/dev/tty ) doesnt seem to have
any effect

plz suggest, file 'cmdhelp'

#!/usr/bin/env -S bash

# for to be sourced in .bashrc or such

unset -v i
[[ ! ${i=$SRANDOM} ]] && {
 printf 'no support outdated bash plz update\n'
 exit 1
}

t=/tmp/.$i o1=$t.1 o2=$t.2

trap '
if [[ $BASH_COMMAND == *--help* ]] ; then
 exec >"$o2" 2>&1
 cmd=$BASH_COMMAND
else
 cmd=
fi' debug

PROMPT_COMMAND=$'
if [[ $cmd ]] ; then
 exec  >/dev/tty 2>&1
 {
  printf %s\\n\\n "$cmd"
  cat "$o2"
 } | vim -
 cmd= # multi sourced clean up
fi
'$PROMPT_COMMAND


reply via email to

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