this post was submitted on 18 Jul 2024
267 points (98.5% liked)

Programmer Humor

19149 readers
1218 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
267
Which one??? (programming.dev)
submitted 1 month ago* (last edited 1 month ago) by JackbyDev@programming.dev to c/programmer_humor@programming.dev
 

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
you are viewing a single comment's thread
view the rest of the comments
[–] korthrun@lemmy.sdf.org 35 points 1 month ago* (last edited 1 month ago) (5 children)

It's all about context. If you write a convenience function and put it in zshrc, scripts you run from the cli will not have access to the function as defined in zshrc. Same with aliases added by zsh plugins etc.

If you need "the thing" on the command line, zshrc. If you also need it in scripts you run from the cli, toss it in the profile file.

ETA: I personally keep the functions I want to access from scripts in .zshenv as I recall reading that this file is ALWAYS sourced.

[–] gamma@programming.dev 2 points 1 month ago (4 children)

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 2 points 1 month ago* (last edited 1 month ago) (2 children)

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.

[–] gamma@programming.dev 1 points 1 month ago* (last edited 1 month 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.

load more comments (1 replies)
load more comments (2 replies)
load more comments (2 replies)