zsh-users
 help / color / mirror / code / Atom feed
* separating functions, fpath, and autoload
@ 2018-08-13 13:49 TJ Luoma
  2018-08-13 13:55 ` TJ Luoma
  2018-08-13 13:56 ` Pier Paolo Grassi
  0 siblings, 2 replies; 12+ messages in thread
From: TJ Luoma @ 2018-08-13 13:49 UTC (permalink / raw)
  To: Zsh-Users List

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

I'm in the midst of an effort to try to learn some of zsh's more powerful
features, since I've been using zsh forever and feel like I only use 1% of
what it can do.

One of the things that I've wanted to do for awhile is separate out some of
my more complex functions to remove them from my .zshrc file and put them
into their own files. This should make them easier to track/change/etc and
it makes things a lot easier to read and debug.

Unfortunately, I can't seem to get it to work right. I'm sure I'm doing
something wrong because I don't really know what I'm doing, so I'll explain
what I've tried, and hopefully someone can explain where I've gone wrong.

I added this to my .zshrc

if [ -d "$ZDOTDIR/functions" ]
then
fpath=($ZDOTDIR/functions $fpath)
fi

The goal there was to add '$ZDOTDIR/functions' to the functions list, which
I think is the right way to do this.

I can verify that works, I think, by using 'echo $fpath':

$ echo $fpath
/Users/luomat/Dropbox/dotfiles/zsh/completion
/Users/luomat/Dropbox/dotfiles/zsh/functions
/usr/local/share/zsh/site-functions /usr/share/zsh/site-functions
/usr/share/zsh/5.3/functions

/Users/luomat/Dropbox/dotfiles is my $ZDOTDIR

The first file in '/Users/luomat/Dropbox/dotfiles/zsh/functions' is called
'msg'. For simplicity's sake, let's assume the contents of 'msg' is simply
this:

function msg  {

  echo "$@"

}

(It's actually more complicated than that, but that's the overall idea.)

I tried that, and then I tried

autoload msg

and I didn't get an error, but when I check 'which msg' I get this:

msg () {
# undefined
builtin autoload -X
}

so I've messed up something along the line.

Any help would be appreciated.

Thanks!

Tj


--
TJ Luoma
TJ @ MacStories <http://www.macstories.net/author/tjluoma/>
Personal Website: luo.ma <http://luo.ma/> (aka RhymesWithDiploma.com
<http://rhymeswithdiploma.com/>)
Twitter: @tjluoma <http://twitter.com/tjluoma>

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

* Re: separating functions, fpath, and autoload
  2018-08-13 13:49 separating functions, fpath, and autoload TJ Luoma
@ 2018-08-13 13:55 ` TJ Luoma
  2018-08-13 13:56 ` Pier Paolo Grassi
  1 sibling, 0 replies; 12+ messages in thread
From: TJ Luoma @ 2018-08-13 13:55 UTC (permalink / raw)
  To: Zsh-Users List

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

Of course, two minutes after I send my message, I had a thought.

I need to _use_ the 'msg' function before it will be defined. Before that,
it is the regular thing that I showed in my previous example, but once I
_use_ it, then it gets loaded, and is available.

Do I have that right?

So 'autoload' does not mean "load this right now" but rather "be prepared
to load this when it is asked for" ?

Tj


--
TJ Luoma
TJ @ MacStories <http://www.macstories.net/author/tjluoma/>
Personal Website: luo.ma <http://luo.ma/> (aka RhymesWithDiploma.com
<http://rhymeswithdiploma.com/>)
Twitter: @tjluoma <http://twitter.com/tjluoma>



On Mon, Aug 13, 2018 at 9:49 AM TJ Luoma <luomat@gmail.com> wrote:

