aboutsummaryrefslogtreecommitdiffhomepage
path: root/zsh
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2022-11-18 13:05:06 +0800
committerHsieh Chin Fan <pham@topo.tw>2022-11-18 13:05:06 +0800
commitcaa9323eae8ec54afd6158472ee71050ea584842 (patch)
tree1f25bcb7c863f9f60732b5df12a1b49968f9713d /zsh
parentb0063faac797b6996301a0dee7599dc7974f7a3d (diff)
Add custom zshrc
Diffstat (limited to 'zsh')
-rw-r--r--zsh/ps1133
-rw-r--r--zsh/zshrc83
2 files changed, 83 insertions, 133 deletions
diff --git a/zsh/ps1 b/zsh/ps1
deleted file mode 100644
index 903bc79..0000000
--- a/zsh/ps1
+++ /dev/null
@@ -1,133 +0,0 @@
1# Purification
2# by Matthieu Cneude
3# https://github.com/Phantas0s/purification
4
5# Based on:
6
7# Purity
8# by Kevin Lanni
9# https://github.com/therealklanni/purity
10# MIT License
11
12# prompt:
13# %F => color dict
14# %f => reset color
15# %~ => current path
16# %* => time
17# %n => username
18# %m => shortname host
19# %(?..) => prompt conditional - %(condition.true.false)
20
21# Display git status
22# TODO to refactor with switch / using someting else than grep
23# Might be faster using ripgrep too
24git_prompt_status() {
25 local INDEX STATUS
26
27 INDEX=$(command git status --porcelain -b 2> /dev/null)
28
29 STATUS=""
30
31 if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then
32 STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
33 fi
34
35 if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
36 STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
37 elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then
38 STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
39 elif $(echo "$INDEX" | grep '^MM ' &> /dev/null); then
40 STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
41 fi
42
43 if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then
44 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
45 elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then
46 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
47 elif $(echo "$INDEX" | grep '^MM ' &> /dev/null); then
48 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
49 elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then
50 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
51 fi
52
53 if $(echo "$INDEX" | grep '^R ' &> /dev/null); then
54 STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS"
55 fi
56
57 if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then
58 STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
59 elif $(echo "$INDEX" | grep '^D ' &> /dev/null); then
60 STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
61 elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then
62 STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
63 fi
64
65 if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
66 STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS"
67 fi
68
69 if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
70 STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
71 fi
72
73 if $(echo "$INDEX" | grep '^## [^ ]\+ .*ahead' &> /dev/null); then
74 STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS"
75 fi
76
77 if $(echo "$INDEX" | grep '^## [^ ]\+ .*behind' &> /dev/null); then
78 STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS"
79 fi
80
81 if $(echo "$INDEX" | grep '^## [^ ]\+ .*diverged' &> /dev/null); then
82 STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS"
83 fi
84
85 if [[ ! -z "$STATUS" ]]; then
86 echo " [ $STATUS]"
87 fi
88}
89
90
91prompt_git_branch() {
92 autoload -Uz vcs_info
93 precmd_vcs_info() { vcs_info }
94 precmd_functions+=( precmd_vcs_info )
95 setopt prompt_subst
96 zstyle ':vcs_info:git:*' formats '%b'
97}
98
99prompt_git_info() {
100 [ ! -z "$vcs_info_msg_0_" ] && echo "$ZSH_THEME_GIT_PROMPT_PREFIX%F{white}$vcs_info_msg_0_%f$ZSH_THEME_GIT_PROMPT_SUFFIX"
101}
102
103prompt_purity_precmd() {
104 # Pass a line before each prompt
105 print -P ''
106}
107
108prompt_purification_setup() {
109 # Display git branch
110
111 autoload -Uz add-zsh-hook
112 add-zsh-hook precmd prompt_purity_precmd
113
114 ZSH_THEME_GIT_PROMPT_PREFIX=" %F{red}λ%f:"
115 ZSH_THEME_GIT_PROMPT_DIRTY=""
116 ZSH_THEME_GIT_PROMPT_CLEAN=""
117
118 ZSH_THEME_GIT_PROMPT_ADDED="%F{green}+%f "
119 ZSH_THEME_GIT_PROMPT_MODIFIED="%F{blue}%f "
120 ZSH_THEME_GIT_PROMPT_DELETED="%F{red}x%f "
121 ZSH_THEME_GIT_PROMPT_RENAMED="%F{magenta}➜%f "
122 ZSH_THEME_GIT_PROMPT_UNMERGED="%F{yellow}═%f "
123 ZSH_THEME_GIT_PROMPT_UNTRACKED="%F{white}%f "
124 ZSH_THEME_GIT_PROMPT_STASHED="%B%F{red}%f%b "
125 ZSH_THEME_GIT_PROMPT_BEHIND="%B%F{red}%f%b "
126 ZSH_THEME_GIT_PROMPT_AHEAD="%B%F{green}%f%b "
127
128 prompt_git_branch
129 RPROMPT='$(prompt_git_info) $(git_prompt_status)'
130 PROMPT=$'%F{white}%~ %B%F{blue}>%f%b '
131}
132
133prompt_purification_setup
diff --git a/zsh/zshrc b/zsh/zshrc
new file mode 100644
index 0000000..d77e299
--- /dev/null
+++ b/zsh/zshrc
@@ -0,0 +1,83 @@
1# Set name of the theme to load --- if set to "random", it will
2# load a random theme each time oh-my-zsh is loaded, in which case,
3# to know which specific one was loaded, run: echo $RANDOM_THEME
4# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
5ZSH_THEME="archcraft"
6
7# typebrook/helper
8export SETTING_DIR=$HOME/helper
9source $SETTING_DIR/tools/init/load-settings.sh
10fpath=($SETTING_DIR/zsh $fpath)
11
12# Options
13setopt extended_glob
14setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file.
15
16_comp_options+=(globdots) # With hidden files
17autoload -Uz compinit; compinit
18zstyle ':completion:*' menu select
19zstyle ':completion::complete:*' gain-privileges 1
20
21# PS1 with git status at right
22#autoload -U ps1; ps1
23alias ps1="vim $SETTING_DIR/zsh/ps1"
24autoload -Uz add-zsh-hook
25add-zsh-hook precmd precmd
26function precmd() {
27 RIGHT=$(NUM=$($SETTING_DIR/tools/git/check-repos.sh -n); (( $NUM != 0 )) && echo $NUM)
28 PROMPT='%B%(?:%F{green}%m%f:%F{red}%m%f)%f %F{cyan} %c%f%b '
29 RPROMPT="%B${RIGHT}%b"
30}
31
32# Directory Stack
33#setopt AUTO_PUSHD # Push the current directory visited on the stack.
34#setopt PUSHD_IGNORE_DUPS # Do not store duplicates in the stack.
35#setopt PUSHD_SILENT # Do not print the directory stack after pushd or popd.
36
37#alias d='dirs -v'
38#for index ({1..9}) alias "$index"="cd +${index}"; unset index
39
40# create a zkbd compatible hash;
41# to add other keys to this hash, see: man 5 terminfo
42typeset -g -A key
43
44key[Home]="${terminfo[khome]}"
45key[End]="${terminfo[kend]}"
46key[Insert]="${terminfo[kich1]}"
47key[Backspace]="${terminfo[kbs]}"
48key[Delete]="${terminfo[kdch1]}"
49key[Up]="${terminfo[kcuu1]}"
50key[Down]="${terminfo[kcud1]}"
51key[Left]="${terminfo[kcub1]}"
52key[Right]="${terminfo[kcuf1]}"
53key[PageUp]="${terminfo[kpp]}"
54key[PageDown]="${terminfo[knp]}"
55key[Shift-Tab]="${terminfo[kcbt]}"
56
57# setup key accordingly
58bindkey -- "\C-A" beginning-of-line
59bindkey -- "\C-E" end-of-line
60bindkey -- "${key[Insert]}" overwrite-mode
61bindkey -- "\C-D" delete-char
62bindkey -- "\C-H" backward-delete-char
63bindkey -- "\M-D" delete-word
64bindkey -- "\C-W" backward-delete-word
65bindkey -- "\C-P" up-line-or-history
66bindkey -- "\C-N" down-line-or-history
67bindkey -- "\C-B" backward-char
68bindkey -- "\C-F" forward-char
69bindkey -- "\M-B" backward-word
70bindkey -- "\M-F" forward-word
71bindkey -- "${key[PageUp]}" beginning-of-buffer-or-history
72bindkey -- "${key[PageDown]}" end-of-buffer-or-history
73bindkey -- "${key[Shift-Tab]}" reverse-menu-complete
74
75# Finally, make sure the terminal is in application mode, when zle is
76# active. Only then are the values from $terminfo valid.
77if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
78 autoload -Uz add-zle-hook-widget
79 function zle_application_mode_start { echoti smkx }
80 function zle_application_mode_stop { echoti rmkx }
81 add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
82 add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
83fi