Created
November 17, 2014 19:10
-
-
Save Slabity/4ec070b742ba6c14d392 to your computer and use it in GitHub Desktop.
Personal zshrc file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# ~/.zshrc | |
# | |
# If not running interactively, don't do anything | |
[[ $- != *i* ]] && return | |
# Save this arrow! | |
# | |
# Global for saving prompt data. | |
PREV_COL="" | |
# First parameter is the color of the section. | |
# Second parameter is the color of the text. | |
# Third parameter is the text to put into the section. | |
function print_prompt_section() | |
{ | |
# If we're not the first section... | |
if [[ "$PREV_COL" != "" && "$PREV_COL" != "$1" ]] | |
then | |
PROMPT="${PROMPT}%K{$1}%F{${PREV_COL}}" # Print out arrow before. | |
elif [[ "$PREV_COL" = "$1" ]] | |
then | |
PROMPT="${PROMPT}%F{$2}" | |
fi | |
PROMPT="${PROMPT}%K{$1}%F{$2} $3 " | |
PREV_COL=$1 | |
} | |
function finalize_prompt() | |
{ | |
if [[ "$PREV_COL" != "" ]] | |
then | |
PROMPT="${PROMPT}%K{default}%F{${PREV_COL}}%F{default}" | |
fi | |
PREV_COL="" | |
} | |
# First parameter is a directory to be printed. | |
function print_prompt_dir() | |
{ | |
DIRS=$1 | |
[[ "$DIRS" =~ ^"$HOME"(/|$) ]] && DIRS="~${DIRS#$HOME}" | |
DIRS=$(echo $DIRS | sed "s/\//\n/g") | |
while read -r line | |
do | |
if [[ $line = "~" ]] | |
then | |
print_prompt_section 2 15 "~" | |
elif [[ $line = "" ]] | |
then | |
print_prompt_section 3 15 "/" | |
else | |
print_prompt_section 5 15 $line | |
fi | |
done <<< $DIRS | |
unset DIRS | |
} | |
function set_prompt() | |
{ | |
PROMPT="" | |
print_prompt_section 1 15 "%n" | |
print_prompt_section 4 15 "%m" | |
print_prompt_dir $PWD 4 | |
finalize_prompt | |
export PROMPT="${PROMPT} %K{default}%F{default}" | |
} | |
precmd_functions+=(set_prompt) | |
alias ls='ls --color=auto' | |
#autoload -U compinit promptinit | |
#compinit | |
#promptinit | |
# create a zkbd compatible hash; | |
# to add other keys to this hash, see: man 5 terminfo | |
typeset -A key | |
key[Home]=${terminfo[khome]} | |
key[End]=${terminfo[kend]} | |
key[Insert]=${terminfo[kich1]} | |
key[Delete]=${terminfo[kdch1]} | |
key[Up]=${terminfo[kcuu1]} | |
key[Down]=${terminfo[kcud1]} | |
key[Left]=${terminfo[kcub1]} | |
key[Right]=${terminfo[kcuf1]} | |
key[PageUp]=${terminfo[kpp]} | |
key[PageDown]=${terminfo[knp]} | |
# setup key accordingly | |
[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line | |
[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line | |
[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode | |
[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char | |
[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history | |
[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history | |
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char | |
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char | |
[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" beginning-of-buffer-or-history | |
[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" end-of-buffer-or-history | |
# Finally, make sure the terminal is in application mode, when zle is | |
# active. Only then are the values from $terminfo valid. | |
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then | |
function zle-line-init () { | |
printf '%s' "${terminfo[smkx]}" | |
} | |
function zle-line-finish () { | |
printf '%s' "${terminfo[rmkx]}" | |
} | |
zle -N zle-line-init | |
zle -N zle-line-finish | |
fi | |
export PATH=/usr/local/bin:$PATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment