help-bash
[Top][All Lists]
Advanced

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

Re: redirection back to tty problem


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

so i dunno much about redirection but first i 1 and 2 to tty and it shows
no problem
then in PROMPT_COMMAND the same has no effect:

curl http://ix.io/3QTT
fg
vim cmdhelp

[1]+  Stopped                 vim cmdhelp
148 exit 69373s old @1645958807.31567 == Sun Feb 2022-02-27 11:46:47.31567
+0100
# root:0:0 # @ /dev/pts/2 ( 1 ) boost -> /root
.config/ .xbl/ tt/ xbl5/ xbl5e/ xmbttpd/ .pki/ .cache/ .local/ .john/ ar_x/
GNUstep/ .ssh/
.cmdhelp.swp cmdhelp .bash_history 2 4 3 .viminfo .lesshst 1 foo2.png
foo.png .xinitrc .xbl.bash docs.install.sshssl
.bashrc@ .profile@
bash --norc
bash-5.1# . cmdhelp
bash-5.1# w
 11:46:51 up 1 day, 13:15,  5 users,  load average: 1.05, 1.36, 1.51
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty2     -                Fri23   36:30m  0.08s  0.04s -bash
root     pts/1    :0               Sat16   19:16m  0.00s  0.00s bash
root     pts/2    :0.0             Sat16    3.00s  0.34s  0.00s w
root     pts/3    :0.0             Sat16   17:51m  0.00s  0.00s bash
root     pts/4    :0.0             Sat16   26:10   0.45s  0.45s bash
bash-5.1# w --help
130 exit 69381s old @1645958815.065149 == Sun Feb 2022-02-27
11:46:55.065149 +0100
#!/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
}

exec 1>/dev/tty 2>/dev/tty
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 2>/dev/tty 1>/dev/tty
 {
  printf %s "$cmd

"
  cat "$o2"
 } | vim -
 cmd= # multi sourced clean up
fi
'$PROMPT_COMMAND

On Sun, Feb 27, 2022 at 11:31 AM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
wrote:
>
> 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]