Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 11.54 KB | None | 0 0
  1. ## Options section
  2. setopt correct                                                  # Auto correct mistakes
  3. setopt extendedglob                                             # Extended globbing. Allows using regular expressions with *
  4. setopt nocaseglob                                               # Case insensitive globbing
  5. setopt rcexpandparam                                            # Array expension with parameters
  6. setopt nocheckjobs                                              # Don't warn about running processes when exiting
  7. setopt numericglobsort                                          # Sort filenames numerically when it makes sense
  8. setopt nobeep                                                   # No beep
  9. setopt appendhistory                                            # Immediately append history instead of overwriting
  10. setopt histignorealldups                                        # If a new command is a duplicate, remove the older one
  11. setopt autocd                                                   # if only directory path is entered, cd there.
  12.  
  13. zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'       # Case insensitive tab completion
  14. zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"         # Colored completion (different colors for dirs/files/etc)
  15. zstyle ':completion:*' rehash true                              # automatically find new executables in path
  16. # Speed up completions
  17. zstyle ':completion:*' accept-exact '*(N)'
  18. zstyle ':completion:*' use-cache on
  19. zstyle ':completion:*' cache-path ~/.zsh/cache
  20. HISTFILE=~/.zhistory
  21. HISTSIZE=1000
  22. SAVEHIST=500
  23. #export EDITOR=/usr/bin/nano
  24. #export VISUAL=/usr/bin/nano
  25. WORDCHARS=${WORDCHARS//\/[&.;]}                                 # Don't consider certain characters part of the word
  26.  
  27.  
  28. ## Keybindings section
  29. bindkey -e
  30. bindkey '^[[7~' beginning-of-line                               # Home key
  31. bindkey '^[[H' beginning-of-line                                # Home key
  32. if [[ "${terminfo[khome]}" != "" ]]; then
  33.   bindkey "${terminfo[khome]}" beginning-of-line                # [Home] - Go to beginning of line
  34. fi
  35. bindkey '^[[8~' end-of-line                                     # End key
  36. bindkey '^[[F' end-of-line                                     # End key
  37. if [[ "${terminfo[kend]}" != "" ]]; then
  38.   bindkey "${terminfo[kend]}" end-of-line                       # [End] - Go to end of line
  39. fi
  40. bindkey '^[[2~' overwrite-mode                                  # Insert key
  41. bindkey '^[[3~' delete-char                                     # Delete key
  42. bindkey '^[[C'  forward-char                                    # Right key
  43. bindkey '^[[D'  backward-char                                   # Left key
  44. bindkey '^[[5~' history-beginning-search-backward               # Page up key
  45. bindkey '^[[6~' history-beginning-search-forward                # Page down key
  46.  
  47. # Navigate words with ctrl+arrow keys
  48. bindkey '^[Oc' forward-word                                     #
  49. bindkey '^[Od' backward-word                                    #
  50. bindkey '^[[1;5D' backward-word                                 #
  51. bindkey '^[[1;5C' forward-word                                  #
  52. bindkey '^H' backward-kill-word                                 # delete previous word with ctrl+backspace
  53. bindkey '^[[Z' undo                                             # Shift+tab undo last action
  54.  
  55. ## Alias section
  56. alias cp="cp -i"                                                # Confirm before overwriting something
  57. alias df='df -h'                                                # Human-readable sizes
  58. alias free='free -m'                                            # Show sizes in MB
  59. alias gitu='git add . && git commit && git push'
  60.  
  61. # Theming section  
  62. autoload -U compinit colors zcalc
  63. compinit -d
  64. colors
  65.  
  66. # enable substitution for prompt
  67. setopt prompt_subst
  68.  
  69. # Prompt (on left side) similar to default bash prompt, or redhat zsh prompt with colors
  70.  #PROMPT="%(!.%{$fg[red]%}[%n@%m %1~]%{$reset_color%}# .%{$fg[green]%}[%n@%m %1~]%{$reset_color%}$ "
  71. # Maia prompt
  72. PROMPT="%B%{$fg[cyan]%}%(4~|%-1~/.../%2~|%~)%u%b >%{$fg[cyan]%}>%B%(?.%{$fg[cyan]%}.%{$fg[red]%})>%{$reset_color%}%b " # Print some system information when the shell is first started
  73. # Print a greeting message when shell is started
  74. echo $USER@$HOST  $(uname -srm) $(lsb_release -rcs)
  75. ## Prompt on right side:
  76. #  - shows status of git when in git repository (code adapted from https://techanic.net/2012/12/30/my_git_prompt_for_zsh.html)
  77. #  - shows exit status of previous command (if previous command finished with an error)
  78. #  - is invisible, if neither is the case
  79.  
  80. # Modify the colors and symbols in these variables as desired.
  81. GIT_PROMPT_SYMBOL="%{$fg[blue]%}±"                              # plus/minus     - clean repo
  82. GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$reset_color%}"
  83. GIT_PROMPT_SUFFIX="%{$fg[green]%}]%{$reset_color%}"
  84. GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}"             # A"NUM"         - ahead by "NUM" commits
  85. GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}"           # B"NUM"         - behind by "NUM" commits
  86. GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}⚡︎%{$reset_color%}"     # lightning bolt - merge conflict
  87. GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}"       # red circle     - untracked files
  88. GIT_PROMPT_MODIFIED="%{$fg_bold[yellow]%}●%{$reset_color%}"     # yellow circle  - tracked files modified
  89. GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}"        # green circle   - staged changes present = ready for "git push"
  90.  
  91. parse_git_branch() {
  92.   # Show Git branch/tag, or name-rev if on detached head
  93.   ( git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD ) 2> /dev/null
  94. }
  95.  
  96. parse_git_state() {
  97.   # Show different symbols as appropriate for various Git repository states
  98.   # Compose this value via multiple conditional appends.
  99.   local GIT_STATE=""
  100.   local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
  101.   if [ "$NUM_AHEAD" -gt 0 ]; then
  102.     GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD}
  103.   fi
  104.   local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
  105.   if [ "$NUM_BEHIND" -gt 0 ]; then
  106.     GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND}
  107.   fi
  108.   local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
  109.   if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
  110.     GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING
  111.   fi
  112.   if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
  113.     GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED
  114.   fi
  115.   if ! git diff --quiet 2> /dev/null; then
  116.     GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED
  117.   fi
  118.   if ! git diff --cached --quiet 2> /dev/null; then
  119.     GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED
  120.   fi
  121.   if [[ -n $GIT_STATE ]]; then
  122.     echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX"
  123.   fi
  124. }
  125.  
  126. git_prompt_string() {
  127.   local git_where="$(parse_git_branch)"
  128.  
  129.   # If inside a Git repository, print its branch and state
  130.   [ -n "$git_where" ] && echo "$GIT_PROMPT_SYMBOL$(parse_git_state)$GIT_PROMPT_PREFIX%{$fg[yellow]%}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX"
  131.  
  132.   # If not inside the Git repo, print exit codes of last command (only if it failed)
  133.   [ ! -n "$git_where" ] && echo "%{$fg[red]%}"
  134. }
  135.  
  136. # Right prompt with exit status of previous command if not successful
  137.  #RPROMPT="%{$fg[red]%} %(?..[%?])"
  138. # Right prompt with exit status of previous command marked with ✓ or ✗
  139.  #RPROMPT="%(?.%{$fg[green]%}✓ %{$reset_color%}.%{$fg[red]%}✗ %{$reset_color%})"
  140.  
  141.  
  142. # Color man pages
  143. export LESS_TERMCAP_mb=$'\E[01;32m'
  144. export LESS_TERMCAP_md=$'\E[01;32m'
  145. export LESS_TERMCAP_me=$'\E[0m'
  146. export LESS_TERMCAP_se=$'\E[0m'
  147. export LESS_TERMCAP_so=$'\E[01;47;34m'
  148. export LESS_TERMCAP_ue=$'\E[0m'
  149. export LESS_TERMCAP_us=$'\E[01;36m'
  150. export LESS=-r
  151.  
  152.  
  153. ## Plugins section: Enable fish style features
  154. # Use syntax highlighting
  155. source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  156. # Use history substring search
  157. source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
  158. # bind UP and DOWN arrow keys to history substring search
  159. zmodload zsh/terminfo
  160. bindkey "$terminfo[kcuu1]" history-substring-search-up
  161. bindkey "$terminfo[kcud1]" history-substring-search-down
  162. bindkey '^[[A' history-substring-search-up         
  163. bindkey '^[[B' history-substring-search-down
  164.  
  165. # Apply different settigns for different terminals
  166. case $(basename "$(cat "/proc/$PPID/comm")") in
  167.   login)
  168.         RPROMPT="%{$fg[red]%}"  
  169.         alias x='startx ~/.xinitrc'      # Type name of desired desktop after x, xinitrc is configured for it
  170.     ;;
  171. #  'tmux: server')
  172. #        RPROMPT='$(git_prompt_string)'
  173. #       ## Base16 Shell color themes.
  174. #       #possible themes: 3024, apathy, ashes, atelierdune, atelierforest, atelierhearth,
  175. #       #atelierseaside, bespin, brewer, chalk, codeschool, colors, default, eighties,
  176. #       #embers, flat, google, grayscale, greenscreen, harmonic16, isotope, londontube,
  177. #       #marrakesh, mocha, monokai, ocean, paraiso, pop (dark only), railscasts, shapesifter,
  178. #       #solarized, summerfruit, tomorrow, twilight
  179. #       #theme="eighties"
  180. #       #Possible variants: dark and light
  181. #       #shade="dark"
  182. #       #BASE16_SHELL="/usr/share/zsh/scripts/base16-shell/base16-$theme.$shade.sh"
  183. #       #[[ -s $BASE16_SHELL ]] && source $BASE16_SHELL
  184. #       # Use autosuggestion
  185. #       source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
  186. #       ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
  187. #       ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
  188. #     ;;
  189.   *)
  190.         RPROMPT='$(git_prompt_string)'
  191.         # Use autosuggestion
  192.         source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
  193.         ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
  194.         ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
  195.     ;;
  196. esac
  197.  
  198. # Mine
  199.  
  200. export LANG="en_US.UTF-8"
  201. export LC_ALL="en_US.UTF-8"
  202. export LANGUAGE="en_US.UTF-8"
  203.  
  204. export PATH=~/bin:$PATH
  205.  
  206. export VISUAL="vim"
  207. export EDITOR="vim"
  208. export BROWSER="firefox"
  209. export PAGER='less -RF'
  210. alias man='PAGER="most" man ' # See ~/bin/most to find out it is actually most -cwd
  211.  
  212. alias e='exit'
  213. alias g='gvim'
  214. alias v='vim'
  215. alias m='mplayer'
  216. alias sbash='sudo bash'
  217. alias szsh='sudo zsh'
  218. alias smc='sudo mc'
  219. alias svim='sudo vim'
  220. alias xbg='xbacklight -get'
  221. alias xbs='xbacklight -set'
  222. alias cgrep='grep --color=always'
  223. alias grepl='cgrep --include=*.lua -r '
  224. alias greph='cgrep --include=*.{h,hh,hpp,hxx} -r '
  225. alias grepc='cgrep --include=*.{c,cc,cpp,cxx} -r '
  226. alias grephc='cgrep --include=*.{h,hh,hpp,hxx,c,cc,cpp,cxx} -r '
  227. alias grepj='cgrep --include=*.java -r '
  228. alias grepp='cgrep --include=*.py -r '
  229. alias grepr='cgrep --include=*.robot -r'
  230. alias grepa='cgrep --include=*.{h,hh,hpp,hcc,c,cc,cpp,cxx,java,py,robot} -r '
  231. alias grept='cgrep --include=*.txt -r'
  232. alias grepcm='cgrep --include=CMakeLists.txt --include=*.cmake -r '
  233. alias rbt='systemctl reboot'
  234. alias pwoff='systemctl poweroff'
  235.  
  236. gcl() {
  237.     grc cat $1 | less -R
  238. }
  239.  
  240. # Arch specific
  241. alias p='pacman'
  242. alias pcdu='sudo pacman -Syyuv'
  243. alias pcar='sudo pacman -Rsn $(pacman -Qdtq)'
  244. alias pl='sudo pacman -Ql'
  245. alias pi='sudo pacman -S'
  246. alias pin='sudo pacman --needed -S'
  247. plb()
  248. {
  249.     files=`pacman -Ql $1`
  250.     files_w_bin=`echo -e ${files} | grep bin`
  251.     echo -e ${files_w_bin}
  252. }
  253.  
  254. # Pass aliases through sudo
  255. alias sudo='sudo '
  256.  
  257. # mc fucks up prompt (it disappears after running commands) sometimes for some reason
  258. if ps $PPID | grep mc; then
  259.     #unset RPROMPT # this removes git_prompt_string cool stuff but I have no other solution for now
  260.     # RPROMPT='$(git_prompt_string)'
  261.     # this removes git_prompt_string cool stuff but I have no other solution for now
  262.     RPROMPT=""
  263. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement