-
Notifications
You must be signed in to change notification settings - Fork 0
/
_alias
255 lines (213 loc) · 4.86 KB
/
_alias
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# ls
alias la='ls -lah'
alias ll='ls -lh'
# rm, mv, cp する時は確認する
alias rm='rm -i'
if (mv --help 2>&1 | grep '\--progress-bar' > /dev/null 2>&1;); then
alias mv='mv -ig'
else
alias mv='mv -i'
fi
if (cp --help 2>&1 | grep '\--progress-bar' > /dev/null 2>&1;); then
alias cp='cp -ig'
else
alias cp='cp -i'
fi
# よく間違えるねん
alias cd..='cd ..'
# tmux
alias tmux='tmux -u'
alias tm='tmux'
alias ta='tmux attach'
alias tl='tmux list-sessions'
# ssh
# 問題出るまではこれで誤魔化す
alias ssh='ssh -t'
# git
alias g='git'
alias ga='git add'
alias gb='git branch'
alias gba='git branch -a'
alias gci='git commit'
alias gco='git checkout'
alias gd='git diff --color'
alias gdc='git diff --color --cached'
alias gpl='git pull'
alias gp='git push'
alias gpf='git push --force-with-lease'
alias gst='git stash'
alias gsl='git stash list'
alias gsp='git stash pop'
alias gss='git status -s'
alias gsu='git submodule update --recursive'
alias gm='git merge --no-ff'
alias gcl1='git clone --depth 1'
# du/df
alias du='du -h'
alias df='df -h'
alias duh='du -h ./ --max-depth=1'
# su
alias su='su -l'
# less
alias less='less -iRM'
# (neo)?vim
if which nvim > /dev/null 2>&1; then
alias vim='nvim'
alias vimdiff='nvim -d'
fi
alias vi='vim'
# extract
alias ex='extract'
# locate
alias loc='locate'
# android emulator
alias emu="${ANDROID_HOME}/tools/emulator"
# docker-compose
alias d='docker compose'
# gnu ls
if ls --color > /dev/null 2>&1; then
alias ls='ls --color'
fi
# OS別の設定
case "${OSTYPE}" in
darwin*)
# java
alias javac='javac -J-Dfile.encoding=UTF-8'
alias java='java -Dfile.encoding=UTF-8'
# colordiff
alias diff='colordiff'
# spotlight locate
alias locate='mdfind -name'
# open
alias o='open'
# homebrew
alias brews='brew list -1'
alias bubo='brew update && brew outdated'
alias bubc='brew upgrade && brew cleanup'
alias bubu='bubo && bubc'
;;
linux*)
;;
esac
alias fp='realpath -s'
# colors
pcolor() {
for ((f = 0; f < 255; f++)); do
printf "\e[38;5;%dm %3d#\e[m" $f $f
if [[ $f%8 -eq 7 ]] then
printf "\n"
fi
done
echo
}
# xcolor (カラーコードの削除)
alias xcolor='sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"'
# tmux-ssh
function ssh() {
if [[ -n $(printenv TMUX) ]]; then
local window_name=$(tmux display -p '#{window_name}')
tmux rename-window -- "$@[-1]" # zsh specified
# tmux rename-window -- "${!#}" # for bash
command ssh $@
tmux rename-window $window_name
else
command ssh $@
fi
}
# tmux-sync
function tmux-sync() {
if [[ -n $(printenv TMUX) ]]; then
if (tmux show-options -w | grep -q 'synchronize-panes on'); then
MODE="off"
else
MODE="on"
fi
tmux set-window-option synchronize-panes ${MODE}
echo "synchronize-panes ${MODE}"
fi
}
alias ts='tmux-sync'
# ag
alias ag='ag --pager="less -iRM"'
function vag () {
vi -c "Ack \"$1\"";
}
# git checkout
function gcof() {
local branches branch
branches=$(git branch -vv) &&
branch=$(echo "$branches" | fzf-tmux +m) &&
git checkout $(echo "$branch" | awk '{print $1}' | sed "s/.* //")
}
# tree
alias tree='tree -N'
# jq
alias jq='jq -C'
# php codestyle fixer
function pfix() {
php-cs-fixer fix $1
phpcbf --standard=PSR2 $1
}
# location and copy
function xcp() {
xargs -d '\n' -I{} cp {} $1
}
# check certificate
function check_cert() {
IPADDR=$1
DOMAIN=$2
if [ ! $DOMAIN ]; then
DOMAIN=$IPADDR
fi
openssl s_client -connect $IPADDR:443 -servername $DOMAIN < /dev/null 2>&1 | openssl x509 -text | egrep '(Not (Before|After)|Subject:|DNS)'
}
function hash_cert() {
CERT_FILE=$1
openssl x509 -in "$CERT_FILE" -pubkey -noout -outform pem | sha256sum
}
function hash_pem() {
PEM_FILE=$1
openssl pkey -in "$PEM_FILE" -pubout -outform pem | sha256sum
}
function hash_csr() {
CSR_FILE=$1
openssl req -in "$CSR_FILE" -pubkey -noout -outform pem | sha256sum
}
# update dotfile
function gitignore-update() {
if which gibo > /dev/null 2>&1; then
gibo update
gibo dump Dropbox Eclipse Emacs Linux macOS Vim VirtualEnv Xcode VisualStudioCode Windows > ~/dotfiles/_git/gitignore
cat ~/dotfiles/_git/my.gitignore >> ~/dotfiles/_git/gitignore
fi
}
function dot-update() {
OLD_DIR=`pwd`
# update dotfiles
cd ~/dotfiles && git pull
# update zsh plugins
sheldon lock --update
# update neovim plugins
nvim --headless "+Lazy! update" +qa
nvim --headless "+TSUpdate" +qa
# update python dependencies
if which pip3 > /dev/null 2>&1; then
dependencies=(
pip poetry
# neovim
pynvim neovim
)
pip3 list -o --format=json | jq -r '.[].name' | xargs pip3 install -U "${dependencies[@]}"
fi
# update nodejs dependencies
if [ ${EUID:-${UID}} != 0 ]; then
npm -g update
fi
cd "$OLD_DIR"
}
function prompt() {
PROMPT='$ '
PROMPT2=''
SPROMPT=''
RPROMPT=''
}