-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.aliases
225 lines (184 loc) · 6.76 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
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
### aliases #####################################
if [[ "${OSTYPE}" == "linux"* ]] || [[ $OSTYPE == cygwin ]]; then
alias ls='ls -F --color=auto -I "NTUSER.DAT*" -I "ntuser.dat*" '
alias sed='sed -r'
# if encountering Mac/BSD scripts...
# alternative: sudo ln -s $(which date) /bin/gdate
# `ln` works across system/shell, unlike alias
alias gfind='find'
alias gdate='date'
#alias gsed, gtar, gmake
# Export pbcopy / pbpaste to linux
alias pbcopy="xclip -selection clipboard"
alias pbpaste="xclip -selection clipboard -o"
# MAC OSX/BSD
elif [[ "${OSTYPE}" == "darwin"* ]]; then
# alias flush='dscacheutil -flushcache'
# browser
#alias browse="open -a /Applications/Google\ Chrome.app"
#alias google="browse https://google.com"
# Open current OSX Finder directory in Terminal:
# faster than dragging from finder to terminal
cdf () {
target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
if [ "$target" != "" ]
then
cd "$target"
pwd
else
echo 'No Finder window found' >&2
fi
}
alias ls='ls -GF'
alias sed='sed -E'
fi
# ls, remembers alias cascades.
alias l="ls"
# or use l()
alias ll="ls -lh"
alias lla="ls -lhA"
alias la="ls -A"
# show only dir
alias lsd="ls -d */"
# show hidden files / dotfiles only
alias lsh="ls -ad .*"
alias tree='tree -FC --dirsfirst -I ".git"'
# tree: color, dirFirstignore .git/*
alias du="du -h"
alias du1="du -h --max-depth=1"
alias du2="du -h --max-depth=2"
alias df="df -h"
alias h="history"
# alias f="find . -name"
function f() { find . -iname "*$@*" ! -name ".git*" | sed 's|^./||' ; }
# alternative: `fd`
# Quicker navigation
alias ~="cd ~"
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
# mkdir and cd into it
# comment: https://news.ycombinator.com/item?id=18898523
mcd() { mkdir -p "$@" && builtin cd "$@"; }
# renamed from mdc and mkcd to mcd()
# after cd, list files
# comment: https://news.ycombinator.com/item?id=18898523
# removed, for now, no need to see it all the time
# perhaps rename it to cdl instead of cd
# function cd {
# builtin cd "${@}"
# if [[ "$(stat -c "%b" .)" -lt "100" ]]
# then
# if [ "$( ls -C -w $COLUMNS | wc -l )" -gt 30 ] ; then
# ls -C -w $COLUMNS --color=always | awk 'NR < 16 { print }; NR == 16 { print " (... snip ...)" }; { buffer[NR % 14] = $0 } END { for( i = NR + 1; i <= NR+14; i++ ) print buffer[i % 14] }'
# else
# ls
# fi
# fi
# }
# open a file with less or a directory with ls
# comment: https://news.ycombinator.com/item?id=18898523
# zsh complains about alias
# l() { if [ -f "$1" ]; then less "$1"; else command ls "${1:-`pwd`}"; fi }
# Colored up cat!
# You must install Pygments first - "sudo easy_install Pygments"
# TODO: change it with bat or another app
alias c='pygmentize -O style=monokai -f console256 -g'
# grep
#color grep
#alias grep='GREP_COLOR="1;37;45" grep --color=auto'
# replaced grep with egrep (or grep -E for extended regex)
alias grep='GREP_COLOR="1;37;45" egrep --color=auto'
# [command line - Testing regex from stdin using grep|sed|awk - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/368211/testing-regex-from-stdin-using-grepsedawk)
# stdin to test if regex is working
# $ testregex 'hello world'
# [aeiou]+ (STDIN)
#
testregex() {
[ "$#" -eq 1 ] || return 1
while IFS= read -r line; do
# print only matching on its own line
# printf '%s\n' "$1" | grep -Eoe "$line"
# print matching in one line, highlighted by color
printf '%s\n' "$1" | grep -Ee "$line"
done
}
# otter.pro: colored pygmentized less
# replaced with .lessfilter script.
# if LESS="-x4R" is not set, use less -x4R option. -N=line #.
#cl() {
# pygmentize -O style=monokai -f console256 -g "$1" | less
# c "$1" | less
#}
# Shortcuts to my Code folder in my home directory
#alias code="cd ~/Code"
#alias sites="cd ~/Code/sites"
# TODO: need to convert to function, as it doesn't function
# due to alias sudo defined below
# alias sudo vi='sudo -e'
# alias sudo vim='sudo -e'
# Enable aliases to be sudo’ed
# if not, aliases are lost when using sudo
alias sudo='sudo '
# mac specific
if [[ $OSTYPE == darwin* ]]; then
# $preview this.png
alias preview="open -a Preview"
#alias s='open -a "Sublime Text"'
#
# v is already used by ~/bin/v
# which should open file in new tab in existing MacVim window
#
# simple macvim, -p = use tab to open multiple files
# Not sophisticated as ~/bin/v since it opens new MacVim instead of reusing
# mvim not working in certain situation, so I added alias here
# Remove this line if mvim won't load properly
#alias mvim="/Applications/MacVim.app/Contents/MacOS/MacVim"
#alias mvim="/Applications/MacVim.app/Contents/MacOS/bin/gvim"
alias mvim="/Applications/MacVim.app/Contents/bin/gvim"
# normal mvim
alias vi="mvim -p"
alias v="mvim -p"
alias vim="mvim -p"
#elif [[ $OSTYPE == freebsd* ]]; then
else
alias vi='vim'
alias v='vim'
fi
#vi read-only (there's already a /bin/view)
#alias view="vim -p -R"
######## Git ##################################################
# You must install Git first - ""
alias g="git"
alias gs='git status'
alias ga='git add -A'
alias gc='git commit -m' # requires you to type a commit message
alias gac='git add -A && git commit -m' # requires you to type a commit message
alias gp='git push'
alias gd='git diff'
# go to root git directory
alias cdgit='builtin cd $(git rev-parse --show-toplevel)'
####### tmux ###################################################
# tmux with -2=256 color
# not sure if needed, and instead use screen256 instead.
alias tmux="tmux -2"
alias tma='tmux attach -d -t'
# tma <tab> will do tab completion, useful for joining existing session
alias tmn='tmux new -s $(basename $(pwd))'
################## Third-party app ################################
# ffmpeg/ffprobe
alias ffprobe='ffprobe -hide_banner'
# imagemagick -- moved to separate script
# alias resize='mogrify -filter Triangle -define filter:support=2 -thumbnail 1024 -unsharp 0.25x0.25+8+0.065 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB -strip'
# TODO: search for files with TODO / FIXME
alias TODO='ag TODO'
# or could be done via
# alias TODO="grep -E 'FIXME|TODO'"
# similar to 'rake notes'
# fasd
alias fv='fasd -f -e vim' # quick opening files with vim
# misc
alias weather='curl wttr.in/jacksonville'
# IP ADDRESS: get my public IP address
alias whatismyip='curl checkip.amazonaws.com'
############## END #####################