about summary refs log tree commit diff
path: root/home/modules/zshrc
blob: 95c1733e13a520872d07ff5684924ef12ce74e1b (plain) (blame)
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
#!/usr/bin/zsh
# vim: set fdm=marker fmr={{{,}}}:

stty -ixon

# Compinstall {{{
zstyle ':completion:*' completer _complete _ignored _correct _approximate
zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]} m:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._- :]=** r:|=**' 'l:|=* r:|=*'
zstyle ':completion:*' max-errors 5
zstyle ':completion:*' use-cache yes
zstyle ':completion::complete:grunt::options:' expire 1
zstyle ':completion:*' prompt '%e errors'
zstyle :compinstall filename '~/.zshrc'
autoload -Uz compinit
compinit
# }}}

# Zsh-newuser-install {{{
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory autocd extendedglob notify autopushd
unsetopt beep nomatch
bindkey -v
# }}}

# Basic options {{{
set -o vi
umask 022
export VIRTUAL_ENV_DISABLE_PROMPT=1
# export PATH=~/.local/bin:~/.cabal/bin:$PATH:~/code/go/bin:~/bin:~/npm/bin:~/.gem/ruby/2.1.0/bin:~/.gem/ruby/2.0.0/bin:/home/smith/bin
# }}}

# Zsh highlight highlighters {{{
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern root)
# }}}

# More basic options {{{
setopt no_hist_verify
setopt histignorespace
# }}}

# Utility Functions {{{

# Set the terminal's title bar.
function titlebar() {
echo -ne "\033]0;$*\007"
}

function quiet() {
"$@" >/dev/null
}

function quieter() {
"$@" >/dev/null 2>&1
}

# From http://stackoverflow.com/questions/370047/#370255
function path_remove() {
IFS=:
# convert it to an array
t=($PATH)
unset IFS
# perform any array operations to remove elements from the array
t=(${t[@]%%$1})
IFS=:
# output the new array
echo "${t[*]}"
}

# }}}

# Force screen to use zsh {{{
# }}}

# Environment {{{
export EDITOR="/usr/bin/vim"
# }}}

# Directory Stuff {{{

# Always use color output for `ls`
if [[ "$OSTYPE" =~ ^darwin ]]; then
else
  export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
fi

# Directory listing

# Easier navigation: .., ..., -

# File size

# Recursively delete `.DS_Store` files

# Create a new directory and enter it
function md() {
  mkdir -p "$@" && cd "$@"
}

# }}}

# MPD/MPC stuff {{{
function mp() {
# Test if drive is already mounted
if ! lsblk | grep /media/external >/dev/null; then
  if ! sudo mount /media/external; then
    echo "External drive not plugged in, or could not mount"
    return 1
  fi
fi
if (mpc >/dev/null 2>&1); then
  ncmpcpp
else
  mpd &&
    (pgrep mpdscribble || mpdscribble) &&
    ncmpcpp
fi
}

# kill mp
function kmp() {
killall ncmpcpp
mpd --kill

local files

if (files=$(lsof 2>&1 | grep -v docker | grep external)); then
  echo
  echo "==> Still processes using external drive:"
  echo
  echo $files
else
  sudo umount /media/external
fi
}


function mppal() {
mpc search album "$1" | mpc add &&
  mpc play;
}
# }}}

# Git stuff {{{
# function ga() { git add "${@:-.}"; } # Add all files by default
# Add non-whitespace changes
# function gc() { git checkout "${@:-master}"; } # Checkout master by default

