forked from Amar1729/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.shell_aliases
255 lines (216 loc) · 6.38 KB
/
.shell_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
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
# General shell aliases. Source from .bashrc or .zshrc
[[ -r ~/.bash_aliases_tmp ]] && source ~/.bash_aliases_tmp
# locking
if [[ "$(uname)" == 'Darwin' ]]
then
# Open the screensaver with `lock`
# note - should set preferences to lock the screen after 5s of screensaver
lock () {
SCREEN_ENGINE="/System/Library/Frameworks/ScreenSaver.framework/Versions/Current/Resources/ScreenSaverEngine.app"
open -a $SCREEN_ENGINE
}
else
# linux locking (typically, this is a script that uses some version of i3lock)
alias lock="~/.config/scripts/lock.sh"
fi
####
## Common aliases, command improvements:
####
# ls, grep, mkdir, tmux improvements
alias ll="ls -lhFG"
alias la="ll -a"
alias lr="gls -lhFG --color=auto --ignore={'*.py[c|o]','__pycache__','*.o','*.so','*~'}"
alias lt="ll -t"
alias grep="grep --color=auto"
alias fgrep="fgrep --color=auto"
alias egrep="egrep --color=auto"
alias ggrep="ggrep --color=auto"
alias less="less -FX"
alias cclear="cd; clear"
# Make new directory and immediately cd into it (from Nate Landau's, link below)
# should the -p flag be included?
mcd () { mkdir -p "$1" && cd "$1"; }
# Use neovim instead of vim
alias vi="nvim"
alias vim="nvim"
alias gvim="/usr/local/bin/vim"
vimdiff () { nvim -d "$@" ;}
# copy with a progress bar.
alias cpv="rsync -avzh --progress --"
# pretty-print json
alias jcat='python -m json.tool'
# colorize diff output (use colordiff instead of diff --color, problems with -y, side-by-side)
alias diff='colordiff'
# set better defaults for highlight
alias highlight='highlight -O xterm256 --style=zenburn --force'
# use `highlight` for colorized cat
hcat () {
while [[ $# -gt 0 ]]; do
case "$1" in
-n)
ARGS="-l"
;;
*rc|*profile)
highlight "$ARGS" --syntax=conf -i "$1"
;;
*)
highlight "$ARGS" -i "$1"
;;
esac
shift
done
unset ARGS
}
# make tmux easier to check
alias tmux-ls="tmux list-sessions"
# tmux-a [index] : attaches to the index of given session
# tmux-a : tries to attach to last session; if none active, creates new one
tmux-a () {
sessions=`tmux list-sessions 2>/dev/null`
# if there are tmux sessions, connect to the last one or the one specified by $1
if [[ $? -eq 0 ]]
then
# if there's an argument given then connect to given session
if [[ -n "$1" ]]
then
tmux attach -t "$1"
#return $?
else
# no argument, and tmux is running: attach to the most recent session
tmux attach
#return $?
fi
else
# tmux isn't running: start it up
tmux
#return 0
fi
}
# Generate a password before plugging into `pass`
gen-pw () {
[[ -z "$1" ]] && LEN=15 || LEN="$1"
cat /dev/urandom | \
gtr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' | \
head -c "$LEN"
}
# overwrite `python` and `python3` to always open better REPL (if it's installed)
python () {
which ipython > /dev/null
if [[ "$?" -eq 0 && "$#" -eq 0 ]]; then
ipython
else
command python "$@"
fi
}
python3 () {
which ipython > /dev/null
if [[ "$?" -eq 0 && "$#" -eq 0 ]]; then
ipython
else
command python3 "$@"
fi
}
# wip: add completions to tmux-a (will defer between bash and zsh uh oh)
function _tmux-a () {
[[ -n ${tmux_describe} ]] && print "Attach or switch to a session" && return
local -a args
args=(
#'-c[specify working directory for the session]:directory:_path_files -g "*(-/)"'
#'-d[detach other clients attached to target session]'
#'-r[put the client into read-only mode]'
'[choose a target session]:target session:__tmux-sessions'
)
_arguments ${args}
}
####
## aliases/functions that are mac or linux specific
####
if [[ "$(uname)" == 'Darwin' ]]
then
# quick look alias
alias ql='qlmanage -p 2>/dev/null'
# fix broken virtualenv (when brew updates python)
fix-env () { gfind "$1" -type l -xtype l -delete }
abri () { open -a Abricotine "$@" }
# get battery status (this is only used when I'm running very low power, no bar)
alias power="pmset -g batt | egrep -o '([0-9]+\%).*?;.*?;'"
# control wifi
wifi () {
if [[ -n "$1" ]]; then
case "$1" in
"status")
networksetup -getairportnetwork en0
;;
"on"|"off")
networksetup -setairportpower en0 "$1"
;;
*)
echo "Not valid option: ""$1" && echo "{on|off|status}" && return 1
;;
esac
else
# with no argument, just toggle
STATUS="$(networksetup -getairportpower en0|cut -f4 -d ' ')"
if [[ $STATUS == "Off" ]]; then
networksetup -setairportpower en0 on && echo "turning wifi on..."
else
networksetup -setairportpower en0 off && echo "turning wifi off..."
fi
fi
}
# Show hidden files (default: false)
export FINDER_SHOW_HIDDEN=1
toggleFinderHidden () {
if [[ $FINDER_SHOW_HIDDEN -eq 0 ]]
then
export FINDER_SHOW_HIDDEN=1
defaults write com.apple.finder ShowAllFiles true
killall Finder
else
export FINDER_SHOW_HIDDEN=0
defaults write com.apple.finder ShowAllFiles false
killall Finder
fi
}
# Show desktop icons by default
export DESKTOP_SHOW=1
toggleDesktop () {
if [[ $DESKTOP_SHOW -eq 0 ]]
then
export DESKTOP_SHOW=1
defaults write com.apple.finder CreateDesktop true
killall Finder
else
export DESKTOP_SHOW=0
defaults write com.apple.finder CreateDesktop false
killall Finder
fi
}
# hardcore ricing stuff (lol)
# http://tex.stackexchange.com/questions/43057/macosx-pdf-viewer-automatic-reload-on-file-modification
# setup Skim for vim latex pdf previewing
# defaults write -app Skim SKAutoReloadFileUpdate -boolean true
#
# http://stackoverflow.com/questions/1264210/does-mac-x11-have-the-xtest-extension
# xtest for xQuartz?
# defaults write org.x.X11 enable_test_extensions -boolean true
####
# Following suggestions are from:
# http://natelandau.com/my-mac-osx-bash_profile/
# Prevent power button from immediately sleeping display
alias PowerSleepOff='defaults write com.apple.loginwindow PowerButtonSleepsSystem -bool no'
alias PowerSleepOn='defaults write com.apple.loginwindow PowerButtonSleepsSystem -bool yes'
# Move default screencap location (only have to run this once, but saved here just in case)
# Where I want them saved:
alias picDls='defaults write com.apple.screencapture location ~/Downloads/; killall SystemUIServer'
# Actual default:
alias picDef='defaults write com.apple.screencapture location ~/Desktop/; killall SystemUIServer'
# Recursively delete .DS_Store files
alias delDS="find . -type f -name '*.DS_Store' -ls -delete"
####
## End of Nate Landau's suggestions
####
else
# linux-specific aliases
:
fi