-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path.alias
473 lines (420 loc) · 14.3 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
#*******************************************************************************
#
# .alias
#
# 現在設定されているaliasを調べる
# $ alias [コマンド名]
# typeコマンドでもaliasが表示される
# $ type [-a] <コマンド名>
# aliasを無効にして実行
# $ \cmd
# alias/シェル関数を無視して実行
# $ command cmd
# 全てのシェル変数を表示
# $ declare
# 関数の名前/定義を表示
# $ declare -f <関数名>
#
#*******************************************************************************
alias where="command -v"
alias jl="jobs -l"
# Exit
alias cl='clear'
alias quit='exit';
# ls
# Macではglsを使用
#
# Common option
# -l 詳細な情報の表示
# -a 隠しファイルを表示
# -h サイズをkB, MB, GBとかで表示
# -d ディレクトリ自体の情報を表示
# -t ファイルの変更日時でソート(古い順:最新が上にくる)
# -r 逆順ソート
# -F ファイルタイプを示す文字を表示
# * 実行可能ファイル
# / ディレクトリ
# @ シンボリックリンク
#
# Mac ls only
# -G ls:カラー有効
# -v 非印字文字を強制表示
# -T タイムスタンプを年月日時分秒まで表示
#
# GNU ls only
# -G : グループを非表示。
# -v : natural sort of (version) numbers within text (gls only)
# --time-style=STYLE : タイムスタンプの表示スタイル (gls only)
# --show-control-chars : Show non graphic characters as-is.
# --width=COL : Assume screen width instead of current value.
# --group-directories-first : Group directories before files.
case "${OSTYPE}" in
freebsd*|darwin*)
if type gls > /dev/null 2>&1; then
alias ls='gls -aFhv --color=auto --show-control-chars --group-directories-first'
alias ll='ls -l --time-style=long-iso'
else
alias ls='ls -aFGhv'
alias ll='ls -lT'
fi
;;
linux*)
alias ls='ls -aFh --color=auto'
alias ll='ls -l'
;;
esac
alias lld='ls -d'
alias llt='ll -rt'
alias lll='ll | less'
# cd
# -P シンボリックリンクをたどらず実ディレクトリに移動
# -L シンボリックリンクをたどったディレクトリに移動
lvalue='.'
rvalue=''
for index in {1..9}; do
lvalue="${lvalue}."
rvalue="${rvalue}../"
alias "$lvalue"="cd $rvalue"
done
unset lvalue rvalue index
alias cdp='cd -P'
alias cdl='cd -L'
# cd <ファイル名> で親ディレクトリに移動
cd() {
if [ -e "$1" -a ! -d "$1" ]; then
builtin cd -- "$(dirname -- "$1")"
else
builtin cd "$@"
fi
}
# pwd
# -P シンボリックリンクをたどらず実ディレクトリを表示
# -L シンボリックリンクをたどったディレクトリを表示
alias pwd='pwd -P'
# df/du
alias df='df -h'
alias du='du -h'
alias dus='du -s'
alias ddu='du -sm ./* | sort -n | tail'
# mv rm cp
# 確認つきファイル操作
# rm, mv, cp などのあぶない操作を確認つきにする
alias mv='mv -i'
alias rm='rm -i'
alias cp='cp -ir'
alias mvi='mv -i'
alias rmi='rm -i'
alias cpi='cp -ir'
# cp
# -p コピー元の所有者、所有者・グループ・アクセス権・アクセス時刻などを維持
# -a コピー元の所有者などの属性、パーミッション 、ディレクトリ構造、
# シンボリックリンクなど、「コピー可能なファイルでコピー可能なものを、
# 可能な限りコピー元の情報をそのままるコピーする」-dpR と同じ
alias cpa='cp -a'
# grep
# -i 大文字小文字を区別しない
# -n 各行の先頭にファイルの行番号を表示します
# -H ファイル名を表示
# -E オプションは、拡張正規表現を使用する場合に指定
# fgrep 正規表現を使わない検索
# egrep 正規表現を使った検索 -E と同じ
# -R, -r, --recursive ディレクトリを再帰的にたどる
# -I バイナリ検索除外(--binary-files=without-match)
# -w 単語マッチ
# --color=[WHEN]
# always: パイプ使用時に強制的にカラーコードをつける
# auto : 出力先に応じて判断 - パイプ時などはカラーコードをつけない
# never : カラーコードOFF
# --directories=recurse grep対象にディレクトリを指定し場合再帰grep(ver2.5.4 or later)
# -q, --quiet, --silent 通常の出力を抑止
# -s, --no-messages ファイルが存在しないことや読み込みできないことを示すエラーメッセージを抑止
#
# 環境変数GREP_OPTIONSにデフォルトオプションを設定
#
# e.g.
# & grep -r searchword --include'*.txt' .
if grep --help 2> /dev/null | grep -q -- --exclude-dir; then
# svn/gitディレクトリを無視
alias grep='grep -niE --exclude-dir=.svn --exclude-dir=.git'
else
alias grep='grep -niE'
fi
alias grepr='grep -R'
# grepの結果をviで表示(gfやgFでカーソル下のファイルへジャンプ)
grepv () {
grep "$@" | \vim -R -
}
# find
#alias find=gfind
alias findbig='find . -type f -exec ls -s {} \; | sort -n -r | head -5'
alias findmod='find . -type f -mmin -10'
alias lsthumbs='find . -type f -name 'Thumbs.db' -print0 | gxargs -0 ls -a'
alias delthumbs='find . -type f -name 'Thumbs.db' -print0 | gxargs -0 rm -f'
# e.g.
# find -name '*' -exec grep -n 'name' {} /dev/null ¥;
# find . -name \*.c -print0 | xargs -0 grep hogehoge /dev/null
# find . -name "*hoge" -type f | grep -v '\.svn' | xargs grep piyopiyo
# find . -name \( -name "*.c" -o -name "*.cpp" -o -name "*.h" \) | xargs grep hoge
#
# xargs -0 : 空白と改行ではなくヌル文字 (``\0'') を区切りとするように xargs に指示
# find(1) の -print0 とともに使用
# -print0 : デリミタ文字 (シングルクォート 、ダブルクォート、バックスラッシュ 、
# スペース、タブ、改行) が含まれるファイル名でも正常に動くHL
#
# ディレクトリ名やファイル名にスペースを含んでいる場合、 find と xargs を
# そのまま実行すると、スペースの前後で別々にxargsの引数として処理され、
# 正常に動作しない。
# そこで、スペースを区切り文字にするのではなく(null)を区切り文字にするとで
# 問題なく正常に動作できる
# history
alias h='history 32'
# 全履歴を表示
history_all() { history -E 1 | less; }
# od
# 16進数でのバイナリダンプコマンド
# -tx1 1バイトごとに区切って表示
# -Ax アドレスを16進数表示
# -v 連続する0をスキップしない
#
alias od='od -tx1 -Ax -v'
# 改行コード判定に使用
alias oc='od -c'
# chmod
# 644 rw-r--r-- ユーザ専用ファイル
# 755 rwxr-xr-x ディレクトリ
alias 644='chmod 644'
alias 755='chmod 755'
# ps
# -a すべてのユーザを対象にする
# -u 実行したユーザを表示
# -x デーモンを表示
# -f fork(フォーク:分岐)-プロセスの親子関係を表示(Mac非対応)
# -w 表示幅をオーバしても改行して表示する
# -L List the set of keywords available for the -O and -o options.
alias psa='ps auxw'
alias pspgid='ps axwww -o "ppid pgid pid user fname args"'
alias iops='ps auxwwww -L|awk "\$10 ~ /(D|STAT)/{print}"'
# top (for FreeBSD/Mac)
# -o rsize メモリ使用量でソートして表示
# -o cpu CPU使用率順に表示
# -O time セカンダリソートを実行時間
# -u "-o cpu -O time"と同じ
# -R -F topコマンドの負荷軽減
alias topm='top -o rsize'
alias topc='top -R -F -u'
# diff
# -r ディクレクトリの再帰検索
# -t 入力ファイルでのタブによる位置あわせを保存するため、 出力のタブをスペースに展開
# -b 空白・タブの数の違いを無視
# -B 空行の有無を無視
# -E タブ展開によるスペースの変更を無視する
# -a テキストファイルとして比較
# -q 差分があるかどうかだけを報告し詳細を報告しない
# -u unified diff形式で出力
# --exclude=xx
alias dif='diff -tbBE'
alias diffr='diff -r --exclude=.git --exclude=.svn'
# curl
# -O ファイルはローカルに保存
# -L リダイレクトを有効
# --max-redirs=10 リダイレクト回数の上限(デフォルト:50) -Z <回数> と同様
# -k 安全ではないSSLを許可
# -f サーバーエラー時に何も出力しない(エラーページなどをDLしない) 代わりににエラー番号22を返す
# -s プログレスメータやエラーメッセージを出力しない(silent)
# -S -sと併用、失敗時にエラーメッセージを出力
# -# プログレスバー表示(DL詳細は見えなくなる)
# -v 詳細表示
alias cur='curl -OLv'
alias curr='curl -OLkfsS'
# rsync
# options are:
# -a - archive mode
# -v - increase verbosity
# -z - compress file data during the transfer
# -u - skip files that are newer on the receiver
# -p - preserve permissions
# -o - preserve owner
# -g - preserve group
# -h - output in human-readable format
# --progress - display progress
# -b - instead of just overwriting an existing file, save the original
# --backup-dir=/tmp/rsync - move backup copies to "/tmp/rsync"
# -e /dev/null - only work on local files
# -- - everything after this is an argument, even if it looks like an option
alias rsync='rsync -avzu'
alias cpv="rsync -poghb --backup-dir=/tmp/rsync -e /dev/null --progress --"
# tcpdump
# options are:
# -n : Don't convert address to names.
# -s : Data length (default: 65535, if setting snaplen to 0 sets it to the default of 65535)
# -i <eth0> : Listen on interface.
# -w : Write the raw packets to file.
# -X : print the data of each packet in hex and ASCII.
#
# port <PORT> : Port number.
# host <ADDRESS> : IP adress.
# <...> and <...>
alias tcpdump80='tcpdump port 80 -n -s 0'
# strace
alias strace_x='strace -s 9999 -fttTCxv'
# date
alias dates='date "+%Y-%m-%d %T.%N"'
alias today="date '+%Y%m%d'"
alias today_="date '+%Y-%m-%d'"
alias now="date '+%Y%m%d_%H%M%S'"
alias now_="date '+%Y-%m-%d_%H%M%S'"
# Japanese env
# ロケールに関する環境変数をすばやく切替えるためのエイリアス
alias utf='export LANG=ja_JP.UTF-8; export LANGUAGE=ja_JP.UTF-8; export LC_ALL=ja_JP.UTF-8'
alias en='export LANG=en; export LANGUAGE=en; export LC_ALL=en'
# iptables
alias liptables='iptables -L -n --line-numbers'
# sudo スーパーユーザへ
alias ssu='sudo -s'
# PATH
# 改行区切りで表示
alias printpath='echo $PATH | tr ":" "\n"'
# 重複削除
alias organize_path='tr ":" "\n" | uniq | paste -d: -s -'
# lv
# -c カラー表示対応
# -l 行番号表示
alias lv='lv -cl'
# tree
# -N 日本語文字化け対応
# -a 隠しファイルも表示
# -I 例外設定(ワイルドカード)
# -F ファイルの種類を表示
alias tree="tree -F -N -a -I '.git|.svn'"
# man
# jman 日本語(FreeBSD系)
# http://www.fan.gr.jp/~sakai/softwares/unix#wordhighlight_id18
# lman 日本語(JM Project - Linux/GNU系)
# http://linuxjm.sourceforge.jp/
# wman ~/work/usr/local 配下にインストールしたコマンドのman
if type jman >/dev/null 2>&1; then
alias jman='env LANG=ja_JP.UTF-8 jman'
alias lman='env LANG=ja_JP.UTF-8 jman -M ~/work/usr/local/share/man'
fi
# ~/work/usr/local配下のコマンドのman
alias wman='env LANG=C command man -M ~/work/usr/local/share/man'
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[31m") \
LESS_TERMCAP_md=$(printf "\e[31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[33m") \
man "$@"
}
# ack
# 高機能検索(find + grep)
# -a 全てのファイルから検索(拡張子無しも含む) ただし--TYPEが無効
# -i 大文字小文字区別なし
# --pager 結果を開くPAGER(less,vim)
# --TYPE or --type=TYPE プログラミング言語に応じたタイプ指定
# 参照:$ ack --help-type
# --nogroup 検索結果をファイルごとにグループ化しない
# -f ファイル検索(find)
# -w 単語検索
# -G filter 検索対象のファイルパスを正規表現指定
# -g filter ファイル検索(find)(正規表現)(-f -G に同じ)
# -C n 一致した行の前後n行を表示
# -B n 前n行を表示
# -A n 後n行を表示
# -l 一致したファイル名のみ出力
# -L 一致していないファイル名を出力
# -n 再帰検索しない
# ※デフォルトオプション: ~/.ackrc
# e.g.
# $ ack 'pattern' -G .*\.txt
# $ ack hoge -G "\.(c|cpp|h)$"
alias acka='ack -a'
alias ackn='ack -n'
# ackの結果をviで表示(gfやgFでカーソル下のファイルへジャンプ)
ackv () {
ack "$@" | \vim -R -
}
# ag
# -z : Search in achives.
# -G <PATTERN>: Only search file names matching PATTERN
alias ag='ag -S --stats --pager "less -F"'
alias agh='ag --hidden'
agv () {
\ag -S --stats --nogroup "$@" | \vim -R -
}
# hw (highway)
#
alias hw='hw -i'
hwv () {
\hw -i --nogroup --no-color "$@" | \vim -R -
}
# nkf
# -g 文字コード判定
# $$: シェル自身のプロセスID
# >!: 強制上書き
#
# 文字コードを判定
alias nkfg='nkf -g'
# utf-8-LF
utf8() {
for i in "$@"; do
nkf -w -Lu $i >! /tmp/euc.$$
mv -f /tmp/utf8.$$ $i
done
}
# euc-LF
euc() {
for i in "$@"; do
nkf -e -Lu $i >! /tmp/euc.$$
mv -f /tmp/euc.$$ $i
done
}
# sjis-CRLF
sjis() {
for i in "$@"; do
nkf -s -Lw $i >! /tmp/euc.$$
mv -f /tmp/euc.$$ $i
done
}
# encode64
encode64(){ echo -n "$1" | base64; }
decode64(){ echo -n "$1" | base64 -D; }
# rmtrash
alias rmt='rmtrash'
# Make a directory named date and move in it.
make_date_dir_and_cd() {
mkdir "$(date +'%Y%m%d')" || return 1
cd "$(date +'%Y%m%d')"
}
alias mkdd='make_date_dir_and_cd'
# Make directories and cd it.
take() {
mkdir -p "$1" && cd "$1"
}
# Make archive.
alias mkzip='zip -q -r'
mktar() {
[ -z "$1" ] && return 1
[ -e "$1" ] || return 1
tar czf "$1.tar.gz" "$1"
}
# http://d.hatena.ne.jp/hirose31/20130227/1361929795
https2text() { # FQDN[:PORT]
case $1 in
*:*)
URL=$1
;;
*)
URL="$1:443"
;;
esac
echo | openssl s_client -connect $URL 2>/dev/null | \
sed -n -e '/BEGIN /,/END /p' | \
openssl x509 -text
}
# Complete Messages.
echo "Loading .alias completed!!"
# vim: ft=sh sw=4 sts=4 ts=4 et