9
\$\begingroup\$

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"
\$\endgroup\$
1
  • \$\begingroup\$ Putting your dotfiles on GitHub helps against nuking them. \$\endgroup\$
    – ggorlen
    Commented Oct 21, 2023 at 17:57

2 Answers 2

10
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\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\$
    – The_AH
    Commented Oct 12, 2023 at 12:43
  • 4
    \$\begingroup\$ I'm with Toby on all counts. Desktop is 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.cnf with restricted permissions. \$\endgroup\$
    – janos
    Commented 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\$ Commented Oct 12, 2023 at 15:55
  • \$\begingroup\$ @TobySpeight Interesting, I never do that but thanks anyways. \$\endgroup\$
    – The_AH
    Commented Oct 12, 2023 at 15:58
5
\$\begingroup\$

Looks pretty good.

  • If /Users/jfami becomes $HOME, you can use it on other boxes and other users can use it too.
  • You probably also want to set your MANPATH, and possibly INFOPATH. 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 by dircolors --sh.
  • Some of these commands might be better for .zshenv or .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_ALL or TZ, 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
\$\endgroup\$
10
  • 1
    \$\begingroup\$ Why set MANPATH, and to what? I definitely consume docs primarily through man, and never had to tune this. \$\endgroup\$
    – janos
    Commented Oct 12, 2023 at 14:03
  • 2
    \$\begingroup\$ As far as I know export foo=bar is totally legit in Bash, is it not? \$\endgroup\$
    – janos
    Commented Oct 12, 2023 at 14:04
  • 1
    \$\begingroup\$ @janos bash is the Bourne Again Shell, which extends the syntax of sh. Other shells extend it in incompatible ways. For instance, csh and tcsh both use setenv rather than export. \$\endgroup\$
    – Davislor
    Commented Oct 12, 2023 at 19:21
  • 2
    \$\begingroup\$ @janos So, yes, export FOO=/bar/baz is also legal in a .bash_profile, but would not work on all shells. \$\endgroup\$
    – Davislor
    Commented Oct 12, 2023 at 19:35
  • 1
    \$\begingroup\$ @janos Many packages that you install will have a directory with their own man pages (typically with names like pydoc3.11.1.gz or pydoc3.11.1 for man -s 1 pydoc3.11). It’s often named man, under the same directory as bin. You would add this to the beginning of MANPATH the same way that you add the bin directory to PATH. \$\endgroup\$
    – Davislor
    Commented Oct 12, 2023 at 19:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.