This is my .zprofile, it recently got nuked so I remade it. I made it clearer and better then my previous .zprofile and then I heard about this site so I want to know how can I improve this code.
# Setting PATH for Python 3.11
export PATH="/Library/Frameworks/Python.framework/Versions/3.11/bin:$PATH"
alias python=python3
export PYTHONPATH="/Users/jfami/Desktop:/Users/jfami/Desktop.noml:$PYTHONPATH"
# Setting PATH for Demonal
export PATH="/Users/jfami/Library/Demonal/bin:$PATH"
# Setting PATH for Sublime Text
export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"
# Moving to a better directory
cd Desktop
# Aliases!
alias noml="python ~/Desktop/noml/app.py"
alias deppy="python ~/Desktop/deppy.py"
alias pylect="python ~/pylect/pylect-env/.pylect.py"
# ENV variables
export MYSQL_PASSWORD=$(cat MYSQL_PASSWORD)
# Configuration
termdx tebwhite > /dev/null 2>&1
termdx tefblack > /dev/null 2>&1
deppy cache-clear
demonal project select playground
# Print the art
echo -e "\e[0;35m<------------------------------------> \e[0m"
echo -e "\e[0;35mThe Terminal \e[0m"
echo -e "\e[0;35m<------------------------------------> \e[0m"
echo -e "\e[0;33mOS: $(uname)\e[0m"
echo -e "\e[0;36mUsername: $(whoami)\e[0m"
echo -e "\e[0;32mBrowser: $('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' --version)\e[0m"
-
\$\begingroup\$ Putting your dotfiles on GitHub helps against nuking them. \$\endgroup\$ggorlen– ggorlen2023年10月21日 17:57:45 +00:00Commented Oct 21, 2023 at 17:57
2 Answers 2
Do you really want all Python programs to look first in these directories?
export PYTHONPATH="/Users/jfami/Desktop:/Users/jfami/Desktop.noml:$PYTHONPATH"
It might be appropriate to create very small shell scripts (which set the environment and exec the Python interpreter) for the few Python programs that actually use that path, and put them in $HOME/bin (or some other suitable place on your $PATH).
Don't do this:
export MYSQL_PASSWORD=$(cat MYSQL_PASSWORD)
That's exposing your password in the environment variables of every process you run from this shell. It's all too easy to leak that information to untrusted programs or other users.
You might think you only ever log in from one kind of terminal, but one day you'll find these hard-coded escape sequences a nuisance:
echo -e "\e[0;35m<------------------------------------> \e[0m"
Instead, use tput to generate the correct codes for your actual $TERM if they exist.
-
\$\begingroup\$ 1. It won't be that much of a performance hog and a lot of scripts could use them which I don't always want in $HOME/bin. 2. So I shouldn't export it but should still assign it? 3. Thanks. \$\endgroup\$192927376337929292283737373773– 1929273763379292922837373737732023年10月12日 12:43:14 +00:00Commented Oct 12, 2023 at 12:43
-
4\$\begingroup\$ I'm with Toby on all counts.
Desktopis not designed for keeping programs and libraries. It's a security risk to have passwords in variables in interactive shells. A better alternative is to store in.my.cnfwith restricted permissions. \$\endgroup\$janos– janos2023年10月12日 14:09:49 +00:00Commented Oct 12, 2023 at 14:09 -
1\$\begingroup\$ @The_AH, I was thinking first of correctness, rather than performance. Since you put those
/Users/...directories ahead of others, they may be picked up in preference to newer versions of the same modules later in the path. It's not wrong to do what you're doing, as long as you're fully aware of the implications. \$\endgroup\$Toby Speight– Toby Speight2023年10月12日 15:55:06 +00:00Commented Oct 12, 2023 at 15:55 -
\$\begingroup\$ @TobySpeight Interesting, I never do that but thanks anyways. \$\endgroup\$192927376337929292283737373773– 1929273763379292922837373737732023年10月12日 15:58:57 +00:00Commented Oct 12, 2023 at 15:58
Looks pretty good.
- If
/Users/jfamibecomes$HOME, you can use it on other boxes and other users can use it too. - You probably also want to set your
MANPATH, and possiblyINFOPATH. On the other hand, maybe you always look up the documentation online, and that’s just old-fashioned of me. - If your system doesn’t by default, you might want to enable colors in
ls, which on many distributions is the command given bydircolors --sh. - Some of these commands might be better for
.zshenvor.zshrc, particularly the aliases, which I don’t believe would get inherited otherwise. - If you often log in remotely, you might want to override your
LANG,LC_ALLorTZ, although your terminal program likely has an option to set these.
Your profile is also very close to Bourne Shell syntax, which would work under any shell if you renamed .zprofile to .profile. The only significant change you would need is to break up your EXPORT commands into two parts:
PATH="/Library/Frameworks/Python.framework/Versions/3.11/bin:$PATH"; export PATH
-
1\$\begingroup\$ Why set
MANPATH, and to what? I definitely consume docs primarily throughman, and never had to tune this. \$\endgroup\$janos– janos2023年10月12日 14:03:40 +00:00Commented Oct 12, 2023 at 14:03 -
2\$\begingroup\$ As far as I know
export foo=baris totally legit in Bash, is it not? \$\endgroup\$janos– janos2023年10月12日 14:04:30 +00:00Commented Oct 12, 2023 at 14:04 -
1\$\begingroup\$ @janos
bashis the Bourne Again Shell, which extends the syntax ofsh. Other shells extend it in incompatible ways. For instance,cshandtcshboth usesetenvrather thanexport. \$\endgroup\$Davislor– Davislor2023年10月12日 19:21:04 +00:00Commented Oct 12, 2023 at 19:21 -
2\$\begingroup\$ @janos So, yes,
export FOO=/bar/bazis also legal in a.bash_profile, but would not work on all shells. \$\endgroup\$Davislor– Davislor2023年10月12日 19:35:15 +00:00Commented Oct 12, 2023 at 19:35 -
1\$\begingroup\$ @janos Many packages that you install will have a directory with their own
manpages (typically with names likepydoc3.11.1.gzorpydoc3.11.1forman -s 1 pydoc3.11). It’s often namedman, under the same directory asbin. You would add this to the beginning ofMANPATHthe same way that you add thebindirectory toPATH. \$\endgroup\$Davislor– Davislor2023年10月12日 19:42:41 +00:00Commented Oct 12, 2023 at 19:42