The prompt escape sequence %~
(included in $current_dir
) expands to the current directory, taking abbreviations into account. The abbreviations are:
~
for your home directory;
~joe
for the home directory of user joe
;
~foo
for a named directory: the directory aliased to foo
with hash -d foo=…
;
~[bar]
for a dynamic named directory.
You can use %/
instead of %~
. This never uses any directory abbreviation.
If you want to be fancier, you can execute your own code to determine how the current directory is displayed. One approach is to use a parameter substitution inside the prompt string. This requires the prompt_subst
option to be set, which oh-my-zsh does (otherwise: setopt prompt_subst
). The current directory is always available in the parameter PWD
. Here's a simple version that only shortens your home directory to ~
:
local current_dir='%{$terminfo[bold]$fg[cyan]%} ${${PWD/#%$HOME/~}/#$HOME\//~/}%{$reset_color%}'
${${PWD/#%$HOME/\~}/#$HOME\//\~/}
means: if $PWD
is exactly the same as $HOME
, then set the result to ~
, otherwise set the result to $PWD
; then, if the current result begins with $HOME/
, then replace this prefix by ~/
, otherwise leave the result unchanged.
A clearer approach is to maintain a parameter containing a pretty-printed version of the current directory. Update this parameter in the chpwd
hook function which is executed on every current directory change. Also initialize that parameter in your .zshrc
.
There's only one chpwd
function, so don't override oh-my-zsh's. Oh-my-zsh's chpwd
calls the function in the array chpwd_functions
, so add yours to the array.
function my_update_pretty_PWD {
case $PWD in
$HOME(/*)#) pretty_PWD=\~${PWD#$HOME};;
*) pretty_PWD=$PWD;;
esac
}
chpwd_functions+=(my_update_pretty_PWD)
my_update_pretty_PWD
local current_dir='%{$terminfo[bold]$fg[cyan]%} ${pretty_PWD}%{$reset_color%}'
If you want to abbreviate users' home directories but not named directories, you can clear the home directories in a subshell and use the %
parameter expansion flag to perform the automatic abbreviations in the subshell.
function my_update_pretty_PWD {
pretty_PWD=$(hash -rd; print -lr -- ${(%)PWD})
}
Or if you prefer the inline approach:
local current_dir='%{$terminfo[bold]$fg[cyan]%} $(hash -rd; print -lr -- ${(%)PWD})%{$reset_color%}'
Thats three questions in one ;-)
AUTO_CD Option and howto find it
First of all the option you are looking for is AUTO_CD.
You can easily find it by looking up man zshoptions
. Use your pagers search function, usually you press / and enter the keyword. With n you jump to the next occurrence. This will bring up the following:
[..]
Changing Directories
AUTO_CD (-J)
If a command is issued that can't be executed as a normal command, and the command is the name of a directory, perform the cd command to that directory.
[..]
The option can be unset using unsetopt AUTO_CD
.
Turning it properly off
You are using oh-my-zsh which is described as
"A community-driven framework for managing your zsh configuration"
Includes 120+ optional plugins (rails, git, OSX, hub, capistrano, brew, ant, macports, etc), ...
So the next thing is to find out, how to enable/disable options according to the framework.
The readme.textile file states that the prefered way to enable/disable plugins would be an entry in your .zshrc: plugins=(git osx ruby)
Find out which plugin uses the AUTO_CD option. As discovered from the manpage it can be invoked via the -J switch or AUTO_CD. Since oh-my-zsh is available on github, searching for it will turn up the file lib/theme-and-appearance.zsh
.
If you don't want to disable the whole plugin "theme-and-appearance", put a unsetopt AUTO_CD
in your .zshrc. Don't modify the files of oh-my-zsh directly, because in case you are updating the framework, your changes will be lost.
Why executables are not invoked directly
Your third question is howto execute a binary directly:
You have to execute your binary file via a path, for example with a prefixed ./
as in ./do-something
. This is some kind of a security feature and should not be changed.
hing of plugging in an USB stick, mounting it and having a look on it with ls
. If there is a executable called ls
which deletes your home directory, everything would be gone, since this would have overwritten the order of your $PATH.
If you have commands you call repeatedly, setting up an alias in your .zshrc would be a common solution.
Best Answer
If you don't want any of oh-my-zsh's aliases, but you want to keep other aliases, you can save the aliases before loading oh-my-zsh
and restore them afterwards.
If you want to remove all aliases at some point, you can use
unalias -m '*'
(remove all aliases matching*
, i.e. all of them).If you absolutely hate aliases and don't want to ever see one, you can make the
alias
builtin inoperative:unalias -m '*'; alias () { : }
. Or you can simply turn off alias expansion withsetopt no_aliases
.