>
> I'm in the midst of an effort to try to learn some of zsh's more powerful
> features, since I've been using zsh forever and feel like I only use 1% of
> what it can do.
>
> One of the things that I've wanted to do for awhile is separate out some
> of my more complex functions to remove them from my .zshrc file and put
> them into their own files. This should make them easier to track/change/etc
> and it makes things a lot easier to read and debug.
>
> Unfortunately, I can't seem to get it to work right. I'm sure I'm doing
> something wrong because I don't really know what I'm doing, so I'll explain
> what I've tried, and hopefully someone can explain where I've gone wrong.
>
> I added this to my .zshrc
>
> if [ -d "$ZDOTDIR/functions" ]
> then
> fpath=($ZDOTDIR/functions $fpath)
> fi
>
> The goal there was to add '$ZDOTDIR/functions' to the functions list,
> which I think is the right way to do this.
>
> I can verify that works, I think, by using 'echo $fpath':
>
> $ echo $fpath
> /Users/luomat/Dropbox/dotfiles/zsh/completion
> /Users/luomat/Dropbox/dotfiles/zsh/functions
> /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions
> /usr/share/zsh/5.3/functions
>
> /Users/luomat/Dropbox/dotfiles is my $ZDOTDIR
>
> The first file in '/Users/luomat/Dropbox/dotfiles/zsh/functions' is called
> 'msg'. For simplicity's sake, let's assume the contents of 'msg' is simply
> this:
>
> function msg  {
>
>   echo "$@"
>
> }
>
> (It's actually more complicated than that, but that's the overall idea.)
>
> I tried that, and then I tried
>
> autoload msg
>
> and I didn't get an error, but when I check 'which msg' I get this:
>
> msg () {
> # undefined
> builtin autoload -X
> }
>
> so I've messed up something along the line.
>
> Any help would be appreciated.
>
> Thanks!
>
> Tj
>
>
> --
> TJ Luoma
> TJ @ MacStories <http://www.macstories.net/author/tjluoma/>
> Personal Website: luo.ma <http://luo.ma/> (aka RhymesWithDiploma.com
> <http://rhymeswithdiploma.com/>)
> Twitter: @tjluoma <http://twitter.com/tjluoma>
>
>

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

* Re: separating functions, fpath, and autoload
  2018-08-13 13:49 separating functions, fpath, and autoload TJ Luoma
  2018-08-13 13:55 ` TJ Luoma
@ 2018-08-13 13:56 ` Pier Paolo Grassi
  2018-08-13 14:31   ` Daniel Shahaf
  1 sibling, 1 reply; 12+ messages in thread
From: Pier Paolo Grassi @ 2018-08-13 13:56 UTC (permalink / raw)
  To: TJ Luoma; +Cc: Zsh-Users List

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

that should be correct, the autoload will be executed when you first invoke
msg, have you tried invoking it?
Il giorno lun 13 ago 2018 alle 15:50 TJ Luoma <luomat@gmail.com> ha scritto:

> I'm in the midst of an effort to try to learn some of zsh's more powerful
> features, since I've been using zsh forever and feel like I only use 1% of
> what it can do.
>
> One of the things that I've wanted to do for awhile is separate out some of
> my more complex functions to remove them from my .zshrc file and put them
> into their own files. This should make them easier to track/change/etc and
> it makes things a lot easier to read and debug.
>
> Unfortunately, I can't seem to get it to work right. I'm sure I'm doing
> something wrong because I don't really know what I'm doing, so I'll explain
> what I've tried, and hopefully someone can explain where I've gone wrong.
>
> I added this to my .zshrc
>
> if [ -d "$ZDOTDIR/functions" ]
> then
> fpath=($ZDOTDIR/functions $fpath)
> fi
>
> The goal there was to add '$ZDOTDIR/functions' to the functions list, which
> I think is the right way to do this.
>
> I can verify that works, I think, by using 'echo $fpath':
>
> $ echo $fpath
> /Users/luomat/Dropbox/dotfiles/zsh/completion
> /Users/luomat/Dropbox/dotfiles/zsh/functions
> /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions
> /usr/share/zsh/5.3/functions
>
> /Users/luomat/Dropbox/dotfiles is my $ZDOTDIR
>
> The first file in '/Users/luomat/Dropbox/dotfiles/zsh/functions' is called
> 'msg'. For simplicity's sake, let's assume the contents of 'msg' is simply
> this:
>
> function msg  {
>
>   echo "$@"
>
> }
>
> (It's actually more complicated than that, but that's the overall idea.)
>
> I tried that, and then I tried
>
> autoload msg
>
> and I didn't get an error, but when I check 'which msg' I get this:
>
> msg () {
> # undefined
> builtin autoload -X
> }
>
> so I've messed up something along the line.
>
> Any help would be appreciated.
>
> Thanks!
>
> Tj
>
>
> --
> TJ Luoma
> TJ @ MacStories <http://www.macstories.net/author/tjluoma/>
> Personal Website: luo.ma <http://luo.ma/> (aka RhymesWithDiploma.com
> <http://rhymeswithdiploma.com/>)
> Twitter: @tjluoma <http://twitter.com/tjluoma>
>
-- 
Pier Paolo Grassi

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

* Re: separating functions, fpath, and autoload
  2018-08-13 13:56 ` Pier Paolo Grassi
@ 2018-08-13 14:31   ` Daniel Shahaf
  2018-08-13 15:38     ` ticking clock Ray Andrews
  0 siblings, 1 reply; 12+ messages in thread
