-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
aliases
136 lines (112 loc) · 3.74 KB
/
aliases
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
#!/bin/sh
#
# File: .aliases
# Description:
# contains all aliases defined by the user. Separated from shell rc files
# for portability between different machines.
# Avoid syntax and commands not portable to other different setups,
# check out http://hyperpolyglot.org/unix-shells for more information
# checks if argument exists in path
exists() { command -v $1 &>/dev/null }
is_zsh() { [ -n "$ZSH_VERSION" ] }
is_darwin() { [ $(uname) = Darwin ] }
# ls
# order of output:
# symbols, UPPERCASE, lowercase (folders first)
unalias ls 2>/dev/null
unfunction ls 2>/dev/null
is_darwin && {
alias l='LC_COLLATE=C gls -h --color=always --dereference-command-line-symlink-to-dir --group-directories-first'
} || {
alias l='LC_COLLATE=C ls -h --color=always --dereference-command-line-symlink-to-dir --group-directories-first'
}
alias ll='l -lF'
alias la='l -A'
alias lla='ll -AF'
# safe copy, move and delete
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -I'
if is_darwin; then
unalias rm 2>/dev/null
! exists grm || alias rm='command grm -I'
fi
# directories
unalias mkdir 2>/dev/null
alias md='mkdir -p'
alias rd='rmdir'
alias po='popd'
alias pu='pushd'
# hdd
is_darwin && alias df='df -h' || alias df='df -h -x squashfs'
alias du='du -h'
# summary of disk used by child items sorted and unsorted
alias dus='LANG=C du -s *'
alias duss='dus | LANG=C sort -h'
# disk space used by system folders
alias dusss="LANG=C du -s /{{boot,lib*,opt,sbin,tmp,usr,var}/*(N),{bin,etc,root}} 2>/dev/null | grep -vE '^(0|[0-9.]+K)' | LANG=C sort -h"
alias diff='command diff -u --color'
# sudo aliases
alias sudo='sudo ' # expand aliases after sudo
alias usersu='sudo -E -s' # preserve environment (-E option) when login as root
alias sudoit='sudo env PATH="$PATH" ' # preserve user PATH
## git
alias gap='git add -p'
alias gdw='git diff -w'
alias gds='git diff --staged'
alias gdsw='git diff --staged -w'
# git fetch
alias gf='git fetch --prune'
alias gfa='gf --all'
alias gpll='git pull'
alias gpsh='git push'
# git push
alias gpa='git push --all'
alias gpfa='git push --force-with-lease --all'
# prune remote branches
alias gpp='git push --prune --all'
# git pretty log
alias gl='git log --oneline --graph --decorate --color'
alias gla='git log --oneline --graph --decorate --color --all'
# Adds author and relative commit date
alias glg='git log --graph --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %Cblue<%an>%Creset" --abbrev-commit --date=relative'
alias glga='git log --graph --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %Cblue<%an>%Creset" --abbrev-commit --date=relative --all'
# git reset
alias grhs='git reset --soft'
alias 'grh!'="git reset --hard"
unalias grhh 2>/dev/null
## utilities
# open with system default application
alias o='open_command'
alias o.='o .'
# enable advanced calculation in bc by default
alias bc='bc -l'
# default parameters for youtube-dl
alias ytdl='youtube-dl --prefer-ffmpeg -o "%(title)s.%(ext)s"'
# terminating global aliases
is_zsh && {
alias -g :L='| command less'
alias -g :H='| command head'
alias -g :T='| command tail'
alias -g :G='| command grep'
alias -g :Gh="| command grep --color=always -e '\$' -e " # only highlight provided string
alias -g :LL='2>&1 | command less'
alias -g :NE='2>/dev/null'
alias -g :NO='1>/dev/null'
alias -g :NUL='&>/dev/null'
}
# ip command
alias ip='ip -color'
alias ipb='ip -color -brief'
# Visual Studio Code
if exists code-insiders; then
alias vsc='code-insiders'
alias 'vsc.'='code-insiders .'
elif exists code; then
alias vsc='code'
alias 'vsc.'='code .'
fi
alias ohmyzsh='vsc "${ZSH:A}"'
alias zshrc='vsc "$(readlink "${ZDOTDIR:-$HOME}/.zshrc")"'
# last exit status
alias '?'='echo $?'