]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/themes/refined.zsh-theme
5e2de7a87fb95e57ea83add4d3a2297afcc3f9ee
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / themes / refined.zsh-theme
1 #!/usr/bin/env zsh
2
3 # ------------------------------------------------------------------------------
4 #
5 # Pure - A minimal and beautiful theme for oh-my-zsh
6 #
7 # Based on the custom Zsh-prompt of the same name by Sindre Sorhus. A huge
8 # thanks goes out to him for designing the fantastic Pure prompt in the first
9 # place! I'd also like to thank Julien Nicoulaud for his "nicoulaj" theme from
10 # which I've borrowed both some ideas and some actual code. You can find out
11 # more about both of these fantastic two people here:
12 #
13 # Sindre Sorhus
14 #   Github:   https://github.com/sindresorhus
15 #   Twitter:  https://twitter.com/sindresorhus
16 #
17 # Julien Nicoulaud
18 #   Github:   https://github.com/nicoulaj
19 #   Twitter:  https://twitter.com/nicoulaj
20 #
21 # ------------------------------------------------------------------------------
22
23 # Set required options
24 #
25 setopt prompt_subst
26
27 # Load required modules
28 #
29 autoload -Uz vcs_info
30
31 # Set vcs_info parameters
32 #
33 zstyle ':vcs_info:*' enable hg bzr git
34 zstyle ':vcs_info:*:*' unstagedstr '!'
35 zstyle ':vcs_info:*:*' stagedstr '+'
36 zstyle ':vcs_info:*:*' formats "$FX[bold]%r$FX[no-bold]/%S" "%s:%b" "%%u%c"
37 zstyle ':vcs_info:*:*' actionformats "$FX[bold]%r$FX[no-bold]/%S" "%s:%b" "%u%c (%a)"
38 zstyle ':vcs_info:*:*' nvcsformats "%~" "" ""
39
40 # Fastest possible way to check if repo is dirty
41 #
42 git_dirty() {
43     # Check if we're in a git repo
44     command git rev-parse --is-inside-work-tree &>/dev/null || return
45     # Check if it's dirty
46     command git diff --quiet --ignore-submodules HEAD &>/dev/null; [ $? -eq 1 ] && echo "*"
47 }
48
49 # Display information about the current repository
50 #
51 repo_information() {
52     echo "%F{blue}${vcs_info_msg_0_%%/.} %F{8}$vcs_info_msg_1_`git_dirty` $vcs_info_msg_2_%f"
53 }
54
55 # Displays the exec time of the last command if set threshold was exceeded
56 #
57 cmd_exec_time() {
58     local stop=`date +%s`
59     local start=${cmd_timestamp:-$stop}
60     let local elapsed=$stop-$start
61     [ $elapsed -gt 5 ] && echo ${elapsed}s
62 }
63
64 # Get the initial timestamp for cmd_exec_time
65 #
66 preexec() {
67     cmd_timestamp=`date +%s`
68 }
69
70 # Output additional information about paths, repos and exec time
71 #
72 precmd() {
73     setopt localoptions nopromptsubst
74     vcs_info # Get version control info before we start outputting stuff
75     print -P "\n$(repo_information) %F{yellow}$(cmd_exec_time)%f"
76     unset cmd_timestamp #Reset cmd exec time.
77 }
78
79 # Define prompts
80 #
81 PROMPT="%(?.%F{magenta}.%F{red})❯%f " # Display a red prompt char on failure
82 RPROMPT="%F{8}${SSH_TTY:+%n@%m}%f"    # Display username if connected via SSH
83
84 # ------------------------------------------------------------------------------
85 #
86 # List of vcs_info format strings:
87 #
88 # %b => current branch
89 # %a => current action (rebase/merge)
90 # %s => current version control system
91 # %r => name of the root directory of the repository
92 # %S => current path relative to the repository root directory
93 # %m => in case of Git, show information about stashes
94 # %u => show unstaged changes in the repository
95 # %c => show staged changes in the repository
96 #
97 # List of prompt format strings:
98 #
99 # prompt:
100 # %F => color dict
101 # %f => reset color
102 # %~ => current path
103 # %* => time
104 # %n => username
105 # %m => shortname host
106 # %(?..) => prompt conditional - %(condition.true.false)
107 #
108 # ------------------------------------------------------------------------------