When within a git repository, doing a tab-autocomplete on a command results with the command becoming unreadable. The command still works but this is pretty annoying visually. Basically I 1. Navigate to a directory with a git repository in it. The prompt indicates the current branch properly 2. Next, type `git -` and hit tab The prompt now shows only part of branch's name with the first suggestion appended. After googling a bit I stumbled upon several pages describing a similar problem (most useful to me was http://stackoverflow.com/questions/23740862/issues-with-zsh-prompt). The culprit seems to be the git_prompt_info function escaping the `$current_branch` variable as if it is a color. As a result zsh is confused where the cursor is. After "unescaping" the variable everything seems to work fine. Using zsh 5.0.7 (x86_64-apple-darwin13.4.0).
100 lines
2.2 KiB
Bash
100 lines
2.2 KiB
Bash
# modify the prompt to contain git branch name if applicable
|
|
git_prompt_info() {
|
|
current_branch=$(git current-branch 2> /dev/null)
|
|
if [[ -n $current_branch ]]; then
|
|
echo " %{$fg_bold[green]%}$current_branch%{$reset_color%}"
|
|
fi
|
|
}
|
|
setopt promptsubst
|
|
export PS1='${SSH_CONNECTION+"%{$fg_bold[green]%}%n@%m:"}%{$fg_bold[blue]%}%c%{$reset_color%}$(git_prompt_info) %# '
|
|
|
|
# load our own completion functions
|
|
fpath=(~/.zsh/completion $fpath)
|
|
|
|
# completion
|
|
autoload -U compinit
|
|
compinit
|
|
|
|
# load custom executable functions
|
|
for function in ~/.zsh/functions/*; do
|
|
source $function
|
|
done
|
|
|
|
# makes color constants available
|
|
autoload -U colors
|
|
colors
|
|
|
|
# enable colored output from ls, etc
|
|
export CLICOLOR=1
|
|
|
|
# history settings
|
|
setopt hist_ignore_all_dups inc_append_history
|
|
HISTFILE=~/.zhistory
|
|
HISTSIZE=4096
|
|
SAVEHIST=4096
|
|
|
|
# awesome cd movements from zshkit
|
|
setopt autocd autopushd pushdminus pushdsilent pushdtohome cdablevars
|
|
DIRSTACKSIZE=5
|
|
|
|
# Enable extended globbing
|
|
setopt extendedglob
|
|
|
|
# Allow [ or ] whereever you want
|
|
unsetopt nomatch
|
|
|
|
# vi mode
|
|
bindkey -v
|
|
bindkey "^F" vi-cmd-mode
|
|
bindkey jj vi-cmd-mode
|
|
|
|
# handy keybindings
|
|
bindkey "^A" beginning-of-line
|
|
bindkey "^E" end-of-line
|
|
bindkey "^R" history-incremental-search-backward
|
|
bindkey "^P" history-search-backward
|
|
bindkey "^Y" accept-and-hold
|
|
bindkey "^N" insert-last-word
|
|
bindkey -s "^T" "^[Isudo ^[A" # "t" for "toughguy"
|
|
|
|
# aliases
|
|
[[ -f ~/.aliases ]] && source ~/.aliases
|
|
|
|
# extra files in ~/.zsh/configs/pre , ~/.zsh/configs , and ~/.zsh/configs/post
|
|
# these are loaded first, second, and third, respectively.
|
|
_load_settings() {
|
|
_dir="$1"
|
|
if [ -d "$_dir" ]; then
|
|
if [ -d "$_dir/pre" ]; then
|
|
for config in "$_dir"/pre/**/*(N-.); do
|
|
. $config
|
|
done
|
|
fi
|
|
|
|
for config in "$_dir"/**/*(N-.); do
|
|
case "$config" in
|
|
"$_dir"/pre/*)
|
|
:
|
|
;;
|
|
"$_dir"/post/*)
|
|
:
|
|
;;
|
|
*)
|
|
if [ -f $config ]; then
|
|
. $config
|
|
fi
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -d "$_dir/post" ]; then
|
|
for config in "$_dir"/post/**/*(N-.); do
|
|
. $config
|
|
done
|
|
fi
|
|
fi
|
|
}
|
|
_load_settings "$HOME/.zsh/configs"
|
|
|
|
# Local config
|
|
[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local
|