Skip to content

Commit

Permalink
Split zshrc file, add installation script
Browse files Browse the repository at this point in the history
Installation script works for zshrc only.
  • Loading branch information
Vasily Laur committed Jul 11, 2016
1 parent 043cbb2 commit b5fe252
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 165 deletions.
40 changes: 40 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -o errexit -o nounset -o pipefail
SCRIPT_PATH="$(dirname $(readlink -f "$0"))"

if [[ $1 = zshrc || $1 = zsh ]]; then
echo '#This file was generated from dotfiles' > ~/.zshrc
echo '#All changes made here will be overwritten on update' >> ~/.zshrc

cat "$SCRIPT_PATH"/zsh/other.zsh >> ~/.zshrc

echo '# history setup --------------------------------------------------------' >> ~/.zshrc
cat "$SCRIPT_PATH"/zsh/history.zsh >> ~/.zshrc
echo '# ----------------------------------------------------------------------' >> ~/.zshrc
echo '' >> ~/.zshrc

echo '# key bindings ---------------------------------------------------------' >> ~/.zshrc
cat "$SCRIPT_PATH"/zsh/key_bindings.zsh >> ~/.zshrc
echo '# ----------------------------------------------------------------------' >> ~/.zshrc
echo '' >> ~/.zshrc

echo '# prompt setup ---------------------------------------------------------' >> ~/.zshrc
cat "$SCRIPT_PATH"/zsh/prompt.zsh >> ~/.zshrc
echo '# ----------------------------------------------------------------------' >> ~/.zshrc
echo '' >> ~/.zshrc

echo '# window title setup ---------------------------------------------------' >> ~/.zshrc
cat "$SCRIPT_PATH"/zsh/window_title.zsh >> ~/.zshrc
echo '# ----------------------------------------------------------------------' >> ~/.zshrc
echo '' >> ~/.zshrc

echo '# aliases --------------------------------------------------------------' >> ~/.zshrc
cat "$SCRIPT_PATH"/zsh/aliases.zsh >> ~/.zshrc
echo '# ----------------------------------------------------------------------' >> ~/.zshrc
echo '' >> ~/.zshrc

echo '# functions setup ------------------------------------------------------' >> ~/.zshrc
cat "$SCRIPT_PATH"/zsh/functions.zsh >> ~/.zshrc
echo '# ----------------------------------------------------------------------' >> ~/.zshrc
fi
13 changes: 13 additions & 0 deletions zsh/aliases.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
alias ls='ls -F --color=auto'
alias ll='ls -l --color=auto -h'
alias la='ls -A --color=auto'
alias lla='ll -A --color=auto -h'
alias grep='grep --colour=auto'
hash colordiff 2>/dev/null && alias diff='colordiff'

# don't try to correct typos
alias mkdir='nocorrect mkdir'
alias mv='nocorrect mv'

# aliases for file extensions
alias -s txt=${EDITOR}
47 changes: 47 additions & 0 deletions zsh/functions.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# cd and ls in one shot
cdls() {
local dir=$1
test -z "$dir" && dir="$HOME"
cd "$dir" && ls
}

cdll() {
local dir=$1
test -z "$dir" && dir="$HOME"
cd "$dir" && ll
}

# classic archive extractor
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via $0" ;;
esac
else
echo "'$1' is not a valid file"
fi
}

# color man pages
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
13 changes: 13 additions & 0 deletions zsh/history.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
HISTFILE=~/.zhistory
HISTSIZE=2000
SAVEHIST=2000
setopt APPEND_HISTORY
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_REDUCE_BLANKS # remove blank lines from history file
# if the command starts with a whitespace, don't add it to history
setopt HIST_IGNORE_SPACE
# append every single command to $HISTFILE immediately after hitting ENTER
setopt INC_APPEND_HISTORY
# shares the histories of multiple Z-Shells; commands from one active Zsh are
# then placed in the other shell's history
setopt SHARE_HISTORY
26 changes: 26 additions & 0 deletions zsh/key_bindings.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# don't guess preferred mode, always use emacs-style keybindings
bindkey -e

# to show hotkey symbol, press ctrl+V, than hotkey
bindkey -M isearch '^R' history-incremental-search-backward
bindkey -M isearch '^S' history-incremental-search-forward
bindkey "^[[5~" history-beginning-search-backward # pg up
bindkey "^[[6~" history-beginning-search-forward # pg down

bindkey "^[[3~" delete-char # delete
bindkey "^W" backward-delete-word # delete instead of kill
bindkey "^A" beginning-of-line
bindkey "^E" end-of-line

case $TERM in
rxvt|rxvt-unicode|rxvt-256color|rxvt-unicode-256color)
bindkey '^[Od' emacs-backward-word # ctrl + left arrow
bindkey '^[Oc' emacs-forward-word # ctrl + right arrow
;;
*)
bindkey '^[[1;5D' emacs-backward-word # ctrl + left arrow
bindkey '^[[1;5C' emacs-forward-word # ctrl + right arrow
;;
esac

export WORDCHARS='_-' # symbols, that are a part of a word
13 changes: 13 additions & 0 deletions zsh/other.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
typeset -U path
path=(~/bin $path)

setopt autocd # change directory without typing cd
setopt correctall # correct typos
setopt NO_BEEP

# enable completion
autoload -U compinit && compinit

# use arrow keys to navigate completion suggestions
setopt menucomplete
zstyle ':completion:*' menu select=1 _complete _ignored _approximate
17 changes: 17 additions & 0 deletions zsh/prompt.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then
if [[ $EUID == 0 ]]; then
PROMPT=$'%{\e[1;31m%}%~ %{\e[0m%}' # root
else
PROMPT=$'%{\e[1;33m%}%~ %{\e[0m%}' # regular user
fi
# right prompt with hostname or bad smiley
RPROMPT=$'%(?,%{\e[34m%}ssh %n@%m%{\e[0m%},%{\e[1;31m%}:(%{\e[0m%})'
else # not SSH
if [[ $EUID == 0 ]]; then
PROMPT=$'%{\e[1;31m%}%~ %{\e[0m%}' # root
else
PROMPT=$'%{\e[1;32m%}%~ %{\e[0m%}' # regular user
fi
# right prompt with hostname or bad smiley
RPROMPT=$'%(?,%{\e[34m%}%m%{\e[0m%},%{\e[1;31m%}:(%{\e[0m%})'
fi
20 changes: 20 additions & 0 deletions zsh/window_title.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
case $TERM in
termite|*xterm*|rxvt|rxvt-unicode|rxvt-256color|rxvt-unicode-256color|(dt|k|E)term)
precmd ()
{
if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" || $EUID == 0 ]]; then
print -Pn "\e]0;%n@%m:%~\a"
else
print -Pn "\e]0;%~\a" # regular user
fi
}
preexec ()
{
if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" || $EUID == 0 ]]; then
print -Pn "\e]0;%n@%m $1\a"
else
print -Pn "\e]0;$1\a" # regular user
fi
}
;;
esac
165 changes: 0 additions & 165 deletions zshrc

This file was deleted.

0 comments on commit b5fe252

Please sign in to comment.