From: Daniel Shahaf @ 2018-08-13 14:31 UTC (permalink / raw)
  To: Pier Paolo Grassi, TJ Luoma; +Cc: Zsh-Users List

In more words:

'autoload foo' marks 'foo' as the name of a function that will be
instantiated upon the first call to it.  After calling foo, you'll
see the actual definition of foo: 'autoload foo; foo; which foo'.
You can pass +X to 'autoload' to load the function immediately
(before it's called).

More below.

Pier Paolo Grassi wrote on Mon, 13 Aug 2018 15:56 +0200:
> that should be correct, the autoload will be executed when you first invoke
> msg, have you tried invoking it?
> Il giorno lun 13 ago 2018 alle 15:50 TJ Luoma <luomat@gmail.com> ha scritto:
> > if [ -d "$ZDOTDIR/functions" ]
> > then
> > fpath=($ZDOTDIR/functions $fpath)

Another way:

fpath=( $ZDOTDIR/functions(N) $fpath )

or even

fpath[1,0]=( $ZDOTDIR/functions(N) )

then you don't need an if.


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

* ticking clock
  2018-08-13 14:31   ` Daniel Shahaf
@ 2018-08-13 15:38     ` Ray Andrews
  2018-08-13 16:29       ` Vin Shelton
  2018-08-14 10:07       ` Sebastian Gniazdowski
  0 siblings, 2 replies; 12+ messages in thread
From: Ray Andrews @ 2018-08-13 15:38 UTC (permalink / raw)
  To: zsh-users

I did this in zshrc:

     ## 2018-08-10: ticking clock:
     #RPS1=$'%t %w'
     RPS1='%B%F{yellow}[%D{%L:%M:%S}]%f %w'
     TMOUT=1
     TRAPALRM() { zle reset-prompt }

Nice to have the time ticking away there, but it kills back-scrolling -- 
I scroll up, but every tick moves back to the bottom.  Fixable?


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

* Re: ticking clock
  2018-08-13 15:38     ` ticking clock Ray Andrews
@ 2018-08-13 16:29       ` Vin Shelton
  2018-08-13 19:57         ` Ray Andrews
  2018-08-14 10:07       ` Sebastian Gniazdowski
  1 sibling, 1 reply; 12+ messages in thread
From: Vin Shelton @ 2018-08-13 16:29 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

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

Hi, Ray -

You could turn off your terminal emulator's scroll to the bottom on output
option.

I think a better solution would be to change your clock
(conky,taskbar/tasklet or whatever) to have resolution down to the second.

  - Vin

On Mon, Aug 13, 2018 at 11:38 AM, Ray Andrews <rayandrews@eastlink.ca>
wrote:

> I did this in zshrc:
>
>     ## 2018-08-10: ticking clock:
>     #RPS1=$'%t %w'
>     RPS1='%B%F{yellow}[%D{%L:%M:%S}]%f %w'
>     TMOUT=1
>     TRAPALRM() { zle reset-prompt }
>
> Nice to have the time ticking away there, but it kills back-scrolling -- I
> scroll up, but every tick moves back to the bottom.  Fixable?
>
>

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

* Re: ticking clock
  2018-08-13 16:29       ` Vin Shelton
@ 2018-08-13 19:57         ` Ray Andrews
  2018-08-13 21:54           ` Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Ray Andrews @ 2018-08-13 19:57 UTC (permalink / raw)
  To: zsh-users

On 13/08/18 09:29 AM, Vin Shelton wrote:
> Hi, Ray -
>
> You could turn off your terminal emulator's scroll to the bottom on output
> option.

That works.  But of course usually I do want it to  scroll, just not 
when the clock ticks.  Dunno, maybe zsh has some sort of 'only tick when 
visible' sort of thing.

>
> I think a better solution would be to change your clock
> (conky,taskbar/tasklet or whatever) to have resolution down to the second.

I've got the desktop's clock up there on the menu bar, but it is nice to 
have one on the command line too.  Not hardly important, but worth 
asking about.

Thanks Vin.


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

* Re: ticking clock
  2018-08-13 19:57         ` Ray Andrews
@ 2018-08-13 21:54           ` Bart Schaefer
  2018-08-13 22:45             ` Ray Andrews
  0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2018-08-13 21:54 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Mon, Aug 13, 2018 at 12:57 PM, Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> I've got the desktop's clock up there on the menu bar, but it is nice to
> have one on the command line too.

I do that by putting the ticking clock in the terminal emulator title
bar instead of in the prompt.

I also use a premcd to start the ticking, and initially set a longer
TMOUT so that it usually ticks only when I'm not actively editing the
buffer (I figure if I'm actively entering commands, having it update
after each command is often enough).


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

* Re: ticking clock
  2018-08-13 21:54           ` Bart Schaefer
@ 2018-08-13 22:45             ` Ray Andrews
  2018-08-14 17:27               ` Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Ray Andrews @ 2018-08-13 22:45 UTC (permalink / raw)
  To: zsh-users

On 13/08/18 02:54 PM, Bart Schaefer wrote:

> I also use a premcd to start the ticking, and initially set a longer
> TMOUT so that it usually ticks only when I'm not actively editing the
> buffer (I figure if I'm actively entering commands, having it update
> after each command is often enough).
So no way to have it tick only when it's idle, and never force a 
scroll?  I can see that forcing the prompt to rewrite is normally an 
'event' so it would naturally force a scroll, so this is probably 
'unnatural' in a way, but it sounds like it could be doable.  This is 
small potatoes tho, hardly any sort of issue.
>


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

* Re: ticking clock
  2018-08-13 15:38     ` ticking clock Ray Andrews
  2018-08-13 16:29       ` Vin Shelton
@ 2018-08-14 10:07       ` Sebastian Gniazdowski
  1 sibling, 0 replies; 12+ messages in thread
From: Sebastian Gniazdowski @ 2018-08-14 10:07 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Mon, 13 Aug 2018 at 18:09, Ray Andrews <rayandrews@eastlink.ca> wrote:
> I did this in zshrc:
>
>      ## 2018-08-10: ticking clock:
>      #RPS1=$'%t %w'
>      RPS1='%B%F{yellow}[%D{%L:%M:%S}]%f %w'
>      TMOUT=1
>      TRAPALRM() { zle reset-prompt }
>
> Nice to have the time ticking away there, but it kills back-scrolling --
> I scroll up, but every tick moves back to the bottom.  Fixable?

Maybe the terminal emulator has configuration option to not scroll
down on view-update? Turning it on is useful in general, allows to
e.g. scroll up and read ./configure log while it's still processing.

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin


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

* Re: ticking clock
  2018-08-13 22:45             ` Ray Andrews
@ 2018-08-14 17:27               ` Bart Schaefer
  2018-08-14 21:21                 ` Ray Andrews
  0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2018-08-14 17:27 UTC (permalink / raw)
  To: Zsh Users

On Mon, Aug 13, 2018 at 3:45 PM, Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> So no way to have it tick only when it's idle, and never force a scroll?

The terminal emulator doesn't "inform" the shell when you scroll back,
so there's no way for the shell to know that it should stop sending
output.

Some emulators have "scroll to bottom on tty input" as well as (or
instead of) "on tty output" -- if possible with your emulator, you
could try enabling only the former.


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

* Re: ticking clock
  2018-08-14 17:27               ` Bart Schaefer
@ 2018-08-14 21:21                 ` Ray Andrews
  0 siblings, 0 replies; 12+ messages in thread
From: Ray Andrews @ 2018-08-14 21:21 UTC (permalink / raw)
  To: zsh-users

On 14/08/18 10:27 AM, Bart Schaefer wrote:
> On Mon, Aug 13, 2018 at 3:45 PM, Ray Andrews <rayandrews@eastlink.ca> wrote:
>> So no way to have it tick only when it's idle, and never force a scroll?
> The terminal emulator doesn't "inform" the shell when you scroll back,
> so there's no way for the shell to know that it should stop sending
> output.
Right , so the prompt doesn't even know if it's visible.  And I can see 
that it's no small thing for the shell to try to convince the terminal 
not to detect that it's been written to in some particular situation.
> Some emulators have "scroll to bottom on tty input" as well as (or
> instead of) "on tty output" -- if possible with your emulator, you
> could try enabling only the former.

Sure.  There's little practical difficulty, I'm mostly interested in the 
theory of the thing.  Thanks Bart.


>


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

end of thread, other threads:[~2018-08-14 21:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-13 13:49 separating functions, fpath, and autoload TJ Luoma
2018-08-13 13:55 ` TJ Luoma
2018-08-13 13:56 ` Pier Paolo Grassi
2018-08-13 14:31   ` Daniel Shahaf
2018-08-13 15:38     ` ticking clock Ray Andrews
2018-08-13 16:29       ` Vin Shelton
2018-08-13 19:57         ` Ray Andrews
2018-08-13 21:54           ` Bart Schaefer
2018-08-13 22:45             ` Ray Andrews
2018-08-14 17:27               ` Bart Schaefer
2018-08-14 21:21                 ` Ray Andrews
2018-08-14 10:07       ` Sebastian Gniazdowski

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).