Using z in zsh, I want to change the default location of where the history is kept.
By default, when your source the shell script
source ~/z/z.sh
It will make a file with the directories you visit in a .z/ directory. While this is fine for most cases, I want to change this to another directory. The README.md does state that you can set some variables for this in my .zshrc
Optionally:
Set $_Z_DATA to change the datafile (default $HOME/.z).
So I added this
export $_Z_DATA="$HOME/.z-history"
But for some reason, I get a warning that my shell can't find the directory.
Any idea why this is happening? Any help is appreciated.
You are having a typo, or haven't yet get how the bash variable works.
You do not need to use $ when declaring a variable. Only when you want to access it.
So just adapt you config with:
export _Z_DATA="$HOME/.z-history"
voilĂ :) it should works
Related
As I understand, if you create an alias for a directory in your .zshrc file, that directory is now considered a "named directory". I could be mistaken there, so let me know.
Based on the documentation here, it sounds like if you use "%~" in your zsh prompt and the current working directory is a named directory, then the prompt should show the alias for the directory, rather than the full path (i.e. ~{alias}). This does not seem to be working for me currently and I'm having a hard time finding examples or posts regarding this.
In my .zshrc file I have an alias like repo = "~/src/apps/repo". My hope is that when I am in that directory, the zsh prompt would show ~repo, but it always shows the full thing.
Any help is greatly appreciated!
In zsh, you can add a named directory with hash -d repo=~/src/apps/repo (not an alias). Also, ~ isn't expanded inside quotes, so you should remove them or use $HOME instead.
hash usage: https://zsh.sourceforge.io/Doc/Release/Shell-Builtin-Commands.html#index-hash-1
Static named directories: https://zsh.sourceforge.io/Doc/Release/Expansion.html#Static-named-directories
So I wanted to install MySQL on my MBP and I edited my bash_profile, added a path variable, however when I run echo $PATH from iTerm2 I get my path as:
Robs-MBP:~ Rob$ echo $PATH
/usr/local/mysql/bin
Ive tried a lot of commands and even used sudo and it just says command not found. My fear is that I have completely messed up, and now nothing works. Please help.
You've made a simple mistake: all you've done is reset the PATH env variable. To correctly do this, you should always add the existing PATH to the end of whatever you're adding. In you case:
PATH=/usr/local/mysql/bin:$PATH
To fix your problem from the terminal, you'll need to reset your PATH to somewhere with a text editor. I don't know where this is located on OSX, so you'll have to find it. After you know where your path should point, run:
$ export PATH=<YOUR_PATH_HERE>
Then edit your bashrc to include the original path as described above, and restart the terminal.
Alternatively, open .bashrc with a GUI text editor and make the change from there. Your PATH decleration should always end in :$PATH to include the PATH created by your system.
I haven't been able to find the answer to this anywhere and suspect it's not possible. I'd like to know if I can somehow override environment variables set by export MY_VARIABLE="some-value" per directory. Meaning, once I cd into a particular directory where x variable is overridden, anything being run from that directory would see the new value.
Is that possible without expicitly exporting? Perhaps adding some file to the directory like .bashrc or something like that?
Thank you!
I was trying to install Sencha Touch SDK tools 2.0.0 but could not run it properly. It created an entry in the $PATH variable.
Later I deleted the sencha sdk tools folder but didn't realize that the path variable is still there.
When i did echo $PATH I got -
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
I searched on how to remove variables from $PATH and followed these steps :
Gave the command PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
Did echo $PATH which showed /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
gave the command export PATH
Closed terminal and reopened it. Gave the command echo $PATH. This time I got
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Can anyone tell me what am i doing wrong?
echo $PATH and copy it's value
export PATH=""
export PATH="/path/you/want/to/keep"
Check the following files:
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
Some of these files may not exist, but they're the most likely ones to contain $PATH definitions.
On MAC OS X Leopard and higher
cd /etc/paths.d
There may be a text file in the above directory that contains the path you are trying to remove.
vim textfile //check and see what is in it when you are done looking type :q
//:q just quits, no saves
If its the one you want to remove do this
rm textfile //remove it, delete it
Here is a link to a site that has more info on it, even though it illustrates 'adding' the path. However, you may gain some insight.
What you're doing is valid for the current session (limited to the terminal that you're working in). You need to persist those changes. Consider adding commands in steps 1-3 above to your ${HOME}/.bashrc.
If you're removing the path for Python 3 specifically, I found it in ~/.zprofile and ~/.zshrc.
$PATH contains data that is referenced from actual files. Ergo, you should find the file containing the reference you want to delete, and then delete said reference.
Here is a good list to run through progressively [copied from #Ansgar's answer with minor updates].
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
/etc/paths
/etc/paths.d/
Note that /etc/paths.d/ is a directory that contains files with path references. For example, inside this directory may be a file called, say, fancy-app, and inside this file you'll see an entry like below:
/path/to/fancy-app
This path will appear in your $PATH and you can delete the entry in the file to remove it, or you can delete the file if it has only the one reference you want to remove.
Use sudo pico /etc/paths inside the terminal window and change the entries to the one you want to remove, then open a new terminal session.
when you login, or start a bash shell, environment variables are loaded/configured according to .bashrc, or .bash_profile. Whatever export you are doing, it's valid only for current session. so export PATH=/Applications/SenchaSDKTools-2.0.0-beta3:$PATH this command is getting executed each time you are opening a shell, you can override it, but again that's for the current session only. edit the .bashrc file to suite your need. If it's saying permission denied, perhaps the file is write-protected, a link to some other file (many organisations keep a master .bashrc file and gives each user a link of it to their home dir, you can copy the file instead of link and the start adding content to it)
Close the terminal(End the current session). Open it again.
If the manual export $PATH method does not seem to be working after you close the terminal and open again, definitely check the shell configuration files.
I found a small script that kept adding some more path in front of the $PATH everytime it was open.
For zsh you can check the ~/.zshrc file.
For mistake I have added a path that I don't want to use.
I have create a file named .base_profile, exported the path using the command source .base_profile, but I don't need this path, how to delete it?
Maybe the title wasn't so appropriate, but I haven't modified the PATH variable.
I have written this in the .base_profile file:
export MP=$MP/usr/local/mysql/bin
And then used the source command.The problem is with the MP variable, which is not one that I want, it's too long.I want to delete it, how to do it?
The way to restore your path to the default is PATH=$(getconf PATH)
Do an
echo $PATH
Then grab with the mouse that part, which looks useful, and append it to:
PATH=
So for example - not on an OSX-System:
PATH=/home/ramy/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
If you only sourced the path in one terminal, you can, alternatively, open a new terminal.
If you added the source-command to one configuration script, you have to remove it there, to get rid of it permananetly.
Fix your errors in the file, and fix the env var with
export PATH=[the correct one]