about summary refs log tree commit diff
path: root/users/grfn/system/home/modules/zshrc
blob: a12173d6842d9b8609ef0c1ee99d6fda5e492e67 (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
#!/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 {{{
# }}}

# Directory Stuff {{{

# Always use color output for `ls`

# 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 }')
}
# }}}

# 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
}

# }}}

# Twitter! {{{


# 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
}
# }}}

# 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=
# }}}


# 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
# }}}

# Change cursor shape on insert/normal mode {{{
# (https://unix.stackexchange.com/q/433273/64261)

KEYTIMEOUT=5

_fix_cursor() {
   echo -ne '\e[5 q'
}

precmd_functions+=(_fix_cursor)

function zle-keymap-select {
  if [[ ${KEYMAP} == vicmd ]] ||
       [[ $1 = 'block' ]]; then
  echo -ne '\e[1 q'

  elif [[ ${KEYMAP} == main ]] ||
         [[ ${KEYMAP} == viins ]] ||
         [[ ${KEYMAP} = '' ]] ||
         [[ $1 = 'beam' ]]; then
  echo -ne '\e[5 q'
  fi
}
zle -N zle-keymap-select

# }}}

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