You are not logged in.
Hi, I didn't see a 'general linux stuff' forum, so I'm posting here, hope you don't mind
I'd like a break down of the purpose of env variables, specifically when you should create your own.
Case in point: My prompt is getting a wee bit heavy (calling both ibam and acpi everytime the prompt is written).
So I figured: I'll have separate processes call these binaries and save the results somewhere.
Then my shell only needs to read those values, not call the binaries to produce them.
env variables was my first thought, and I'm convinced it is would be a simple and clean sollution, but I'm uncertain whether it might conflict with some unspoken purpose or guideline for env vars?
(I'm not completely sure how much more efficient it is, rewriting the zsh/bash function might be better, but bash/zsh Isn't my strongest, and it should provide some improvement.)
Last edited by Bladtman242 (2012-03-19 21:56:53)
Offline
Case in point: My prompt is getting a wee bit heavy
How much is 'heavy'? Mind posting it?
https://wiki.archlinux.org/index.php/En … _Variables
If you want to monitor things like battery, why not use something like dzen?
Last edited by wolfcore (2012-03-19 19:20:16)
Offline
Just a suggestion, maybe what you're looking for is already exposed in the /proc or /sys hierarchy.
Offline
Wolfcore: of course, here it is: http://paste.pocoo.org/show/568176/
Well, I could use a widget, but I'd much rather make one. (Besides, while I really do appreciate ALL the help and advice I can get, I still want to know about env vars)
I'll definitely have a look at dzen though.
I read the wiki page you linked to, but it didn't quite provide the answer I was looking for.
When should a sysadmin/desktop user create his own env vars, and when should a programmer have a program make them?
KLazimir: Would you elaborate a little?
I'm not all that familiar with /proc (I actually thought it was deprecated).
EDIT: wrong link, still getting used to this hole "secondary and primary" buffer thingy
Last edited by Bladtman242 (2012-03-19 20:26:10)
Offline
I'd put the tmux stuff in .profile as you only need it when you login, not every time you launch a shell and the keybinds can be done in .inputrc
As for the battery stuff, you could have a script run in a loop and write to a file and then query the file from your PS1 - but if it is getting elaborate, I'd write it to a separate bar (like dzen as wolfcore suggested, or conky on your desktop -- depending what sort of DE/WM setup you have).
Offline
The tmux part is commented out, as I don't use it right now and I don't have a .profile file?
I'm actually okay with the shell, the only speed problem is with the RPROMPT, which is reloaded everytime the prompt is displayed.
I know widgets can do this stuff, but what I'd like to know is whether or not it is against convention to use environmental variables for this sort of thing.
What are their purpose, what need are they supposed to fulfil, for both admins, users, and programmers?
Offline
.profile could be .bash_profile (or whatever shell you decide to use)...
I think you are answering your own question (at least in terms of practical application): if the speed is an issue, move it out of the prompt.
In terms of a design perspective, as I understand it, the environmental variables are set for the session and will apply to all the shells in that session. There is no theoretical reason why you can't jam battery info into your PS1 -- to me, though, it doesn't seem very UNIXy (one thing well, etc). YMMV.
Offline
Wolfcore: of course, here it is: http://paste.pocoo.org/show/568176/
Well, I could use a widget, but I'd much rather make one. (Besides, while I really do appreciate ALL the help and advice I can get, I still want to know about env vars)
I'll definitely have a look at dzen though.
Well, I'd say if you want to do-it-yourself, using what you've written to show battery info in your PS1 is really the same or close to it if you put it in Conky/Dzen.
Also (and as a separate point), you can put the battery stuff in a separate script and stick it in your crontab, making it run every 5 minutes for example, then save the output to a file or to an environmental variable and read from there. (instead of rerunning everytime your PS1 re-evals).
Offline
Thank you all very much, but I know how this can be done, I am simply not familiar with the philosophy of env vars. Is it bad form to fill stuff like this in there?
wolfcore: Thats exactly what I was thinking, except I'd have acpid set the "ac-adapter-plugged-in" variable, as to only run it when needed
Jasonwryab:I'm not sure I agree that its un-UNIXy.
Having a program do one thing, and one thing well, can include providing an overview. Which, in this case, for me, involves a battery indicator. The whole idea is that if we program does one thing well, other programs can use it, instead of having to do everything themselves.
It doesn't mean that one program can do only one thing, it means it should achieve one goal. Otherwise UNIX programmers could do nothing: Want to sort an array? Too bad, you said you program should be a battery applet. So what if we to make a nice graph of battery statistics? Leave it for another program? Well, you could have your program use gnuplot.
Thats how I think of it anyway
Anyway, to get back on topic, no matter if I want it in the prompt or not. The question is where to keep the values, if I want them accessible
Last edited by Bladtman242 (2012-03-19 21:26:54)
Offline
There isn't a science/philosophy to environmental variables... just use them if you want to. Nothing is holding you back. They're used when you need to access the same variables from multiple places/applications... but it's not written in stone...
I'd say keeping your vars stored as environmentals is fine, just watch out you do not conflict with existing vars, and also (as an aside), as jasonwryan pointed out, you can move some of the things you're keeping in your .bashrc to your .bash_profile/.profile (which is only used at login).
Offline
Thanks
I confess I didn't quite catch the .profile thing earlier. (I searched for it in my home dir, but didn't find it)
I havent created a .zprofile file, but im guessing /etc/ for globals and ~/ for user specific?
(Using zsh as the login shell btw).
Could I put everything but the prompts in there? like aliases, keybindings, and zsh settings?
Last edited by Bladtman242 (2012-03-19 21:35:44)
Offline
Thanks
I confess I didn't quite catch the .profile thing earlier. (I searched for it in my home dir, but didn't find it)I havent created a .zprofile file, but im guessing /etc/ for globals and ~/ for user specific?
(Using zsh as the login shell btw).Could I put everything but the prompts in there? like aliases, keybindings, and zsh settings?
Use ~/.bash_profile for things that apply to your whole session, including environmental variables.
Use ~/.bashrc for aliases, function definitions, shell options, and prompt settings.
key bindings normally go in ~/.inputrc
Also, if I'm not mistaken, there's a sample ~/.bash_profile, ~/.bashrc, etc in /etc/skel/
Offline
There is, I didn't know that.
Thanks again. marking thread as solved.
Offline