-
Notifications
You must be signed in to change notification settings - Fork 0
/
zsh.zshrc
147 lines (120 loc) · 3.87 KB
/
zsh.zshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Theme
ZSH_THEME="sharjeel"
# Enable Bashmarks
source ~/.local/bin/bashmarks.sh
# Set browser for commandline
if [ "$(uname)" = "Darwin" ]; then
BROWSER=open
elif which google-chrome > /dev/null 2>&1; then
BROWSER=google-chrome
elif which chromium-browser > /dev/null 2>&1; then
BROWSER=chromium-browser
elif which firefox > /dev/null 2>&1; then
BROWSER=firefox
else
BROWSER=lynx
fi
export BROWSER=$BROWSER
# History
SAVEHIST=10000
HISTSIZE=10000
setopt SHARE_HISTORY
# Alt-S inserts "sudo " at the start of line
insert_sudo () { zle beginning-of-line; zle -U "sudo " }
zle -N insert-sudo insert_sudo
bindkey "^[s" insert-sudo
# Alt-g inserts pipe grep
insert_grep () { zle -U " | grep -B0 -A0 " }
zle -N insert-grep insert_grep
bindkey "^[g" insert-grep
# Alt-i inserts "sudo apt-get install " at the start of line
insert_apt_get_install () { zle beginning-of-line; zle -U "sudo apt-get install " }
zle -N insert-apt-get-install insert_apt_get_install
bindkey "^[i" insert-apt-get-install
# Al-z inserts glob
insert_glob () { zle -U "**/" }
zle -N insert-glob insert_glob
bindkey "^[z" insert-glob
# C-x C-l inserts the last line of the output of the last command
zmodload -i zsh/parameter
insert-last-command-output() {
LBUFFER+="$(eval $history[$((HISTCMD-1))] | tail -n1)"
}
zle -N insert-last-command-output
bindkey "^X^L" insert-last-command-output
# cd into directory of a file
cdto () { cd `dirname $1`; }
# git diff between branches
gitdiff () { git diff $2 $1:$2; }
# show recent git branches
gitrecentbranches() { git for-each-ref --sort=-committerdate refs/heads/ }
alias git-recent-branches=gitrecentbranches
# Explain shell command
explain () {
echo "This will send data to external server? Continue (y/n)? "
read explain_decision
[[ ( $explain_decision == "y" || $explain_decision == "Y" ) ]] && $BROWSER "http://explainshell.com/explain?cmd=$*"
}
makeprint() {
make --eval="print-%: ; @echo \$*=\$(\$*)" print-$*
}
# There is only one default editor in the world
export EDITOR="emacsclient -nw --alternate-editor=emacs"
# if [ -n "$SSH_CLIENT" ]; then
# export EDITOR="emacs --no-window"
# else
# export EDITOR="emacs"
# fi
export TERM=xterm-256color
# Enable zsh-autosuggestions
if [ -e ~/.zsh-autosuggestions/autosuggestions.zsh ]; then
# Setup zsh-autosuggestions
source ~/.zsh-autosuggestions/autosuggestions.zsh
# Enable autosuggestions automatically
zle-line-init() {
zle autosuggest-start
}
zle -N zle-line-init
# use ctrl+t to toggle autosuggestions(hopefully this wont be needed as
# zsh-autosuggestions is designed to be unobtrusive)
bindkey '^T' autosuggest-toggle
export AUTOSUGGESTION_HIGHLIGHT_COLOR=fg=237
export AUTOSUGGESTION_HIGHLIGHT_CURSOR=0
fi
# gcloud
if [ -d $HOME/google-cloud-sdk/ ]; then
# The next line updates PATH for the Google Cloud SDK.
source "$HOME/google-cloud-sdk/path.zsh.inc"
# The next line enables bash completion for gcloud.
source "$HOME/google-cloud-sdk/completion.zsh.inc"
fi
export PATH=~/bin/:~/.local/bin/:~/.personalconfig/bin/:$PATH
# Common bashmarks directories
export DIR_persconf="$HOME/.personalconfig"
# Load personal aliases
source ~/.personalconfig/zshaliases.rc
# g aliased intelligently to bashmark get or git
g () {
if [ -z $1 ]; then
cat ~/.sdirs
if [ -e ~/.g4d ]; then
cat ~/.g4d
fi
return
fi
source $SDIRS
BASHMARK="$(eval $(echo echo $(echo \$DIR_$1)))"
if [ -e $BASHMARK ]; then
cd $BASHMARK
else
git "$@"
fi
}
# e for editing with emacs in a single window
e () {
if [[ -n "$DISPLAY" || ! -n "$SSH_CLIENT" ]]; then
emacsclient --no-wait --alternate-editor="$HOME/.personalconfig/bin/emacsserv.sh" $@
else
emacsclient -nw --alternate-editor="$HOME/.personalconfig/bin/emacsserv.sh" $@
fi
}