# open all changed files (that still actually exist) in the editor
function ged() {
local files=()
for f in $(git diff --name-only "$@"); do
  [[ -e "$f" ]] && files=("${files[@]}" "$f")
done
local n=${#files[@]}
echo "Opening $n $([[ "$@" ]] || echo "modified ")file$([[ $n != 1 ]] && \
  echo s)${@:+ modified in }$@"
q "${files[@]}"
}

# git find-replace
function gfr() {
if [[ "$#" == "0" ]]; then
  echo 'Usage:'
  echo ' gg_replace term replacement file_mask'
  echo
  echo 'Example:'
  echo ' gg_replace cappuchino cappuccino *.html'
  echo
else
  find=$1; shift
  replace=$1; shift

  ORIG_GLOBIGNORE=$GLOBIGNORE
  GLOBIGNORE=*.*
  if [[ "$#" = "0" ]]; then
    set -- ' ' $@
  fi

  while [[ "$#" -gt "0" ]]; do
    for file in `git grep -l $find -- $1`; do
      sed -e "s/$find/$replace/g" -i'' $file
    done
    shift
  done

  GLOBIGNORE=$ORIG_GLOBIGNORE
fi
}

function vconflicts() {
$EDITOR $(git status --porcelain | awk '/^UU/ { print $2 }')
}

function fetchall() {
for repo in ~/code/nomi/gems/* ~/code/nomi/services/svc-users ~/code/nomi/services/svc-entities ~/code/go/src/github.com/getnomi/svc-gateway; do
  echo -e "\x1b[34;1m=======> \x1b[37;1m$repo\x1b[0m"
  git -C $repo fetch
done
}
# }}}

# Wifi {{{
# }}}

# adb {{{
export GNEX_IP='192.168.3.30'
# }}}

# Golang {{{
export GOPATH="/home/griffin/code/go"
# }}}

# Tail logs {{{
# }}}

# Running stuff {{{
# }}}

# Directories {{{



export NODE_ENV='development'
# }}}

# SSH shortcuts {{{
# }}}

# Editing config files {{{
# }}}

# XRandR {{{
# }}}

# fzf {{{
v() {
  local file
  file=$(fzf-tmux --query="$1" --select-1 --exit-0)
  [ -n "$file" ] && ${EDITOR:-vim} "$file"
}

c() {
  local dir
  dir=$(find ${1:-*} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf +m) && cd "$dir"
}

co() {
  local branch
  branch=$(git branch -a | sed -s "s/\s*\**//g" | fzf --query="$1" --select-1 --exit-0) && git checkout "$branch"
}


# fh - repeat history
# h() {
#   eval $(([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s | sed 's/ *[0-9]* *//')
# }

# fkill - kill process
fkill() {
  ps -ef | sed 1d | fzf-tmux -m | awk '{print $2}' | xargs kill -${1:-9}
}
# }}}

# Tmux utils {{{
kill_detached() {
  for sess in $(tmux ls | grep -v attached | sed -s "s/:.*$//"); do
    tmux kill-session -t $sess;
  done
}
# }}}

# Docker {{{


# dbp foo/bar .
function dbp () {
  docker build -t $1 ${@:2} && docker push $1
}

# }}}

# Vagrant {{{
# }}}

# Twitter! {{{
export TWITTER_WHOAMI='glittershark1'


# favelast <username>
function favelast() {
  t fave $(t tl -l $1 | head -n1 | first)
}

function rtlast() {
  t rt $(t tl -l $1 | head -n1 | first)
}

function tthread() {
  t reply $(t tl -l $TWITTER_WHOAMI | head -n1 | first) $@
}
# }}}

# Geeknote {{{
gnc() {
  gn create --title $1 --content '' &&
    gn find --count=1 "$1"
    gn edit 1
}
# }}}

# Systemd aliases {{{
# }}}

# Misc aliases {{{

function fw() { # fix white
  local substitution
  local substitution='s/\x1b\[90m/\x1b[92m/g'
  $@ > >(perl -pe "$substitution") 2> >(perl -pe "$substitution" 1>&2)
}
# }}}

# Grep options {{{
unset GREP_OPTIONS
export GREP_OPTIONS=
# }}}

# Keyboard backlight {{{

KEYBOARD_BRIGHTNESS_FILE='/sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/brightness'

setkbd() {
  echo $1 | sudo tee $KEYBOARD_BRIGHTNESS_FILE
}

kbdup() {
  curr=$(< $KEYBOARD_BRIGHTNESS_FILE)
  echo $(( $curr + 15 )) | sudo tee $KEYBOARD_BRIGHTNESS_FILE
}

kbdup() {
  curr=$(< $KEYBOARD_BRIGHTNESS_FILE)
  echo $(( $curr - 15 )) | sudo tee $KEYBOARD_BRIGHTNESS_FILE
}

# }}}

# Run docker containers {{{
    # -d \
    # -v $HOME/.pentadactyl:/home/firefox/.pentadactyl:rw \
    # -v $HOME/.pentadactylrc:/home/firefox/.pentadactylrc:rw \
    # -v $HOME/.mozilla:/home/firefox/.mozilla:rw \
    # -v $HOME/.config:/home/firefox/.config \
    # -v $HOME/Downloads:/home/firefox/Downloads:rw \
    # -v /etc/fonts:/etc/fonts \
    # -v /tmp/.X11-unix:/tmp/.X11-unix \
    # -v /dev/snd:/dev/snd \
    # --net=host \
    # -v $XDG_RUNTIME_DIR:$XDG_RUNTIME_DIR \
    # -e uid=$(id -u) \
    # -e gid=$(id -g) \
    # -e DISPLAY=$DISPLAY \
    # -e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \
    # --name firefox \
    # --rm -it \
    # glittershark/firefox
# }}}

[ -f ./.localrc ] && source ./.localrc