Advertisement
Guest User

ZSH.RC (AIX/Linux)

a guest
Aug 31st, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.47 KB | None | 0 0
  1. ###############################################################################
  2. # Safety Check
  3. ###############################################################################
  4.  
  5. # Don't do anything for non-interactive shells
  6. [[ -z "$PS1" ]] && return
  7. # Need to know if this is Linux or AIX
  8. OS=`uname -a|awk '{print $1}'`
  9. # On AIX, we need to source /etc/environment first and foremost.
  10. if [[ ${OS} == "AIX" && -s /etc/environment ]]; then
  11.     . /etc/environment
  12. fi
  13. ###############################################################################
  14. # Local Settings
  15. ###############################################################################
  16.  
  17. # Add any machine specific settings/aliases to your login
  18. eval LOCAL_SETUP_FILE="~/.zshrc.local"
  19. if [[ -s ${LOCAL_SETUP_FILE} ]]; then
  20.     . ${LOCAL_SETUP_FILE}
  21. fi
  22.  
  23. # If applicable, add any machine specifics scripts to your login
  24. if [[ -d ${LOCAL_SCRIPT_DIR} && -n ${LOCAL_SCRIPT_DIR} ]]; then
  25.     export PATH=${PATH}:${LOCAL_SCRIPT_DIR}
  26. fi
  27.  
  28. ###############################################################################
  29. # History
  30. ###############################################################################
  31. HISTFILE=~/.history
  32. HISTSIZE=10500
  33. SAVEHIST=10000
  34. setopt appendhistory nomatch    # Add everything to the history.
  35. setopt incappendhistory         # Write after every command
  36. setopt sharehistory             # Share between sessions
  37. setopt histexpiredupsfirst      # Kill duplicates in history first (when full)
  38. setopt histfindnodups           # Don't find dupes, either.
  39. setopt histsavenodups           # I hate duplicates, obviously...  Don't save them.
  40. setopt histverify               # Preview history expansions
  41. export HISTIGNORE="&:ls:[bf]g:exit:reset:clear:cd:cd ..:cd.."
  42.  
  43. ###############################################################################
  44. # Editor Settings
  45. ###############################################################################
  46. # Check for VIM, use that if possible.
  47. which vim 2>&1 1>/dev/null
  48. if [[ $? == 0 ]]; then
  49.     export EDITOR=vim
  50.     export VISUAL=vim
  51.     alias vi='vim'
  52. else
  53.     export EDITOR=vi
  54.     export VISUAL=vi
  55. fi
  56.  
  57. ###############################################################################
  58. # Autocompletion
  59. ###############################################################################
  60. # The below somehow screw up vi searching from a prompt with esc+/ ... ?
  61. #autoload -U compinit   # Load these two for the case-insensitive globbing.
  62. #compinit -C
  63. # Case-insensitive (all),partial-word and then substring completion
  64. #zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
  65.  
  66. ## case-insensitive (all),partial-word and then substring completion
  67. zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
  68.  
  69. setopt autoparamslash   # Append a slash on directory completion
  70. setopt completealiases  # Treat aliases as commands
  71. setopt extendedglob     # Assume [#~^] refer to patterns
  72. setopt globdots         # Assume leading . for hidden files
  73. setopt nonomatch        # Ignore globs if they match nothing
  74. setopt autopushd        # Automatically add directories to pushd
  75. setopt autocd           # Automatically change directories if no cmd given
  76. setopt nomenucomplete   # Disable ZSH menu completion
  77. setopt noautomenu       # Disable ZSH tab cycle completion
  78. setopt bashautolist     # Enable Bash/KSH style completion.
  79. ###############################################################################
  80. # Aliases
  81. ###############################################################################
  82. if [[ ${OS} == "AIX" && -a /usr/linux/bin/ls ]]; then
  83.     # To install ZSH, you have to have CoreUtils...  This shouldn't be needed.
  84.     LS="/usr/linux/bin/ls"
  85.     EGREP="/usr/linux/bin/egrep"
  86. else
  87.     LS="ls"
  88.     EGREP="egrep"
  89.  
  90. fi
  91. alias grep=`echo ${EGREP}`' --color=tty -d skip'
  92. alias ls=`echo ${LS}`' --color=tty'
  93. alias ld='ls -ld [^.]*/ 2>/dev/null || echo "No directories..."'
  94. alias ll='ls -l'
  95. alias la='ls -la'
  96. alias lt='ls -ltr'
  97. alias tf='tail -f'
  98. alias ruler='echo .........1.........2.........3.........4.........5.........6.........7.........8'
  99.  
  100. ###############################################################################
  101. # Color man pages - Linux Only
  102. ###############################################################################
  103. if [[ ${OS} == "Linux" ]]; then
  104.     export LESS_TERMCAP_mb=$'\e[01;34m'
  105.     export LESS_TERMCAP_md=$'\e[01;34m'
  106.     export LESS_TERMCAP_me=$'\e[0m'
  107.     export LESS_TERMCAP_se=$'\e[0m'
  108.     export LESS_TERMCAP_so=$'\e[01;44;33m'
  109.     export LESS_TERMCAP_ue=$'\e[0m'
  110.     export LESS_TERMCAP_us=$'\e[38;05;111m;'
  111. fi
  112.  
  113. ###############################################################################
  114. # Key Bindings
  115. ###############################################################################
  116.  
  117. # Force ZSH to use VI keybindings
  118. bindkey -v                              # VI Keybindings
  119. # Generic Key Bindings (XTerm)
  120. bindkey "\e[1~" beginning-of-line       # Home
  121. bindkey "\e[4~" end-of-line             # End
  122. bindkey "\e[5~" beginning-of-history    # PageUp
  123. bindkey "\e[6~" end-of-history          # PageDown
  124. bindkey "\e[2~" quoted-insert           # Ins
  125. bindkey "\e[3~" delete-char             # Del
  126. # RXVT Keybinding
  127. bindkey "\e[7~" beginning-of-line       # Home
  128. bindkey "\e[8~" end-of-line             # End
  129. # XTerm - non-RH/Debian
  130. bindkey "\eOH" beginning-of-line        # Home
  131. bindkey "\eOF" end-of-line              # End
  132. # FreeBSD Console
  133. bindkey "\e[H" beginning-of-line        # Home
  134. bindkey "\e[F" end-of-line              # End
  135.  
  136. ###############################################################################
  137. # Misc Functions
  138. ###############################################################################
  139.  
  140. function backup() { cp $1{,.$(date '+%Y%m%d-%H%M%S')}; }
  141.  
  142. ex () {
  143.     if [ -f $1 ] ; then
  144.         case $1 in
  145.             *.tar.bz2)   tar xjf $1        ;;
  146.             *.tar.gz)    tar xzf $1     ;;
  147.             *.bz2)       bunzip2 $1       ;;
  148.             *.rar)       rar x $1     ;;
  149.             *.gz)        gunzip $1     ;;
  150.             *.tar)       tar xf $1        ;;
  151.             *.tbz2)      tar xjf $1      ;;
  152.             *.tgz)       tar xzf $1       ;;
  153.             *.zip)       unzip $1     ;;
  154.             *.Z)         uncompress $1  ;;
  155.             *.7z)        7z x $1    ;;
  156.             *)           echo "'$1' cannot be extracted via extract()" ;;
  157.         esac
  158.     else
  159.         echo "'$1' is not a valid file"
  160.     fi
  161. }
  162.  
  163. ###############################################################################
  164. # Prompt  Settings
  165. ###############################################################################
  166. setprompt () {
  167.     # Need this so the prompt will work.
  168.     setopt prompt_subst
  169.  
  170.     # See if we can use colors.  AIX VTMenu terminals notably will not.
  171.     autoload colors zsh/terminfo
  172.     if [[ "$terminfo[colors]" -ge 8 ]]; then
  173.         colors
  174.     fi
  175.     for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
  176.         eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
  177.         eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
  178.     done
  179.     PR_NO_COLOR="%{$terminfo[sgr0]%}"
  180.        
  181.         # The default non-root prompt symbol is a %, which throws me off, change that.
  182.         if [[ `id -u` == 0 ]]; then
  183.                 PromptChar="#"
  184.         else
  185.                 PromptChar="$"
  186.         fi
  187.  
  188.         PROMPT="${COLOR1}[${COLOR2}%D{%H:%M:%S}${COLOR1}] [${COLOR2}%n${COLOR1}@${COLOR2}%m${COLOR1}:${COLOR2}%~${COLOR1}]
  189. %(?..${COLOR1}[${COLOR_ERR}RTN: %?${PS_NO_COLOR}${COLOR1}] )${PR_NO_COLOR}${PromptChar} "
  190.         RPROMPT=""
  191.         PS2="${COLOR1}-(${COLOR2}%_${COLOR1})-${PR_NO_COLOR} "
  192. }
  193. setprompt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement