zsh-users
 help / color / mirror / code / Atom feed
* option to show file:line everytime echo is called?
@ 2017-01-09 23:55 ` Timothee Cour
  2017-01-10  9:30   ` Peter Stephenson
  2017-01-10 12:30   ` Anthony Heading
  0 siblings, 2 replies; 18+ messages in thread
From: Timothee Cour @ 2017-01-09 23:55 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 262 bytes --]

is there an option to show file:line everytime echo is called? eg:

set -magic_echo_option

echo myvr=$myvar #assuming this is at line 19

#shows:

/home/timothee/.zshrc:19 myvar=FOO

if impossible what would be a workaround ? or another command that does
this?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-09 23:55 ` option to show file:line everytime echo is called? Timothee Cour
@ 2017-01-10  9:30   ` Peter Stephenson
  2017-01-10 11:22     ` Timothee Cour
       [not found]     ` <CANri+EwT3h8MkpeKSd-9_QLp9S=TEibmSgjS3r9mv0jY46dQAw__39244.7733007886$1484262699$gmane$org@mail.gmail.com>
  2017-01-10 12:30   ` Anthony Heading
  1 sibling, 2 replies; 18+ messages in thread
From: Peter Stephenson @ 2017-01-10  9:30 UTC (permalink / raw)
  To: zsh-users; +Cc: Timothee Cour

On Mon, 9 Jan 2017 15:55:08 -0800
Timothee Cour <timothee.cour2@gmail.com> wrote:
> is there an option to show file:line everytime echo is called? eg:
> 
> set -magic_echo_option
> 
> echo myvr=$myvar #assuming this is at line 19
> 
> #shows:
> 
> /home/timothee/.zshrc:19 myvar=FOO

"set -x" does this in most shells.

You can change the information by altering the variable PS4, but it's
probably good enough.

pws


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-10  9:30   ` Peter Stephenson
@ 2017-01-10 11:22     ` Timothee Cour
  2017-01-10 12:28       ` Peter Stephenson
       [not found]     ` <CANri+EwT3h8MkpeKSd-9_QLp9S=TEibmSgjS3r9mv0jY46dQAw__39244.7733007886$1484262699$gmane$org@mail.gmail.com>
  1 sibling, 1 reply; 18+ messages in thread
From: Timothee Cour @ 2017-01-10 11:22 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-users, Timothee Cour

