-
Notifications
You must be signed in to change notification settings - Fork 0
/
.alias
235 lines (219 loc) · 8.25 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
### navigation
##############
# default to colorsl if available
if command -v lsd >/dev/null 2>&1; then
alias l='lsd -gl'
alias ll='lsd -gal'
alias lt='lsd -gltr'
alias llt='lsd -galtr'
else
alias l='ls -Flh'
alias ll='ls -Flah'
alias lt='ls -Flthr'
alias llt='ls -Flathr'
fi
# create folder and cd into it
md () { mkdir -p $1; cd $1 }
alias rd='trash'
alias undelete="trash-restore"
# Empty the Trash on all mounted volumes and the main HDD.
# Also, clear Apple’s System Logs to improve shell startup speed.
# Finally, clear download history from quarantine. https://mths.be/bum
alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl; sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'"
alias ..='cd ..'
alias ,,='git rev-parse --git-dir >/dev/null 2>&1 && cd `git rev-parse --show-toplevel` || echo "Not in git repo"'
alias dus='du -d 1 -h | sort -h'
if [[ `uname` == "Darwin" ]]; then
alias df="df -h"
else
alias df="df -h --total"
fi
if [[ "$(uname)" == "Linux" ]]; then
alias root='sudo -E zsh' # keep $SSH_CLIENT to show remote connections
elif [[ "$(uname)" == "Darwin" ]]; then
alias root='sudo zsh'
fi
alias t='cd /tmp'
alias o='open .'
alias tgz='COPYFILE_DISABLE=true tar -c --exclude=.git --exclude=.DS_Store -zvf '
alias x="unarchive"
alias errorcode="echo $?"
alias p="ps aux G "
(( $+commands[fd] )) && alias fda="fd --hidden --no-ignore"
# fasd
alias v='f -e vim' # quick opening files with vim
alias c='z'
alias co='f -e code ' #quick opening files with code
# search
alias rg="rg -S --max-columns 444"
alias rgh='rg --hidden '
alias rga='rg --hidden --no-ignore --search-zip'
# Globals
alias -g G="| rg -v 'rg -S' | rg "
alias -g GC="| rg -v 'rg -S' | rg -C 5 "
alias -g L="| less"
alias -g J="| jq"
alias -g C="| wc -l"
alias -g F="| fzf --multi"
### GIT stuff
#############
alias gs='git status -s'
alias gu='git submodule update --init --recursive --remote'
alias gd='git diff'
alias gf='git fetch --all --prune'
alias ga='git add'
alias gl='git pull'
alias gp='git push'
alias co='git submodule foreach git checkout'
commit () { git commit -v -m "$*" }
alias gc='noglob commit'
# show a nice version of the git graph
alias gg="git log --remotes --tags --oneline --decorate --stat --abbrev-commit --date=relative --branches --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n'"
diff_so_fancy () { diff -u "$@" | diff-so-fancy }
alias diff="diff_so_fancy"
alias gfi='find . -type f | grep -v .venv | grep -v .idea | grep -v .direnv | grep -v migrations | grep -v static | grep -v __ | git check-ignore -v --stdin' # find files ignored by git and the reason why
alias grm="git branch --merged | grep -v \"\*\" | xargs -n 1 git branch -d" #remove merged branches
### sane defaults / utilities
#############################
# Disable globbing for some tools
alias poetry='noglob poetry'
alias pip='noglob pip'
alias wget="noglob wget"
alias sudo='sudo -s "PATH=$PATH"' # Enable aliases and shell functions to be sudo’ed
alias please='sudo "PATH=$PATH" zsh -c "$(fc -ln -1)"' # rerun the last command with sudo (because it failed)
alias cp='cp -iv'
function mv() {
if [[ "$#" -ne 1 ]] || [[ ! -f "$1" ]]; then
command mv -iv "$@"
return
fi
new_filename="$1"
vared new_filename
command mv -iv -- "$1" "$new_filename"
}
which() {
local format="${2:-path}" # Default to path output
if [[ "$1" = "--full" ]]; then
format="full"
shift 1
fi
IFS=$'\n'
set -f
found=false
for LINE in $(type -a "$1" 2>/dev/null); do
if [[ "$LINE" == "$1 is an alias for "* ]]; then
alias_def=$(echo "$LINE" | sed -E "s/^$1 is an alias for //")
found=true
if [[ $format == 'full' ]]; then
echo "$1 is an alias for $alias_def"
fi
else
COMMAND=$(echo "$LINE" | awk '{print $NF}')
if [[ $COMMAND = /* ]]; then
version=$("$COMMAND" --version 2>/dev/null)
[[ -n $version ]] && version="($version)"
found=true
if [[ $format == 'full' ]]; then
echo "$1 is $COMMAND $version"
ll "$COMMAND"
else
echo "$COMMAND"
break
fi
fi
fi
done
if [[ $found = false ]]; then
return 1
fi
}
alias wi="which --full"
### shortcuts
#############
alias update-dotfiles="~/ghar/dotfiles/misc/update.sh"
alias stree='open -a SourceTree .'
alias csv='column -s, -t'
alias wetter='curl wttr.in/Berlin'
alias tm='tmux attach || tmux new'
alias getmp3="youtube-dl -x --audio-format mp3 "
# Hide/show all desktop icons (useful when presenting)
alias hidedesktop="defaults write com.apple.finder CreateDesktop -bool false && killall Finder"
alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder"
sleep-in() { echo "Going to sleep in $1 minutes .." && sleep $((60 * $1)) && pmset sleepnow }
# Faster npm for Europeans
command -v npm > /dev/null && alias npme="npm --registry http://registry.npmjs.eu/"
alias ping="prettyping --nolegend"
(( $+commands[bat] )) && alias cat="bat --theme TwoDark --style=plain --paging never"
(( $+commands[fzf] )) && alias preview="fzf --preview 'bat --style=numbers --color=always --line-range :500 {}'"
(( $+commands[gsed] )) && alias sed="gsed"
(( $+commands[gtar] )) && alias tar="gtar"
(( $+commands[glances] )) && alias top="glances"
(( $+commands[gdate] )) && alias date="gdate"
### Python / Django
###################
alias ipy="python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'"
alias shell='python manage.py shell_plus'
alias rs="manage.py runserver 0.0.0.0:8000"
alias idea='open -a "IntelliJ IDEA"'
alias update-venv="pip install -U pip setuptools wheel"
alias init-python="update-venv && pip install -U poetry twine bumpversion isort black httpie magic-wormhole"
function jwt() {
for part in 1 2; do
b64="$(cut -f${part} -d. <<< "$1" | tr '_-' '/+')"
len=${#b64}
n=$((len % 4))
if [[ 2 -eq n ]]; then
b64="${b64}=="
elif [[ 3 -eq n ]]; then
b64="${b64}="
fi
d="$(openssl enc -base64 -d -A <<< "$b64")"
echo "$d" | jq
# don't decode further if this is an encrypted JWT (JWE)
if [[ 1 -eq part ]] && grep '"enc":' <<< "$d" >/dev/null ; then
return 0
fi
done
}
# URL-encode strings
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'
# Recursively delete `.DS_Store` files
alias cleanup="find . -type f -name '*.DS_Store' -ls -delete && find . -name __pycache__ -print -delete && find . -name '*.pyc' -ls -delete"
### network
###########
# Start an HTTP server from a directory, optionally specifying the port
function seecert () {
nslookup $1
(openssl s_client -showcerts -servername $1 -connect $1:443 <<< "Q" | openssl x509 -text | grep -iA2 "Validity")
}
function server() {
local IP=`localip`
local port="${1:-8000}";
echo "http://$IP:$port/"
python -m http.server ${port}
}
alias send="woof"
# get public/local IP addresses
alias ip="curl -s https://ifconfig.co/json J"
alias ip4="curl -4 -s https://ifconfig.co/json J"
alias ip6="curl -6 -s https://ifconfig.co/json J"
alias ips="ifconfig -a | grep -o 'inet\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet? (addr:)? ?/, \"\"); print }' | grep -v 127.0.0.1"
alias localip="ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' | head -n 1"
function digga() {
dig +nocmd "$1" any +multiline +noall +answer;
}
alias get='curl --continue-at - --location --progress-bar --remote-name --remote-time'
# Flush Directory Service cache
alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder"
# View HTTP traffic
alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
alias info="neofetch"
rick () { echo "$*" | chatgpt -i "Du bist Rick, von Rick und Morty. Antworte auf Fragen in seinem Stil und verwende beleidigende und sexistische Witze." }
dead () { echo "$*" | chatgpt -i "Du bist Deadpool und antwortest mit dem Charm von Rick Reynolds." -t 0.77 }
chat () { echo "$*" | chatgpt }
alias h='noglob dead'
gpt() { sgpt "$*" }
gpts() { sgpt -s "$*" }
alias sg="noglob gpt"
alias sgs="noglob gpts"