-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup_shell.sh
More file actions
executable file
·164 lines (146 loc) · 3.96 KB
/
setup_shell.sh
File metadata and controls
executable file
·164 lines (146 loc) · 3.96 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env bash
# ROOT=$(dirname $(pwd)/${(%):-%N})
ROOT=$(dirname ${(%):-%N})
_log() {
echo -e "[\033[32m"mishajw/dotfiles"\033[39m]" $@
}
_log "setting up shell ($ROOT)"
# env
export LANG=en_GB.UTF-8
export LANGUAGE="$LANG"
export LC_ALL="$LANG"
# globals
alias -g G='| grep'
alias -g Gi='| grep -i'
alias -g L="| less"
alias -g C="| wc -l"
alias -g Se="2>&1"
alias -g Ps="\$(ps -axo 'pid args' | awk 'NR!=1' | fzf | awk '{print \$1}')"
# apt-get
alias aget="sudo apt-get"
alias ai="aget install"
alias as="apt-cache search"
# brew
[ -e /opt/homebrew/bin/brew ] 1>/dev/null && eval "$(/opt/homebrew/bin/brew shellenv)"
alias b="brew"
alias bi="brew install"
alias bf="brew bundle --file ~/dotfiles/config/Brewfile dump -f"
# calc
_calc() {
if [[ "$#" == "0" ]]; then
echo "Usage: $0 <maths>"
return 1
fi
MATHS="$@"
python -c "from math import *; print($MATHS)"
}
alias calc="noglob py-calc"
# exa
if command -v exa 1>/dev/null; then
alias ls="exa --color=always"
alias ll="ls -l"
alias la="ls -la"
alias lt="ls -T"
fi
# git
alias g="git"
alias ga='git add'
alias gap='git add --patch'
alias gb='git branch'
alias gcam='git commit --amend'
alias gco='git checkout'
alias gd='git diff'
alias gds='git diff --staged'
alias gf='git fetch'
alias gl='git log --oneline --decorate'
alias glg='git log --oneline --decorate --graph'
alias gm='git merge'
alias gp='git push'
alias gpf='git push --force'
alias gpl='git pull'
alias gpsup='git push --set-upstream origin $(git_current_branch)'
alias grao='git remote add origin'
alias grb='git rebase --interactive --autosquash'
alias grba='git rebase --abort'
alias grbc='git rebase --continue'
alias grbh='git rebase --interactive HEAD~20'
alias gs='git status'
alias gsh='git show'
alias gshf='git show --name-only'
alias gsi='git submodule init'
alias gst='git stash'
alias gstd='git stash drop'
alias gstn='git stash push --message'
alias gstp='git stash pop'
alias gstsh='git stash show --patch'
alias gsu='git submodule update'
function gc() { git commit --message "$*"; }
function gca() { git commit --all --message "$*"; }
function gcf() { git log --oneline --author Misha | fzf | awk '{print $1}' | xargs -I% git commit --fixup %; }
function gcl() { git clone ssh://git@github.com/$*; }
function gbl() { git branch --list | fzf | sed 's/\\*//g' | xargs git checkout; }
g-rm-branch() {
current_branch=$(git rev-parse --abbrev-ref HEAD)
if ! git branch | grep -q "main"; then
echo "No main branch"
return 0
fi
if [[ "$current_branch" == "main" ]]; then
echo "Can't delete main branch"
return 0
fi
echo "Deleting branch $current_branch"
git checkout main \
&& git branch -D $current_branch
if git branch --all | grep -q "origin/$current_branch"; then
echo "Deleting remote branch $current_branch"
git push origin --delete $current_branch
fi
}
alias -g Gc="\$(\
git log --oneline --author \$(git config user.email) \
| fzf \
| awk '{print \$1}')"
alias -g Gb="\$(git branch | fzf | sed 's/*//g')"
# mac key overrides
if [ "$(uname)" != "Darwin" ]; then
bindkey "∆" history-beginning-search-forward
bindkey "˚" history-beginning-search-backward
bindkey "¬" forward-word
bindkey "˙" backward-word
fi
# make
m() {
if [ -f Makefile ]; then
make $@
elif [ -f package.json ]; then
npm run $@
elif [ -f poetry.lock ]; then
poetry run $@
else
make $@
fi
}
# pyenv
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
alias python="python3"
fi
# editors
export EDITOR="vim"
alias e="vim"
alias se="EDITOR=vim sudoedit"
# theme
setopt PROMPT_SUBST
PROMPT='%F{cyan}%c%f %F{red}${vcs_info_msg_0_}%f$ '
# oh-my-zsh
plugins=(zsh-fzf-history-search zsh-syntax-highlighting zsh-autosuggestions)
export ZSH=$HOME/.oh-my-zsh
source $ZSH/oh-my-zsh.sh
# misc
cdmk() { mkdir -p -- "$1" && cd -P -- "$1"; }
alias ".."="cd .."
alias reup="source ~/.zshrc"
[ -f $ROOT/local.sh ] && source $ROOT/local.sh
_log done