[-- Attachment #1: Type: text/plain, Size: 646 bytes --]

Thanks; `set -x` is rather verbose, is there any other way to just alter
echo to show file:line (or similar) ?


On Tue, Jan 10, 2017 at 1:30 AM, Peter Stephenson <p.stephenson@samsung.com>
wrote:

> On Mon, 9 Jan 2017 15:55:08 -0800
> Timothee Cour <timothee.cour2@gmail.com> wrote:
> > is there an option to show file:line everytime echo is called? eg:
> >
> > set -magic_echo_option
> >
> > echo myvr=$myvar #assuming this is at line 19
> >
> > #shows:
> >
> > /home/timothee/.zshrc:19 myvar=FOO
>
> "set -x" does this in most shells.
>
> You can change the information by altering the variable PS4, but it's
> probably good enough.
>
> pws
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-10 11:22     ` Timothee Cour
@ 2017-01-10 12:28       ` Peter Stephenson
  0 siblings, 0 replies; 18+ messages in thread
From: Peter Stephenson @ 2017-01-10 12:28 UTC (permalink / raw)
  To: zsh-users

On Tue, 10 Jan 2017 03:22:00 -0800
Timothee Cour <timothee.cour2@gmail.com> wrote:
> Thanks; `set -x` is rather verbose, is there any other way to just alter
> echo to show file:line (or similar) ?

OK, you have an *explicit* echo, and you want to add some more
information to it by hand?  You don't want the shell to output
information automatically, as I assumed?

You can output the information from $PS4 by using "print -P".  So for
example

print -P $PS4 Got to this bit.

Prompt sequences are expanded but anything else is printed as normal.

pws


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-09 23:55 ` option to show file:line everytime echo is called? Timothee Cour
  2017-01-10  9:30   ` Peter Stephenson
@ 2017-01-10 12:30   ` Anthony Heading
  2017-01-10 12:50     ` Timothee Cour
                       ` (2 more replies)
  1 sibling, 3 replies; 18+ messages in thread
From: Anthony Heading @ 2017-01-10 12:30 UTC (permalink / raw)
  To: Timothee Cour; +Cc: zsh-users

On Mon, Jan 09, 2017 at 03:55:08PM -0800, Timothee Cour wrote:
> is there an option to show file:line everytime echo is called? eg:
> echo myvr=$myvar #assuming this is at line 19
> #shows:
> /home/timothee/.zshrc:19 myvar=FOO

Maybe use an alias?

#!/bin/env zsh
alias echo='echo ${0:A}:$LINENO'

myvar=FOO

echo myvr=$myvar #this seems actually to be line 6


prints

/home/ajrh/x:6 myvr=FOO


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-10 12:30   ` Anthony Heading
@ 2017-01-10 12:50     ` Timothee Cour
  2017-01-10 17:12     ` Ray Andrews
       [not found]     ` <8ed3897d-82d3-5c5f-f2c1-5382e311e931__1904.16159243814$1484070246$gmane$org@eastlink.ca>
  2 siblings, 0 replies; 18+ messages in thread
From: Timothee Cour @ 2017-01-10 12:50 UTC (permalink / raw)
  To: Anthony Heading; +Cc: Timothee Cour, zsh-users

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

thanks!

On Tue, Jan 10, 2017 at 4:30 AM, Anthony Heading <ajrh@ajrh.net> wrote:

> On Mon, Jan 09, 2017 at 03:55:08PM -0800, Timothee Cour wrote:
> > is there an option to show file:line everytime echo is called? eg:
> > echo myvr=$myvar #assuming this is at line 19
> > #shows:
> > /home/timothee/.zshrc:19 myvar=FOO
>
> Maybe use an alias?
>
> #!/bin/env zsh
> alias echo='echo ${0:A}:$LINENO'
>
> myvar=FOO
>
> echo myvr=$myvar #this seems actually to be line 6
>
>
> prints
>
> /home/ajrh/x:6 myvr=FOO
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-10 12:30   ` Anthony Heading
  2017-01-10 12:50     ` Timothee Cour
@ 2017-01-10 17:12     ` Ray Andrews
       [not found]     ` <8ed3897d-82d3-5c5f-f2c1-5382e311e931__1904.16159243814$1484070246$gmane$org@eastlink.ca>
  2 siblings, 0 replies; 18+ messages in thread
From: Ray Andrews @ 2017-01-10 17:12 UTC (permalink / raw)
  To: zsh-users

On 10/01/17 04:30 AM, Anthony Heading wrote:
>
> Maybe use an alias?
>
> #!/bin/env zsh
> alias echo='echo ${0:A}:$LINENO'
Where can I read up on " ${0:A} ", I haven't seen that construction before.
And probably there's a host of siblings equally useful.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
       [not found]     ` <8ed3897d-82d3-5c5f-f2c1-5382e311e931__1904.16159243814$1484070246$gmane$org@eastlink.ca>
@ 2017-01-10 18:17       ` Daniel Shahaf
  2017-01-12  2:25         ` Timothee Cour
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Shahaf @ 2017-01-10 18:17 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

Ray Andrews wrote on Tue, Jan 10, 2017 at 09:12:37 -0800:
> On 10/01/17 04:30 AM, Anthony Heading wrote:
> >
> >Maybe use an alias?
> >
> >#!/bin/env zsh
> >alias echo='echo ${0:A}:$LINENO'
> Where can I read up on " ${0:A} ", I haven't seen that construction before.
> And probably there's a host of siblings equally useful.

That's the `:A' modifier applied to the `$0' variable.

:A is in http://zsh.sourceforge.net/Doc/Release/Expansion.html#Modifiers

$0 is in http://zsh.sourceforge.net/Doc/Release/Parameters.html#Parameters-Set-By-The-Shell


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-10 18:17       ` Daniel Shahaf
@ 2017-01-12  2:25         ` Timothee Cour
  2017-01-12  4:33           ` Anthony Heading
  0 siblings, 1 reply; 18+ messages in thread
From: Timothee Cour @ 2017-01-12  2:25 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Ray Andrews, zsh-users

[-- Attachment #1: Type: text/plain, Size: 859 bytes --]

actually this doesn't work:

path/.zshrc:
```
alias echo2='echo ${0:A}:$LINENO'
echo2 FOO
fun(){
  echo2 BAR
}
fun
```

shows:
path/.zshrc:2 FOO #OK
$PWD/fun:1 BAR #NOT OK, I want path/.zshrc:4

On Tue, Jan 10, 2017 at 10:17 AM, Daniel Shahaf <d.s@daniel.shahaf.name>
wrote:

> Ray Andrews wrote on Tue, Jan 10, 2017 at 09:12:37 -0800:
> > On 10/01/17 04:30 AM, Anthony Heading wrote:
> > >
> > >Maybe use an alias?
> > >
> > >#!/bin/env zsh
> > >alias echo='echo ${0:A}:$LINENO'
> > Where can I read up on " ${0:A} ", I haven't seen that construction
> before.
> > And probably there's a host of siblings equally useful.
>
> That's the `:A' modifier applied to the `$0' variable.
>
> :A is in http://zsh.sourceforge.net/Doc/Release/Expansion.html#Modifiers
>
> $0 is in http://zsh.sourceforge.net/Doc/Release/Parameters.html#
> Parameters-Set-By-The-Shell
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-12  2:25         ` Timothee Cour
@ 2017-01-12  4:33           ` Anthony Heading
  0 siblings, 0 replies; 18+ messages in thread
From: Anthony Heading @ 2017-01-12  4:33 UTC (permalink / raw)
  To: Timothee Cour; +Cc: zsh-users

On Wed, Jan 11, 2017 at 06:25:30PM -0800, Timothee Cour wrote:
> actually this doesn't work:
> $PWD/fun:1 BAR #NOT OK, I want path/.zshrc:4

OK, so maybe this then:

alias echo2='echo ${(%):-%x:%I}'


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
       [not found]     ` <CANri+EwT3h8MkpeKSd-9_QLp9S=TEibmSgjS3r9mv0jY46dQAw__39244.7733007886$1484262699$gmane$org@mail.gmail.com>
@ 2017-01-13  3:57       ` Daniel Shahaf
  2017-01-13  7:57         ` Bart Schaefer
       [not found]         ` <alpine.LRH.2.00.1701122304500.4560__6317.49331155351$1484294388$gmane$org@toltec.zanshin.com>
  0 siblings, 2 replies; 18+ messages in thread
From: Daniel Shahaf @ 2017-01-13  3:57 UTC (permalink / raw)
  To: Timothee Cour; +Cc: Peter Stephenson, zsh-users

Timothee Cour wrote on Tue, Jan 10, 2017 at 03:22:00 -0800:
> Thanks; `set -x` is rather verbose, is there any other way to just alter
> echo to show file:line (or similar) ?

% echo() { set -x; builtin echo "$@" }
% setopt promptsubst
% PS4='$functrace> ' 
% source =(<<<$'print foo\nf(){\necho bar\n}\nf\n')
foo
f:1 /tmp/zshqKiKeo:5 zsh:9> echo bar
bar

See zshmodules(1) for $functrace.

Cheers,

Daniel


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-13  3:57       ` Daniel Shahaf
@ 2017-01-13  7:57         ` Bart Schaefer
  2017-01-13  8:06           ` Bart Schaefer
       [not found]         ` <alpine.LRH.2.00.1701122304500.4560__6317.49331155351$1484294388$gmane$org@toltec.zanshin.com>
  1 sibling, 1 reply; 18+ messages in thread
From: Bart Schaefer @ 2017-01-13  7:57 UTC (permalink / raw)
  To: zsh-users; +Cc: Timothee Cour

On Fri, 13 Jan 2017, Daniel Shahaf wrote:

> % echo() { set -x; builtin echo "$@" }

That's more output than he wanted.

  echo() { print -n "$funcfiletrace> "; builtin echo "$@" }

is probably more like it.

Similarly

  typeset -AgH whence_my_alias
  alias() {
    emulate -L zsh
    local opts
    zparseopts -D -a opts L g m r s
    if [[ -z $opts[-m] && $1 = *=* ]] && whence_my_alias[${1%=*}]=$functrace
    builtin alias $opts $*
  }
  whence() {
    local whence="$(builtin whence "$@")"
    case "$whence" in
    (* is an alias for *)
       local from="${whence_my_alias[${whence%% *}]}"
       print -r -- "$whence" ${from:+from} "$from"
       ;;
    (*) print -r -- "$whence";;
    esac
  }

Some edge cases possibly not caught.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-13  7:57         ` Bart Schaefer
@ 2017-01-13  8:06           ` Bart Schaefer
  2017-01-13  8:31             ` Timothee Cour
  2017-01-13  8:32             ` Timothee Cour
  0 siblings, 2 replies; 18+ messages in thread
From: Bart Schaefer @ 2017-01-13  8:06 UTC (permalink / raw)
  To: zsh-users; +Cc: Timothee Cour

On Thu, 12 Jan 2017, Bart Schaefer wrote:

>     case "$whence" in
>     (* is an alias for *)
>
> Some edge cases possibly not caught.

Change that to (* is * alias for *) ...


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-13  8:06           ` Bart Schaefer
@ 2017-01-13  8:31             ` Timothee Cour
  2017-01-13  8:32             ` Timothee Cour
  1 sibling, 0 replies; 18+ messages in thread
From: Timothee Cour @ 2017-01-13  8:31 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users, Timothee Cour

[-- Attachment #1: Type: text/plain, Size: 449 bytes --]

turns out Anthony Heading's solution works great (thanks!)
```
alias echo2='echo ${(%):-%x:%I}'
```

any downside compared to Daniel Shahaf's solution i haven't seen yet?

On Fri, Jan 13, 2017 at 12:06 AM, Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Thu, 12 Jan 2017, Bart Schaefer wrote:
>
> >     case "$whence" in
> >     (* is an alias for *)
> >
> > Some edge cases possibly not caught.
>
> Change that to (* is * alias for *) ...
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-13  8:06           ` Bart Schaefer
  2017-01-13  8:31             ` Timothee Cour
@ 2017-01-13  8:32             ` Timothee Cour
  2017-01-14  0:36               ` Ray Andrews
  2017-01-14 16:58               ` Bart Schaefer
  1 sibling, 2 replies; 18+ messages in thread
From: Timothee Cour @ 2017-01-13  8:32 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 443 bytes --]

turns out Anthony Heading's solution works great (thanks!): alias
echo2='echo ${(%):-%x:%I}'

any downside compared to Daniel Shahaf's solution i haven't seen yet?


On Fri, Jan 13, 2017 at 12:06 AM, Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Thu, 12 Jan 2017, Bart Schaefer wrote:
>
> >     case "$whence" in
> >     (* is an alias for *)
> >
> > Some edge cases possibly not caught.
>
> Change that to (* is * alias for *) ...
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
       [not found]         ` <alpine.LRH.2.00.1701122304500.4560__6317.49331155351$1484294388$gmane$org@toltec.zanshin.com>
@ 2017-01-13 14:52           ` Daniel Shahaf
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel Shahaf @ 2017-01-13 14:52 UTC (permalink / raw)
  To: zsh-users; +Cc: Timothee Cour

Bart Schaefer wrote on Thu, Jan 12, 2017 at 23:57:49 -0800:
>   alias() {
>     if [[ -z $opts[-m] && $1 = *=* ]] && whence_my_alias[${1%=*}]=$functrace

[${1%%=*}]

> Some edge cases possibly not caught.

'alias' can take more than one positional argument.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-13  8:32             ` Timothee Cour
@ 2017-01-14  0:36               ` Ray Andrews
  2017-01-14 16:58               ` Bart Schaefer
  1 sibling, 0 replies; 18+ messages in thread
From: Ray Andrews @ 2017-01-14  0:36 UTC (permalink / raw)
  To: zsh-users

On 13/01/17 12:32 AM, Timothee Cour wrote:
> turns out Anthony Heading's solution works great (thanks!): alias
> echo2='echo ${(%):-%x:%I}'
I have a function 'varis' that does something similar but it uses 
$LINENO which reports the line number within the function, but I see 
that the above reports the line number within the file which is very 
nice for the obvious reason that if you have several functions defined 
in one file, you don't constantly have to do the arithmetic of the line 
offset from where the function begins in the file.  But I'm curious as 
to how the  above can work, or even how $LINENO works, since, once a 
function is sourced, it exists in it's -- don' t know the correct term 
-- 'cut down' or 'pure' form with no blank lines or comments (I think), 
so how does zsh know/remember what the function looks like in the 
original file?  Does it go back and check when the above is used or does 
it have some way of remembering? That doesn't seem reasonable, still it 
works perfectly.

Way down in some file:

    xx ()
    {

         jjunk="This is jjunk"



         varis jjunk
         echo ${(%):-%x:%I}

    }

    $ xx
    xx, line 7:  evaluated: "$jjunk" is: |This is jjunk|
    ./varis:91


... so the 'echo' knows the true line number and the name of the file 
vs. knowing the name of the function and the line within the function.  
Nice to have both available!


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: option to show file:line everytime echo is called?
  2017-01-13  8:32             ` Timothee Cour
  2017-01-14  0:36               ` Ray Andrews
@ 2017-01-14 16:58               ` Bart Schaefer
  1 sibling, 0 replies; 18+ messages in thread
From: Bart Schaefer @ 2017-01-14 16:58 UTC (permalink / raw)
  To: Timothee Cour; +Cc: Zsh Users

On Fri, 13 Jan 2017, Timothee Cour wrote:

> turns out Anthony Heading's solution works great (thanks!): alias
> echo2='echo ${(%):-%x:%I}'
>
> any downside compared to Daniel Shahaf's solution i haven't seen yet?

Use of $funcfiletrace (like in my follow-up to Daniel) will show you
not just the file:line where the echo was called, but also the file:line
where the caller of echo was called, and so on all the way up to the
top-level execution loop e.g. the interactive command line.


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2017-01-14 16:58 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170110091259epcas5p14d052ee1dc7ebb5c4dd74e4aa02a8d18@epcas5p1.samsung.com>
2017-01-09 23:55 ` option to show file:line everytime echo is called? Timothee Cour
2017-01-10  9:30   ` Peter Stephenson
2017-01-10 11:22     ` Timothee Cour
2017-01-10 12:28       ` Peter Stephenson
     [not found]     ` <CANri+EwT3h8MkpeKSd-9_QLp9S=TEibmSgjS3r9mv0jY46dQAw__39244.7733007886$1484262699$gmane$org@mail.gmail.com>
2017-01-13  3:57       ` Daniel Shahaf
2017-01-13  7:57         ` Bart Schaefer
2017-01-13  8:06           ` Bart Schaefer
2017-01-13  8:31             ` Timothee Cour
2017-01-13  8:32             ` Timothee Cour
2017-01-14  0:36               ` Ray Andrews
2017-01-14 16:58               ` Bart Schaefer
     [not found]         ` <alpine.LRH.2.00.1701122304500.4560__6317.49331155351$1484294388$gmane$org@toltec.zanshin.com>
2017-01-13 14:52           ` Daniel Shahaf
2017-01-10 12:30   ` Anthony Heading
2017-01-10 12:50     ` Timothee Cour
2017-01-10 17:12     ` Ray Andrews
     [not found]     ` <8ed3897d-82d3-5c5f-f2c1-5382e311e931__1904.16159243814$1484070246$gmane$org@eastlink.ca>
2017-01-10 18:17       ` Daniel Shahaf
2017-01-12  2:25         ` Timothee Cour
2017-01-12  4:33           ` Anthony Heading

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).