Fuck it, .zshrc it is.

Image transcription:

  • Top text: I STILL DON’T KNOW WHAT SHOULD GO IN .*RC VERSUS .*PROFILE
  • Bottom text: AND AT THIS POINT I’M AFRAID TO ASK
  • Gamma@programming.dev
    link
    fedilink
    English
    arrow-up
    2
    ·
    4 months ago

    What kind of functions do you write which you share between your scripts? Generally if I’m wanting to reuse a non-trivial function, I extend the functionality of the first script instead.

    • Korthrun@lemmy.sdf.org
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      4 months ago

      All of the repos for my GitHub sourced vim plugins live under one parent directory. I symlink to them from ~/.vim

      One example is a simple function that pushes the top level repo directory onto my dir stack and then runs a loop where it pushes each subdir into the stack, runs “ggpull” then pops back to the top level repo directory. ggpull is an alias added by the zsh git plugin. After all repos have been updated it pops back to my original pwd.

      I run this as part of my “update all the things” script but sometimes I also want to run it in demand from the cli. So I want this function in all scopes and I want it to have access to “ggpull” in all of those scopes.

      • Korthrun@lemmy.sdf.org
        link
        fedilink
        arrow-up
        2
        ·
        4 months ago

        I also “misuse” timewarrior a bit and use it to time things like “how much time do I spend waiting for salt to run”. That has its own timewarrior db and a wrapper function for pointing the command at said db. I use this in both login and non login shell contexts.

      • Gamma@programming.dev
        link
        fedilink
        English
        arrow-up
        2
        arrow-down
        1
        ·
        edit-2
        4 months ago

        Yeah, I’d write this as a single update script with options to update vimplugins or update pkg or update all.

        I see that you want it to be a function so you can get the chdir as a side effect, but mixing that with updating doesn’t make sense to me.

    • stetech@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      3 months ago

      zshenv’s selling point isn’t necessarily that your typical functions are available across scripts (though that can be neat, too – I source aliasrc as well as an utils script file in my shell config) – it’s that it’s there for non-interactive shells too, whereas zprofile is only applied for login shells (and zshrc only for interactive ones).

      So for example, I could open a command in my editor of choice (Helix’s :sh for me), and if I define stuff using the zshenv, all of my aliases etc. are right there. I just have to avoid naming conflicts for script function names if it’s the default shell, but that’s pretty easily done.